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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/track/vtt/VTTScannerTest.cpp
diff --git a/Source/core/html/track/vtt/VTTScannerTest.cpp b/Source/core/html/track/vtt/VTTScannerTest.cpp
index be672bdc2efb645b79e058952afc130a302fa34e..5e0393458af7bbc7915eaea0927b0392e69067b8 100644
--- a/Source/core/html/track/vtt/VTTScannerTest.cpp
+++ b/Source/core/html/track/vtt/VTTScannerTest.cpp
@@ -152,6 +152,88 @@ TEST(VTTScanner, PredicateScanning)
TEST_WITH(scanWithPredicate, "badAbing");
}
+void scanWithInvPredicate(const String& input)
+{
+ VTTScanner scanner(input);
+ EXPECT_FALSE(scanner.isAtEnd());
+ // Collect "BAD".
+ VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>();
+ // collectUntil doesn't move the scan position.
+ EXPECT_TRUE(scanner.match('B'));
+ // Consume "BAD".
+ scanner.skipRun(ucRun);
+ EXPECT_TRUE(scanner.match('a'));
+ EXPECT_TRUE(scanner.isAt(ucRun.end()));
+
+ // Consume "a".
+ EXPECT_TRUE(scanner.scan('a'));
+
+ // Collect "BING".
+ ucRun = scanner.collectUntil<lowerCaseAlpha>();
+ // collectUntil doesn't move the scan position.
+ EXPECT_FALSE(scanner.isAtEnd());
+ // Consume "BING".
+ scanner.skipRun(ucRun);
+ EXPECT_TRUE(scanner.isAt(ucRun.end()));
+ EXPECT_TRUE(scanner.isAtEnd());
+}
+
+// Tests collectUntil().
+TEST(VTTScanner, InversePredicateScanning)
+{
+ TEST_WITH(scanWithInvPredicate, "BADaBING");
+}
+
+void scanRuns(const String& input)
+{
+ String fooString("foo");
+ String barString("bar");
+ VTTScanner scanner(input);
+ EXPECT_FALSE(scanner.isAtEnd());
+ VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>();
+ EXPECT_FALSE(scanner.scanRun(word, barString));
+ EXPECT_TRUE(scanner.scanRun(word, fooString));
+
+ EXPECT_TRUE(scanner.match(':'));
+ EXPECT_TRUE(scanner.scan(':'));
+
+ word = scanner.collectWhile<lowerCaseAlpha>();
+ EXPECT_FALSE(scanner.scanRun(word, fooString));
+ EXPECT_TRUE(scanner.scanRun(word, barString));
+ EXPECT_TRUE(scanner.isAtEnd());
+}
+
+// Tests scanRun/skipRun.
+TEST(VTTScanner, RunScanning)
+{
+ TEST_WITH(scanRuns, "foo:bar");
+}
+
+void scanRunsToStrings(const String& input)
+{
+ VTTScanner scanner(input);
+ EXPECT_FALSE(scanner.isAtEnd());
+ VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>();
+ String fooString = scanner.extractString(word);
+ EXPECT_EQ(fooString, "foo");
+ EXPECT_TRUE(scanner.isAt(word.end()));
+
+ EXPECT_TRUE(scanner.match(':'));
+ EXPECT_TRUE(scanner.scan(':'));
+
+ word = scanner.collectWhile<lowerCaseAlpha>();
+ String barString = scanner.extractString(word);
+ EXPECT_EQ(barString, "bar");
+ EXPECT_TRUE(scanner.isAt(word.end()));
+ EXPECT_TRUE(scanner.isAtEnd());
+}
+
+// Tests extractString.
+TEST(VTTScanner, ExtractString)
+{
+ TEST_WITH(scanRunsToStrings, "foo:bar");
+}
+
void tailStringExtract(const String& input)
{
VTTScanner scanner(input);
« 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