Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/compiled/String.cpp

Issue 29714586: Noissue - implement a couple of common lexical_cast cases. (Closed) Base URL: github.com:adblockplus/adblockpluscore
Patch Set: address comment Created March 6, 2018, 10:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« compiled/String.h ('K') | « compiled/String.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_EQ(u"123:abc"_str, split.first); 104 EXPECT_EQ(u"123:abc"_str, split.first);
105 EXPECT_EQ(u""_str, split.second); 105 EXPECT_EQ(u""_str, split.second);
106 } 106 }
107 { 107 {
108 auto str = u"123:abc"_str; 108 auto str = u"123:abc"_str;
109 auto split = SplitString(str, 10); 109 auto split = SplitString(str, 10);
110 EXPECT_EQ(u"123:abc"_str, split.first); 110 EXPECT_EQ(u"123:abc"_str, split.first);
111 EXPECT_EQ(u""_str, split.second); 111 EXPECT_EQ(u""_str, split.second);
112 } 112 }
113 } 113 }
114
115 TEST(TestStringLexicalCast, toIntegers)
116 {
117 EXPECT_EQ(0, lexical_cast<int32_t>(u"0"_str));
118 EXPECT_EQ(1, lexical_cast<int32_t>(u"1"_str));
119 EXPECT_EQ(2, lexical_cast<int32_t>(u"2"_str));
120 EXPECT_EQ(10, lexical_cast<int32_t>(u"10"_str));
121 EXPECT_EQ(10, lexical_cast<int32_t>(u"010"_str));
122 EXPECT_EQ(-1, lexical_cast<int32_t>(u"-1"_str));
123 EXPECT_EQ(-2, lexical_cast<int32_t>(u"-2"_str));
124 EXPECT_EQ(-20, lexical_cast<int32_t>(u"-20"_str));
125 EXPECT_EQ(-20, lexical_cast<int32_t>(u"-020"_str));
126 EXPECT_EQ(0, lexical_cast<int32_t>(u"0-2"_str));
127 EXPECT_EQ(-2147483647, lexical_cast<int32_t>(u"-2147483647"_str));
128 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-2147483648"_str));
129 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-2147483649"_str));
130 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-2157483649"_str));
131 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-3147483649"_str));
132 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-02147483648"_str));
133 EXPECT_EQ(-2147483648, lexical_cast<int32_t>(u"-000002147483648"_str));
134 EXPECT_EQ( 0, lexical_cast<int32_t>(u"-21474836480"_str));
135 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"2147483647"_str));
136 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"000002147483647"_str));
137 EXPECT_EQ(2147483647, lexical_cast<int32_t>(u"02147483647"_str));
138 EXPECT_EQ( 0, lexical_cast<int32_t>(u"21474836470"_str));
139 EXPECT_EQ( 0, lexical_cast<int32_t>(u"2147483648"_str));
140 EXPECT_EQ( 0, lexical_cast<int32_t>(u"2157483648"_str));
141 EXPECT_EQ( 0, lexical_cast<int32_t>(u"3147483648"_str));
142 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"0"_str));
143 EXPECT_EQ(2u, lexical_cast<uint32_t>(u"2"_str));
144 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"123"_str));
145 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"0123"_str));
146 EXPECT_EQ(123u, lexical_cast<uint32_t>(u"0000123"_str));
147 EXPECT_EQ(4294967294u, lexical_cast<uint32_t>(u"4294967294"_str));
148 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(u"4294967295"_str));
149 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"4294967296"_str));
150 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"4594967295"_str));
151 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"5294967295"_str));
152 EXPECT_EQ( 0u, lexical_cast<uint32_t>(u"42949672950"_str));
153 EXPECT_EQ(4294967295u, lexical_cast<uint32_t>(u"04294967295"_str));
154
155 EXPECT_EQ(0, lexical_cast<int32_t>(u" 123"_str));
156 EXPECT_EQ(0u, lexical_cast<uint32_t>(u" 123"_str));
157 EXPECT_EQ(0, lexical_cast<int32_t>(u"123abc"_str));
158 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"123abc"_str));
159 EXPECT_EQ(0, lexical_cast<int32_t>(u"1 23"_str));
160 EXPECT_EQ(0u, lexical_cast<uint32_t>(u"1 23"_str));
161 }
162
163 TEST(TestStringLexicalCast, toBoolean)
164 {
165 EXPECT_TRUE(lexical_cast<bool>(u"true"_str));
166 EXPECT_FALSE(lexical_cast<bool>(u"true123"_str));
167 EXPECT_FALSE(lexical_cast<bool>(u"false"_str));
168 EXPECT_FALSE(lexical_cast<bool>(u"some-string"_str));
169 EXPECT_FALSE(lexical_cast<bool>(u""_str));
170 EXPECT_FALSE(lexical_cast<bool>(DependentString()));
171 }
172
173 TEST(TestStringLexicalCast, toOwnedString)
174 {
175 EXPECT_EQ(u"some-string"_str, lexical_cast<OwnedString>(u"some-string"_str));
176 EXPECT_EQ(u""_str, lexical_cast<OwnedString>(u""_str));
177 }
OLDNEW
« compiled/String.h ('K') | « compiled/String.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld