From c029d90d1975e124d237605f1edb2be16bd05b5d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 28 Feb 2017 21:50:44 +0100 Subject: Initial commit --- test/test-strings.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/test-strings.cc (limited to 'test/test-strings.cc') diff --git a/test/test-strings.cc b/test/test-strings.cc new file mode 100644 index 0000000..c049165 --- /dev/null +++ b/test/test-strings.cc @@ -0,0 +1,55 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#include "common.hh" +#include "test.hh" + +#include "strings.hh" + +namespace { + +bool test_trim(char const* expected, char const* input) { + ASSERT_EQ(expected, Strings::trim(input)); + return true; +} + +bool test_quote(char const* expected, char const* input) { + ASSERT_EQ(expected, Strings::quote(input)); + return true; +} + +bool test_unquote(char const* expected, char const* input) { + ASSERT_EQ(expected, Strings::unquote(input)); + return true; +} + +} // namespace + +int main(void) { + BEFORE; + RUN(test_trim("", "")); + RUN(test_trim("foo", "foo")); + RUN(test_trim("foo", " foo")); + RUN(test_trim("foo", " foo ")); + RUN(test_trim("foo", " foo ")); + RUN(test_trim("", " ")); + RUN(test_trim("", " ")); + RUN(test_trim("foo bar", "foo bar")); + RUN(test_trim("foo bar", " foo bar ")); + RUN(test_quote("\"\"", "")); + RUN(test_quote("\"'\"", "'")); + RUN(test_quote("\"\\\"\"", "\"")); + RUN(test_quote("\"\\\\\"", "\\")); + RUN(test_quote("\"foo\"", "foo")); + RUN(test_quote("\"\\\"fo\\\"o\"", "\"fo\"o")); + RUN(test_quote("\"f\\\"o\\\"o\"", "f\"o\"o")); + RUN(test_quote("\"\\\"foo\\\"\"", "\"foo\"")); + RUN(test_unquote("", "\"\"")); + RUN(test_unquote("'", "\"'\"")); + RUN(test_unquote("\"", "\"\\\"\"")); + RUN(test_unquote("\\", "\"\\\\\"")); + RUN(test_unquote("foo", "\"foo\"")); + RUN(test_unquote("\"fo\"o", "\"\\\"fo\\\"o\"")); + RUN(test_unquote("f\"o\"o", "\"f\\\"o\\\"o\"")); + RUN(test_unquote("\"foo\"", "\"\\\"foo\\\"\"")); + AFTER; +} -- cgit v1.2.3-70-g09d2