From 57ee580c0f18515f7d1be19ac477758817456eba Mon Sep 17 00:00:00 2001 From: wangqr Date: Wed, 18 Sep 2019 18:11:18 -0400 Subject: [PATCH] Fix lagi_thes unit tests on Windows The thes file was using \r\n line ends, and \r was not stripped, causing the encoding string has a \r at its end. Use binary mode and always use \n as line ends. --- tests/tests/thesaurus.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/tests/thesaurus.cpp b/tests/tests/thesaurus.cpp index 0a003a002..5fa1d878b 100644 --- a/tests/tests/thesaurus.cpp +++ b/tests/tests/thesaurus.cpp @@ -26,13 +26,14 @@ protected: std::string dat_path; void SetUp() override { - using std::endl; + // Use '\n' on all platforms, as we are mapping the file to memory as binary data, and readline can only handle '\n' + const char endl = '\n'; idx_path = "data/thes.idx"; dat_path = "data/thes.dat"; - std::ofstream idx(idx_path.c_str()); - std::ofstream dat(dat_path.c_str()); + std::ofstream idx(idx_path.c_str(), std::ios_base::binary); + std::ofstream dat(dat_path.c_str(), std::ios_base::binary); idx << "UTF-8" << endl; dat << "UTF-8" << endl;