MCPcopy Create free account
hub / github.com/catboost/catboost / TestZero

Method TestZero

util/generic/string_ut.cpp:29–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28public:
29 void TestZero() {
30 const char data[] = "abc\0def\0";
31 TString s(data, sizeof(data));
32 UNIT_ASSERT(s.size() == sizeof(data));
33 UNIT_ASSERT(s.StartsWith(s));
34 UNIT_ASSERT(s.EndsWith(s));
35 UNIT_ASSERT(s.Contains('\0'));
36
37 const char raw_def[] = "def";
38 const char raw_zero[] = "\0";
39 TString def(raw_def, sizeof(raw_def) - 1);
40 TString zero(raw_zero, sizeof(raw_zero) - 1);
41 UNIT_ASSERT_EQUAL(4, s.find(raw_def));
42 UNIT_ASSERT_EQUAL(4, s.find(def));
43 UNIT_ASSERT_EQUAL(4, s.find_first_of(raw_def));
44 UNIT_ASSERT_EQUAL(3, s.find_first_of(zero));
45 UNIT_ASSERT_EQUAL(7, s.find_first_not_of(def, 4));
46
47 const char nonSubstring[] = "def\0ghi";
48 UNIT_ASSERT_EQUAL(TString::npos, s.find(TString(nonSubstring, sizeof(nonSubstring))));
49
50 TString copy = s;
51 copy.replace(copy.size() - 1, 1, "z");
52 UNIT_ASSERT(s != copy);
53 copy.replace(copy.size() - 1, 1, "\0", 0, 1);
54 UNIT_ASSERT(s == copy);
55
56 TString prefix(data, 5);
57 UNIT_ASSERT(s.StartsWith(prefix));
58 UNIT_ASSERT(s != prefix);
59 UNIT_ASSERT(s > prefix);
60 UNIT_ASSERT(s > s.data());
61 UNIT_ASSERT(s == TString(s.data(), s.size()));
62 UNIT_ASSERT(data < s);
63
64 s.remove(5);
65 UNIT_ASSERT(s == prefix);
66 }
67};
68
69UNIT_TEST_SUITE_REGISTRATION(TStringTestZero);

Callers

nothing calls this directly

Calls 10

sizeMethod · 0.45
StartsWithMethod · 0.45
EndsWithMethod · 0.45
ContainsMethod · 0.45
findMethod · 0.45
find_first_ofMethod · 0.45
find_first_not_ofMethod · 0.45
replaceMethod · 0.45
dataMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected