diff --git a/.gitignore b/.gitignore index 263764c..003bc2a 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ Debug miniscript-cpp.dir *.vcxproj* *.sln + +# Tests fallout +_*.txt diff --git a/MiniScript-cpp/src/ShellIntrinsics.cpp b/MiniScript-cpp/src/ShellIntrinsics.cpp index e54718a..aed1893 100644 --- a/MiniScript-cpp/src/ShellIntrinsics.cpp +++ b/MiniScript-cpp/src/ShellIntrinsics.cpp @@ -726,7 +726,7 @@ static IntrinsicResult intrinsic_readLines(Context *context, IntrinsicResult par partialLine = ""; } list.Add(line); - if (buf[i] == '\n' && i+1 < bytesRead && buf[i+1] == '\r') i++; + if (buf[i] == '\r' && i+1 < bytesRead && buf[i+1] == '\n') i++; if (i+1 < bytesRead && buf[i+1] == 0) i++; lineStart = i + 1; } diff --git a/MiniScript-cpp/tests/testFileReadLines.ms b/MiniScript-cpp/tests/testFileReadLines.ms new file mode 100644 index 0000000..07d7d11 --- /dev/null +++ b/MiniScript-cpp/tests/testFileReadLines.ms @@ -0,0 +1,25 @@ +import "qa" + +testDir = "tests/" + +testFileReadLines = function + fn = file.child(testDir, "_cr.txt") + f = file.open(fn, "w") + f.write("a" + char(13) + "b" + char(13) + "c") + f.close + qa.assertEqual file.readLines("tests/_cr.txt"), ["a", "b", "c"] + + fn = file.child(testDir, "_lf.txt") + f = file.open(fn, "w") + f.write("a" + char(10) + "b" + char(10) + "c") + f.close + qa.assertEqual file.readLines("tests/_lf.txt"), ["a", "b", "c"] + + fn = file.child(testDir, "_crlf.txt") + f = file.open(fn, "w") + f.write("a" + char(13) + char(10) + "b" + char(13) + char(10) + "c") + f.close + qa.assertEqual file.readLines("tests/_crlf.txt"), ["a", "b", "c"] +end function + +if refEquals(locals, globals) then testFileReadLines