OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 void scanWithInvPredicate(const String& input) | 155 void scanWithInvPredicate(const String& input) |
156 { | 156 { |
157 VTTScanner scanner(input); | 157 VTTScanner scanner(input); |
158 EXPECT_FALSE(scanner.isAtEnd()); | 158 EXPECT_FALSE(scanner.isAtEnd()); |
159 // Collect "BAD". | 159 // Collect "BAD". |
160 VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>(); | 160 VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>(); |
161 // collectUntil doesn't move the scan position. | 161 // collectUntil doesn't move the scan position. |
162 EXPECT_TRUE(scanner.match('B')); | 162 EXPECT_TRUE(scanner.match('B')); |
163 // Consume "BAD". | 163 // Consume "BAD". |
164 scanner.skipRun(ucRun); | 164 scanner.skipUntil<lowerCaseAlpha>(); |
165 EXPECT_TRUE(scanner.match('a')); | 165 EXPECT_TRUE(scanner.match('a')); |
166 EXPECT_TRUE(scanner.isAt(ucRun.end())); | 166 EXPECT_TRUE(scanner.isAt(ucRun.end())); |
167 | 167 |
168 // Consume "a". | 168 // Consume "a". |
169 EXPECT_TRUE(scanner.scan('a')); | 169 EXPECT_TRUE(scanner.scan('a')); |
170 | 170 |
171 // Collect "BING". | 171 // Collect "BING". |
172 ucRun = scanner.collectUntil<lowerCaseAlpha>(); | 172 ucRun = scanner.collectUntil<lowerCaseAlpha>(); |
173 // collectUntil doesn't move the scan position. | 173 // collectUntil doesn't move the scan position. |
174 EXPECT_FALSE(scanner.isAtEnd()); | 174 EXPECT_FALSE(scanner.isAtEnd()); |
175 // Consume "BING". | 175 // Consume "BING". |
176 scanner.skipRun(ucRun); | 176 scanner.skipUntil<lowerCaseAlpha>(); |
177 EXPECT_TRUE(scanner.isAt(ucRun.end())); | 177 EXPECT_TRUE(scanner.isAt(ucRun.end())); |
178 EXPECT_TRUE(scanner.isAtEnd()); | 178 EXPECT_TRUE(scanner.isAtEnd()); |
179 } | 179 } |
180 | 180 |
181 // Tests collectUntil(). | 181 // Tests skipUntil() and collectUntil(). |
182 TEST(VTTScanner, InversePredicateScanning) | 182 TEST(VTTScanner, InversePredicateScanning) |
183 { | 183 { |
184 TEST_WITH(scanWithInvPredicate, "BADaBING"); | 184 TEST_WITH(scanWithInvPredicate, "BADaBING"); |
185 } | 185 } |
186 | 186 |
187 void scanRuns(const String& input) | 187 void scanRuns(const String& input) |
188 { | 188 { |
189 String fooString("foo"); | 189 String fooString("foo"); |
190 String barString("bar"); | 190 String barString("bar"); |
191 VTTScanner scanner(input); | 191 VTTScanner scanner(input); |
192 EXPECT_FALSE(scanner.isAtEnd()); | 192 EXPECT_FALSE(scanner.isAtEnd()); |
193 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); | 193 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); |
194 EXPECT_FALSE(scanner.scanRun(word, barString)); | 194 EXPECT_FALSE(scanner.scanRun(word, barString)); |
195 EXPECT_TRUE(scanner.scanRun(word, fooString)); | 195 EXPECT_TRUE(scanner.scanRun(word, fooString)); |
196 | 196 |
197 EXPECT_TRUE(scanner.match(':')); | 197 EXPECT_TRUE(scanner.match(':')); |
198 EXPECT_TRUE(scanner.scan(':')); | 198 EXPECT_TRUE(scanner.scan(':')); |
199 | 199 |
| 200 // Skip 'baz'. |
| 201 scanner.skipRun(scanner.collectWhile<lowerCaseAlpha>()); |
| 202 |
| 203 EXPECT_TRUE(scanner.match(':')); |
| 204 EXPECT_TRUE(scanner.scan(':')); |
| 205 |
200 word = scanner.collectWhile<lowerCaseAlpha>(); | 206 word = scanner.collectWhile<lowerCaseAlpha>(); |
201 EXPECT_FALSE(scanner.scanRun(word, fooString)); | 207 EXPECT_FALSE(scanner.scanRun(word, fooString)); |
202 EXPECT_TRUE(scanner.scanRun(word, barString)); | 208 EXPECT_TRUE(scanner.scanRun(word, barString)); |
203 EXPECT_TRUE(scanner.isAtEnd()); | 209 EXPECT_TRUE(scanner.isAtEnd()); |
204 } | 210 } |
205 | 211 |
206 // Tests scanRun/skipRun. | 212 // Tests scanRun/skipRun. |
207 TEST(VTTScanner, RunScanning) | 213 TEST(VTTScanner, RunScanning) |
208 { | 214 { |
209 TEST_WITH(scanRuns, "foo:bar"); | 215 TEST_WITH(scanRuns, "foo:baz:bar"); |
210 } | 216 } |
211 | 217 |
212 void scanRunsToStrings(const String& input) | 218 void scanRunsToStrings(const String& input) |
213 { | 219 { |
214 VTTScanner scanner(input); | 220 VTTScanner scanner(input); |
215 EXPECT_FALSE(scanner.isAtEnd()); | 221 EXPECT_FALSE(scanner.isAtEnd()); |
216 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); | 222 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); |
217 String fooString = scanner.extractString(word); | 223 String fooString = scanner.extractString(word); |
218 EXPECT_EQ(fooString, "foo"); | 224 EXPECT_EQ(fooString, "foo"); |
219 EXPECT_TRUE(scanner.isAt(word.end())); | 225 EXPECT_TRUE(scanner.isAt(word.end())); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // Tests scanDigits(). | 300 // Tests scanDigits(). |
295 TEST(VTTScanner, ScanDigits) | 301 TEST(VTTScanner, ScanDigits) |
296 { | 302 { |
297 TEST_WITH(scanDigits1, "foo 123 bar 45678"); | 303 TEST_WITH(scanDigits1, "foo 123 bar 45678"); |
298 TEST_WITH(scanDigits2, "-654 1000000000000000000"); | 304 TEST_WITH(scanDigits2, "-654 1000000000000000000"); |
299 } | 305 } |
300 | 306 |
301 #undef TEST_WITH | 307 #undef TEST_WITH |
302 | 308 |
303 } // namespace | 309 } // namespace |
OLD | NEW |