Skip to content

Commit

Permalink
Fix for JoeStrout#156
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx committed Jul 10, 2024
1 parent 110c8e5 commit 58ff9c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ Debug
miniscript-cpp.dir
*.vcxproj*
*.sln

# Tests fallout
_*.txt
2 changes: 1 addition & 1 deletion MiniScript-cpp/src/ShellIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,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;
}
Expand Down
25 changes: 25 additions & 0 deletions MiniScript-cpp/tests/testFileReadLines.ms
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 58ff9c1

Please sign in to comment.