summaryrefslogtreecommitdiff
path: root/test/test-strings.cc
blob: c049165318e7f7554a55f4e830152f9ed8e0106e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
}