Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: Source/core/html/track/vtt/VTTScannerTest.cpp

Issue 134153002: Use VTTScanner for VTT cue settings parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 EXPECT_TRUE(scanner.isAt(lcRun.end())); 145 EXPECT_TRUE(scanner.isAt(lcRun.end()));
146 EXPECT_TRUE(scanner.isAtEnd()); 146 EXPECT_TRUE(scanner.isAtEnd());
147 } 147 }
148 148
149 // Tests skipWhile() and collectWhile(). 149 // Tests skipWhile() and collectWhile().
150 TEST(VTTScanner, PredicateScanning) 150 TEST(VTTScanner, PredicateScanning)
151 { 151 {
152 TEST_WITH(scanWithPredicate, "badAbing"); 152 TEST_WITH(scanWithPredicate, "badAbing");
153 } 153 }
154 154
155 void scanWithInvPredicate(const String& input)
156 {
157 VTTScanner scanner(input);
158 EXPECT_FALSE(scanner.isAtEnd());
159 // Collect "BAD".
160 VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>();
161 // collectUntil doesn't move the scan position.
162 EXPECT_TRUE(scanner.match('B'));
163 // Consume "BAD".
164 scanner.skipRun(ucRun);
165 EXPECT_TRUE(scanner.match('a'));
166 EXPECT_TRUE(scanner.isAt(ucRun.end()));
167
168 // Consume "a".
169 EXPECT_TRUE(scanner.scan('a'));
170
171 // Collect "BING".
172 ucRun = scanner.collectUntil<lowerCaseAlpha>();
173 // collectUntil doesn't move the scan position.
174 EXPECT_FALSE(scanner.isAtEnd());
175 // Consume "BING".
176 scanner.skipRun(ucRun);
177 EXPECT_TRUE(scanner.isAt(ucRun.end()));
178 EXPECT_TRUE(scanner.isAtEnd());
179 }
180
181 // Tests collectUntil().
182 TEST(VTTScanner, InversePredicateScanning)
183 {
184 TEST_WITH(scanWithInvPredicate, "BADaBING");
185 }
186
187 void scanRuns(const String& input)
188 {
189 String fooString("foo");
190 String barString("bar");
191 VTTScanner scanner(input);
192 EXPECT_FALSE(scanner.isAtEnd());
193 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>();
194 EXPECT_FALSE(scanner.scanRun(word, barString));
195 EXPECT_TRUE(scanner.scanRun(word, fooString));
196
197 EXPECT_TRUE(scanner.match(':'));
198 EXPECT_TRUE(scanner.scan(':'));
199
200 word = scanner.collectWhile<lowerCaseAlpha>();
201 EXPECT_FALSE(scanner.scanRun(word, fooString));
202 EXPECT_TRUE(scanner.scanRun(word, barString));
203 EXPECT_TRUE(scanner.isAtEnd());
204 }
205
206 // Tests scanRun/skipRun.
207 TEST(VTTScanner, RunScanning)
208 {
209 TEST_WITH(scanRuns, "foo:bar");
210 }
211
212 void scanRunsToStrings(const String& input)
213 {
214 VTTScanner scanner(input);
215 EXPECT_FALSE(scanner.isAtEnd());
216 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>();
217 String fooString = scanner.extractString(word);
218 EXPECT_EQ(fooString, "foo");
219 EXPECT_TRUE(scanner.isAt(word.end()));
220
221 EXPECT_TRUE(scanner.match(':'));
222 EXPECT_TRUE(scanner.scan(':'));
223
224 word = scanner.collectWhile<lowerCaseAlpha>();
225 String barString = scanner.extractString(word);
226 EXPECT_EQ(barString, "bar");
227 EXPECT_TRUE(scanner.isAt(word.end()));
228 EXPECT_TRUE(scanner.isAtEnd());
229 }
230
231 // Tests extractString.
232 TEST(VTTScanner, ExtractString)
233 {
234 TEST_WITH(scanRunsToStrings, "foo:bar");
235 }
236
155 void tailStringExtract(const String& input) 237 void tailStringExtract(const String& input)
156 { 238 {
157 VTTScanner scanner(input); 239 VTTScanner scanner(input);
158 EXPECT_TRUE(scanner.scan("foo")); 240 EXPECT_TRUE(scanner.scan("foo"));
159 EXPECT_TRUE(scanner.scan(':')); 241 EXPECT_TRUE(scanner.scan(':'));
160 String barSuffix = scanner.restOfInputAsString(); 242 String barSuffix = scanner.restOfInputAsString();
161 EXPECT_EQ(barSuffix, "bar"); 243 EXPECT_EQ(barSuffix, "bar");
162 244
163 EXPECT_TRUE(scanner.isAtEnd()); 245 EXPECT_TRUE(scanner.isAtEnd());
164 } 246 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // Tests scanDigits(). 294 // Tests scanDigits().
213 TEST(VTTScanner, ScanDigits) 295 TEST(VTTScanner, ScanDigits)
214 { 296 {
215 TEST_WITH(scanDigits1, "foo 123 bar 45678"); 297 TEST_WITH(scanDigits1, "foo 123 bar 45678");
216 TEST_WITH(scanDigits2, "-654 1000000000000000000"); 298 TEST_WITH(scanDigits2, "-654 1000000000000000000");
217 } 299 }
218 300
219 #undef TEST_WITH 301 #undef TEST_WITH
220 302
221 } // namespace 303 } // namespace
OLDNEW
« Source/core/html/track/vtt/VTTCue.cpp ('K') | « Source/core/html/track/vtt/VTTScanner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698