Skip to content

Commit

Permalink
Merge pull request NixOS#7581 from edolstra/getline-tests
Browse files Browse the repository at this point in the history
Backport getLine tests from lazy-trees
  • Loading branch information
edolstra authored Jan 11, 2023
2 parents a3ba803 + 7515617 commit 6dd8b3b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/libutil/tests/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,42 @@ namespace nix {
ASSERT_THROW(base64Decode("cXVvZCBlcm_0IGRlbW9uc3RyYW5kdW0="), Error);
}

/* ----------------------------------------------------------------------------
* 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
* --------------------------------------------------------------------------*/
Expand Down

0 comments on commit 6dd8b3b

Please sign in to comment.