Debian Codegraph @

tests/src/test_stringutils.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/tests/src/test_stringutils.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5 #include <catch2/trompeloeil.hpp>
6
7 #include "common/stringutils.h"cxx . . $ `<file>/src/common/stringutils.h`/
8
9 extern template struct trompeloeil::reportercxx . . $ trompeloeil/reporter#<trompeloeilcxx . . $ trompeloeil/::specializedcxx . . $ trompeloeil/specialized#>;
10
11 namespace Testscxx . . $ Tests/::Utilscxx . . $ Tests/Utils/::Stringcxx . . $ Tests/Utils/String/ {
12
13 TEST_CASEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:144:11`!("StringUtils tests", "[Utils][String]")
14 {
15 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("cleanPrefix")
16 {
17 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns a string without the prefix when the input string "
18 "contains the prefix")
19 {
20 stdcxx . . $ std/::stringcxx . . $ std/string# prefixcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix ");
21 stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix text");
22 auto res = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::cleanPrefixcxx . . $ Utils/String/cleanPrefix(203b42cd324c6c40).(data, prefix);
23
24 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(res == "text");
25 }
26
27 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns the input string when the prefix is not a substring of "
28 "the input string")
29 {
30 stdcxx . . $ std/::stringcxx . . $ std/string# prefixcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix");
31 stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("some data");
32 auto res = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::cleanPrefixcxx . . $ Utils/String/cleanPrefix(203b42cd324c6c40).(data, prefix);
33
34 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(res == "some data");
35 }
36
37 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns an empty string when the input string equals the prefix")
38 {
39 stdcxx . . $ std/::stringcxx . . $ std/string# prefixcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix");
40 stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix");
41 auto res = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::cleanPrefixcxx . . $ Utils/String/cleanPrefix(203b42cd324c6c40).(data, prefix);
42
43 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(res == "");
44 }
45
46 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns the input string when it is shorter than the prefix")
47 {
48 stdcxx . . $ std/::stringcxx . . $ std/string# prefixcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("prefix");
49 stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("pref");
50 auto res = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::cleanPrefixcxx . . $ Utils/String/cleanPrefix(203b42cd324c6c40).(data, prefix);
51
52 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(res == "pref");
53 }
54
55 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns the input string when the prefix is empty")
56 {
57 stdcxx . . $ std/::stringcxx . . $ std/string# prefixcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("");
58 stdcxx . . $ std/::stringcxx . . $ std/string# datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("data");
59 auto res = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::cleanPrefixcxx . . $ Utils/String/cleanPrefix(203b42cd324c6c40).(data, prefix);
60
61 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(res == "data");
62 }
63 }
64
65 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("parseVersion")
66 {
67 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns version when the input string is in 'mayor.minor.patch' "
68 "format")
69 {
70 auto version = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseVersioncxx . . $ Utils/String/parseVersion(18acf75b68842036).("1.2.3"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
71 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(version == std::make_tuple(1, 2, 3));
72 }
73
74 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns 0.0.0 version when the input string is not in "
75 "'mayor.minor.patch' format")
76 {
77 auto version = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseVersioncxx . . $ Utils/String/parseVersion(18acf75b68842036).("not a version"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
78 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(version == std::make_tuple(0, 0, 0));
79 }
80 }
81
82 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("split")
83 {
84 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Doesn't include the delimiter character in the results")
85 {
86 auto result = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::splitcxx . . $ Utils/String/split(119f23dcbaa30370).(" "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., ' ');
87 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result.empty());
88 }
89
90 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns the original string when it doesn't contains the "
91 "delimiter character")
92 {
93 auto result = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::splitcxx . . $ Utils/String/split(119f23dcbaa30370).("one"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., ' ');
94 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result.size() == 1);
95 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result[0] == "one");
96 }
97
98 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Split a string into substrings")
99 {
100 auto result = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::splitcxx . . $ Utils/String/split(119f23dcbaa30370).("one two three "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., ' ');
101 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result.size() == 3);
102 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result[0] == "one");
103 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result[1] == "two");
104 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(result[2] == "three");
105 }
106 }
107
108 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("parseKernelProcVersion")
109 {
110 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Provides kernel version when data is using...")
111 {
112 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Semver format")
113 {
114 stdcxx . . $ std/::stringcxx . . $ std/string# const datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("Linux version 1.2.3_other_info ...");
115 auto output = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseKernelProcVersioncxx . . $ Utils/String/parseKernelProcVersion(1bef80927fe03eda).(data);
116 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(output.has_value());
117 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(*output == "1.2.3");
118 }
119
120 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Invalid semver format...")
121 {
122 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Missing patch version (see #254)")
123 {
124 stdcxx . . $ std/::stringcxx . . $ std/string# const datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("Linux version 1.2_other_info ...");
125 auto output = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseKernelProcVersioncxx . . $ Utils/String/parseKernelProcVersion(1bef80927fe03eda).(data);
126 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(output.has_value());
127 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(*output == "1.2.0");
128 }
129
130 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("With additional version numbers after patch version")
131 {
132 stdcxx . . $ std/::stringcxx . . $ std/string# const datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("Linux version 1.2.3.4_other_info ...");
133 auto output = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseKernelProcVersioncxx . . $ Utils/String/parseKernelProcVersion(1bef80927fe03eda).(data);
134 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(output.has_value());
135 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(*output == "1.2.3");
136 }
137 }
138 }
139
140 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns no value when the string follow an unknown format")
141 {
142 stdcxx . . $ std/::stringcxx . . $ std/string# const datacxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("Other format");
143 auto output = ::Utilscxx . . $ Utils/::Stringcxx . . $ Utils/String/::parseKernelProcVersioncxx . . $ Utils/String/parseKernelProcVersion(1bef80927fe03eda).(data);
144 REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(output.has_value());
145 }
146 }
147 }
148
149 } // namespace Tests::Utils::String