diff options
author | Neil <nyamatongwe@gmail.com> | 2020-04-13 09:59:02 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-04-13 09:59:02 +1000 |
commit | ebc4cb750d6a72ecf204a8b586eeef25c3783dea (patch) | |
tree | 647695da0e87080ab7386f6db6c3dbcd17112d98 | |
parent | 98fba9dcdd0b734e0788de4d731bd3dcf5ee9fc0 (diff) | |
download | scintilla-mirror-ebc4cb750d6a72ecf204a8b586eeef25c3783dea.tar.gz |
Add test for differing styles between \r and \n.
-rw-r--r-- | lexilla/test/TestLexers.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lexilla/test/TestLexers.cxx b/lexilla/test/TestLexers.cxx index 542ca212c..3296cd16a 100644 --- a/lexilla/test/TestLexers.cxx +++ b/lexilla/test/TestLexers.cxx @@ -65,8 +65,50 @@ std::map<std::string, std::string> PropertiesFromFile(std::filesystem::path path return m; } +int Substitute(std::string &s, const std::string &sFind, const std::string &sReplace) { + int c = 0; + const size_t lenFind = sFind.size(); + const size_t lenReplace = sReplace.size(); + size_t posFound = s.find(sFind); + while (posFound != std::string::npos) { + s.replace(posFound, lenFind, sReplace); + posFound = s.find(sFind, posFound + lenReplace); + c++; + } + return c; +} + const std::string BOM = "\xEF\xBB\xBF"; +void TestCRLF(std::filesystem::path path, const std::string s, Scintilla::ILexer5 *plex) { + // Convert all line ends to \r\n to check if styles change between \r and \n which makes + // it difficult to test on different platforms when files may have line ends changed. + std::string text = s; + Substitute(text, "\r\n", "\n"); + Substitute(text, "\n", "\r\n"); + TestDocument doc; + doc.Set(text); + Scintilla::IDocument *pdoc = &doc; + plex->Lex(0, pdoc->Length(), 0, pdoc); + int prevStyle = -1; + Sci_Position line = 1; + for (Sci_Position pos = 0; pos < pdoc->Length(); pos++) { + const int styleNow = pdoc->StyleAt(pos); + char ch = '\0'; + pdoc->GetCharRange(&ch, pos, 1); + if (ch == '\n') { + if (styleNow == prevStyle) { + std::cout << path.string() << ":" << line << ":" << + " different styles between \\r and \\n at " << + pos << ": " << prevStyle << ", " << styleNow << "\n"; + } + line++; + } + prevStyle = styleNow; + } + plex->Release(); +} + bool TestFile(std::filesystem::path path, std::map<std::string, std::string> properties) { // Find and create correct lexer @@ -122,6 +164,10 @@ bool TestFile(std::filesystem::path path, std::ofstream ofs(pathNew, std::ios::binary); ofs << styledTextNew; } + plex->Release(); + + TestCRLF(path, text, CreateLexer(language)); + return true; } |