MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / StringTest

Method StringTest

Tests/Libraries/Memory/StringTest.cpp:14–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12struct SC::StringTest : public SC::TestCase
13{
14 StringTest(SC::TestReport& report) : TestCase(report, "StringTest")
15 {
16 using namespace SC;
17
18 if (test_section("construction_comparison"))
19 {
20 StringView sv = "Test String";
21 String str = String("Test String");
22 SC_TEST_EXPECT(str == sv);
23 SC_TEST_EXPECT(str.view() == sv);
24 SC_TEST_EXPECT(str.owns(StringView(str.view()).sliceStart(1)));
25 String str2 = "Another String";
26 SC_TEST_EXPECT(not str.owns(StringView(str2.view()).sliceStart(1)));
27 SC_TEST_EXPECT(str != "ASD");
28 SC_TEST_EXPECT(str == "Test String");
29 SC_TEST_EXPECT(str == str);
30 SC_TEST_EXPECT(str != String("ASD"));
31 str = "Salver";
32 SC_TEST_EXPECT(str == "Salver");
33 }
34
35 if (test_section("SmallString / String"))
36 {
37 String vec2;
38 {
39 SmallString<3> vec;
40 SC_TEST_EXPECT(vec.assign("123"));
41 SC_TEST_EXPECT(vec.data.size() == 4);
42
43 vec2 = move(vec);
44 SC_TEST_EXPECT(vec.data.isInline());
45 }
46 SC_TEST_EXPECT(not vec2.data.isInline());
47 }
48
49 if (test_section("SmallString"))
50 {
51 // Test String assignment to SmallString
52 SmallString<10> ss10;
53 String normal("asd");
54 ss10 = normal;
55 auto assertUpCasting = [this](String& s) { SC_TEST_EXPECT(s.sizeInBytesIncludingTerminator() == 4); };
56 assertUpCasting(ss10);
57 SC_TEST_EXPECT(ss10.view() == "asd");
58 SC_TEST_EXPECT(ss10.data.isInline());
59 SC_TEST_EXPECT(ss10.data.capacity() == 10);
60 // Test SmallString assignment to regular string
61 SmallString<20> ss20;
62 ss20 = "ASD22";
63 normal = move(ss20);
64 SC_TEST_EXPECT(normal.view() == "ASD22");
65 SC_TEST_EXPECT(not normal.data.isInline());
66 }
67
68 if (test_section("SmallString Buffer"))
69 {
70 SmallBuffer<5> myStuff;
71 StringView test = "ASDF";

Callers

nothing calls this directly

Calls 7

sliceStartMethod · 0.80
StringClass · 0.50
viewMethod · 0.45
assignMethod · 0.45
sizeMethod · 0.45
capacityMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected