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

Unified Diff: test/cctest/parsing/test-scanner.cc

Issue 2366573002: [parser] Use Back2() where appropriate. (Closed)
Patch Set: Add comments. Created 4 years, 3 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
« no previous file with comments | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/parsing/test-scanner.cc
diff --git a/test/cctest/parsing/test-scanner.cc b/test/cctest/parsing/test-scanner.cc
index 8821b2a5324ce43041413fcd5758ca5023542f50..2577aa586888219ca43de8ed88b042f335b55d38 100644
--- a/test/cctest/parsing/test-scanner.cc
+++ b/test/cctest/parsing/test-scanner.cc
@@ -25,6 +25,10 @@ std::unique_ptr<Scanner> make_scanner(const char* src) {
} // anonymous namespace
+// DCHECK_TOK checks token equality, but by checking for equality of the token
+// names. That should have the same result, but has much nicer error messaages.
+#define DCHECK_TOK(a, b) DCHECK_EQ(Token::Name(a), Token::Name(b))
+
TEST(Bookmarks) {
// Scan through the given source and record the tokens for use as reference
// below.
@@ -51,12 +55,33 @@ TEST(Bookmarks) {
if (i == bookmark_pos) {
bookmark.Set();
}
- DCHECK_EQ(tokens[i], scanner->Next());
+ DCHECK_TOK(tokens[i], scanner->Next());
}
bookmark.Apply();
for (size_t i = bookmark_pos; i < tokens.size(); i++) {
- DCHECK_EQ(tokens[i], scanner->Next());
+ DCHECK_TOK(tokens[i], scanner->Next());
+ }
+ }
+}
+
+TEST(AllThePushbacks) {
+ const struct {
+ const char* src;
+ const Token::Value tokens[5]; // Large enough for any of the test cases.
+ } test_cases[] = {
+ {"<-x", {Token::LT, Token::SUB, Token::IDENTIFIER, Token::EOS}},
+ {"<!x", {Token::LT, Token::NOT, Token::IDENTIFIER, Token::EOS}},
+ {"<!-x",
+ {Token::LT, Token::NOT, Token::SUB, Token::IDENTIFIER, Token::EOS}},
+ {"<!-- xx -->\nx", {Token::IDENTIFIER, Token::EOS}},
+ };
+
+ for (const auto& test_case : test_cases) {
+ auto scanner = make_scanner(test_case.src);
+ for (size_t i = 0; test_case.tokens[i] != Token::EOS; i++) {
+ DCHECK_TOK(test_case.tokens[i], scanner->Next());
}
+ DCHECK_TOK(Token::EOS, scanner->Next());
}
}
« no previous file with comments | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698