aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/tests
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2023-01-11 14:30:47 +0100
committerGitHub <noreply@github.com>2023-01-11 14:30:47 +0100
commit6dd8b3b4122d9a4dccf17c00a290349a1509a7d6 (patch)
treed2bfc1d1e922e68b4de660b0e9b5b5c80ebfdafe /src/libutil/tests
parenta3ba80357d3a792eb1690011f253c64840c6ae72 (diff)
parent7515617ad046a08f2b9d0dd1f552e8841be4971d (diff)
Merge pull request #7581 from edolstra/getline-tests
Backport getLine tests from lazy-trees
Diffstat (limited to 'src/libutil/tests')
-rw-r--r--src/libutil/tests/tests.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libutil/tests/tests.cc b/src/libutil/tests/tests.cc
index 6e325db98..250e83a38 100644
--- a/src/libutil/tests/tests.cc
+++ b/src/libutil/tests/tests.cc
@@ -312,6 +312,42 @@ namespace nix {
}
/* ----------------------------------------------------------------------------
+ * getLine
+ * --------------------------------------------------------------------------*/
+
+ TEST(getLine, all) {
+ {
+ auto [line, rest] = getLine("foo\nbar\nxyzzy");
+ ASSERT_EQ(line, "foo");
+ ASSERT_EQ(rest, "bar\nxyzzy");
+ }
+
+ {
+ auto [line, rest] = getLine("foo\r\nbar\r\nxyzzy");
+ ASSERT_EQ(line, "foo");
+ ASSERT_EQ(rest, "bar\r\nxyzzy");
+ }
+
+ {
+ auto [line, rest] = getLine("foo\n");
+ ASSERT_EQ(line, "foo");
+ ASSERT_EQ(rest, "");
+ }
+
+ {
+ auto [line, rest] = getLine("foo");
+ ASSERT_EQ(line, "foo");
+ ASSERT_EQ(rest, "");
+ }
+
+ {
+ auto [line, rest] = getLine("");
+ ASSERT_EQ(line, "");
+ ASSERT_EQ(rest, "");
+ }
+ }
+
+ /* ----------------------------------------------------------------------------
* toLower
* --------------------------------------------------------------------------*/