Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Copyright (c) 2005-2026
*/

#define VERSION "0.9.48"
#define VERSION "0.9.49"

/*
* Mike Mirzayanov
Expand Down Expand Up @@ -63,6 +63,7 @@
*/

const char *latestFeatures[] = {
"readLine()/readString(): a CR right before EOF no longer appends a 0xFF byte to the line",
"Byte 0xFF in input is data, not EOF: EOFC is -1 now, readers return bytes as unsigned char",
"testlib format()/println() work with using namespace std; call std::format/std::println explicitly for standard formatting",
"Remove incorrect const attributes",
Expand Down Expand Up @@ -4286,6 +4287,7 @@ void InStream::readStringTo(std::string &result) {
reader->unreadChar(cur);
break;
}
continue;
}

lastLine = reader->getLine();
Expand Down
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/files/answer.01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc
2 changes: 2 additions & 0 deletions tests/test-010_read-line-cr/files/answer.02
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
abcdef
ghi
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/files/answer.03
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcd
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/files/input.01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/files/output.01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc
2 changes: 2 additions & 0 deletions tests/test-010_read-line-cr/files/output.02
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
abcdef
ghi
Expand Down
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r1/exit_code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r1/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok 1 lines
Empty file.
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r2/exit_code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r2/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok 2 lines
Empty file.
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r3/exit_code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions tests/test-010_read-line-cr/refs/r3/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wrong answer line 1: expected 4 bytes 'abcd', found 3 bytes 'abc'
Empty file.
10 changes: 10 additions & 0 deletions tests/test-010_read-line-cr/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -eo pipefail

# readLine(): a CR not followed by LF is skipped, a CR right before EOF adds no byte to the line

bash ../scripts/compile src/lines.cpp
bash ../scripts/test-ref r1 "$VALGRIND" ./lines files/input.01 files/output.01 files/answer.01
bash ../scripts/test-ref r2 "$VALGRIND" ./lines files/input.01 files/output.02 files/answer.02
bash ../scripts/test-ref r3 "$VALGRIND" ./lines files/input.01 files/output.01 files/answer.03
rm -f lines lines.exe
46 changes: 46 additions & 0 deletions tests/test-010_read-line-cr/src/lines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "testlib.h"

using namespace std;

/*
* readLine(): LF and CRLF end a line, a CR not followed by LF is skipped,
* EOF ends the last line without adding any byte to it.
*/

static void check(InStream &in, const string &expected, const char *what) {
string line = in.readLine();
if (line != expected)
quitf(_fail, "%s: expected %d bytes '%s', found %d bytes '%s'", what,
int(expected.size()), expected.c_str(), int(line.size()), line.c_str());
if (!in.eof())
quitf(_fail, "%s: not at EOF after the only line", what);
}

int main(int argc, char *argv[]) {
registerTestlibCmd(argc, argv);

// String streams.
InStream a(inf, "abc\r");
check(a, "abc", "string 'abc<CR>'");
InStream b(inf, "abc\rdef\n");
check(b, "abcdef", "string 'abc<CR>def<LF>'");
InStream c(inf, "abc\r\n");
check(c, "abc", "string 'abc<CR><LF>'");
InStream d(inf, "\r");
check(d, "", "string '<CR>'");

// Files: output lines must equal answer lines byte for byte.
int lines = 0;
while (!ans.eof()) {
string j = ans.readLine();
string p = ouf.readLine();
lines++;
if (j != p)
quitf(_wa, "line %d: expected %d bytes '%s', found %d bytes '%s'", lines,
int(j.size()), j.c_str(), int(p.size()), p.c_str());
}
if (!ouf.eof())
quitf(_wa, "output has extra data after %d lines", lines);

quitf(_ok, "%d lines", lines);
}
Loading