Skip to content

Commit ee1e10e

Browse files
author
ochafik
committed
Normalize newlines in test-chat-templates for windows tests
1 parent d5fa351 commit ee1e10e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/test-chat-template.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
#include "common.h"
1010
#include "chat-template.hpp"
1111

12+
static std::string normalize_newlines(const std::string & s) {
13+
#ifdef _WIN32
14+
static const std::regex nl_regex("\r\n");
15+
return std::regex_replace(s, nl_regex, "\n");
16+
#else
17+
return s;
18+
#endif
19+
}
20+
1221
int main(void) {
1322
std::vector<llama_chat_message> conversation {
1423
{"system", "You are a helpful assistant"},
@@ -300,8 +309,8 @@ int main(void) {
300309
printf("\n\n=== %s (jinja) ===\n\n", test_case.name.c_str());
301310
try {
302311
minja::chat_template tmpl(test_case.template_str, test_case.bos_token, test_case.eos_token);
303-
auto output = tmpl.apply(messages, json(), add_generation_prompt);
304-
auto expected_output = test_case.expected_output_jinja.empty() ? test_case.expected_output : test_case.expected_output_jinja;
312+
auto output = normalize_newlines(tmpl.apply(messages, json(), add_generation_prompt));
313+
auto expected_output = normalize_newlines(test_case.expected_output_jinja.empty() ? test_case.expected_output : test_case.expected_output_jinja);
305314
if (output != expected_output) {
306315
printf("Expected:\n%s\n", expected_output.c_str());
307316
printf("-------------------------\n");

0 commit comments

Comments
 (0)