OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSSelectorParser.h" | 6 #include "core/css/parser/CSSSelectorParser.h" |
7 | 7 |
8 #include "core/css/parser/CSSTokenizer.h" | 8 #include "core/css/parser/CSSTokenizer.h" |
9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 {"+n + 61", 1, 61}, | 66 {"+n + 61", 1, 61}, |
67 {"+N - 63", 1, -63}, | 67 {"+N - 63", 1, -63}, |
68 {"+n/**/- 48", 1, -48}, | 68 {"+n/**/- 48", 1, -48}, |
69 {"-n + 81", -1, 81}, | 69 {"-n + 81", -1, 81}, |
70 {"-N - 88", -1, -88}, | 70 {"-N - 88", -1, -88}, |
71 }; | 71 }; |
72 | 72 |
73 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) { | 73 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) { |
74 SCOPED_TRACE(testCases[i].input); | 74 SCOPED_TRACE(testCases[i].input); |
75 | 75 |
76 Vector<CSSParserToken> tokens; | |
77 CSSTokenizer::tokenize(testCases[i].input, tokens); | |
78 CSSParserTokenRange range(tokens); | |
79 | |
80 std::pair<int, int> ab; | 76 std::pair<int, int> ab; |
| 77 CSSTokenizer::Scope scope(testCases[i].input); |
| 78 CSSParserTokenRange range = scope.tokenRange(); |
81 bool passed = CSSSelectorParser::consumeANPlusB(range, ab); | 79 bool passed = CSSSelectorParser::consumeANPlusB(range, ab); |
82 EXPECT_TRUE(passed); | 80 EXPECT_TRUE(passed); |
83 EXPECT_EQ(ab.first, testCases[i].a); | 81 EXPECT_EQ(ab.first, testCases[i].a); |
84 EXPECT_EQ(ab.second, testCases[i].b); | 82 EXPECT_EQ(ab.second, testCases[i].b); |
85 } | 83 } |
86 } | 84 } |
87 | 85 |
88 TEST(CSSSelectorParserTest, InvalidANPlusB) | 86 TEST(CSSSelectorParserTest, InvalidANPlusB) |
89 { | 87 { |
90 // Some of these have token range prefixes which are valid <an+b> and could | 88 // Some of these have token range prefixes which are valid <an+b> and could |
91 // in theory be valid in consumeANPlusB, but this behaviour isn't needed | 89 // in theory be valid in consumeANPlusB, but this behaviour isn't needed |
92 // anywhere and not implemented. | 90 // anywhere and not implemented. |
93 const char* testCases[] = { | 91 const char* testCases[] = { |
94 " odd", | 92 " odd", |
95 "+ n", | 93 "+ n", |
96 "3m+4", | 94 "3m+4", |
97 "12n--34", | 95 "12n--34", |
98 "12n- -34", | 96 "12n- -34", |
99 "12n- +34", | 97 "12n- +34", |
100 "23n-+43", | 98 "23n-+43", |
101 "10n 5", | 99 "10n 5", |
102 "10n + +5", | 100 "10n + +5", |
103 "10n + -5", | 101 "10n + -5", |
104 }; | 102 }; |
105 | 103 |
106 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) { | 104 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(testCases); ++i) { |
107 SCOPED_TRACE(testCases[i]); | 105 SCOPED_TRACE(testCases[i]); |
108 | 106 |
109 Vector<CSSParserToken> tokens; | |
110 CSSTokenizer::tokenize(testCases[i], tokens); | |
111 CSSParserTokenRange range(tokens); | |
112 | |
113 std::pair<int, int> ab; | 107 std::pair<int, int> ab; |
| 108 CSSTokenizer::Scope scope(testCases[i]); |
| 109 CSSParserTokenRange range = scope.tokenRange(); |
114 bool passed = CSSSelectorParser::consumeANPlusB(range, ab); | 110 bool passed = CSSSelectorParser::consumeANPlusB(range, ab); |
115 EXPECT_FALSE(passed); | 111 EXPECT_FALSE(passed); |
116 } | 112 } |
117 } | 113 } |
118 | 114 |
119 } // namespace | 115 } // namespace |
OLD | NEW |