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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSTokenizerTest.cpp

Issue 2024373002: Replace CSSParserString with StringView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Match arguments to equalStringView. Created 4 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "core/css/parser/CSSTokenizer.h" 5 #include "core/css/parser/CSSTokenizer.h"
6 6
7 #include "core/css/parser/CSSParserTokenRange.h" 7 #include "core/css/parser/CSSParserTokenRange.h"
8 #include "core/css/parser/MediaQueryBlockWatcher.h" 8 #include "core/css/parser/MediaQueryBlockWatcher.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/allocator/Partitions.h" 10 #include "wtf/allocator/Partitions.h"
(...skipping 11 matching lines...) Expand all
22 { 22 {
23 ASSERT_EQ(expected.type(), actual.type()); 23 ASSERT_EQ(expected.type(), actual.type());
24 switch (expected.type()) { 24 switch (expected.type()) {
25 case DelimiterToken: 25 case DelimiterToken:
26 ASSERT_EQ(expected.delimiter(), actual.delimiter()); 26 ASSERT_EQ(expected.delimiter(), actual.delimiter());
27 break; 27 break;
28 case IdentToken: 28 case IdentToken:
29 case FunctionToken: 29 case FunctionToken:
30 case StringToken: 30 case StringToken:
31 case UrlToken: 31 case UrlToken:
32 ASSERT_EQ(String(expected.value()), String(actual.value())); 32 ASSERT_EQ(expected.value(), actual.value());
33 break; 33 break;
34 case DimensionToken: 34 case DimensionToken:
35 ASSERT_EQ(String(expected.value()), String(actual.value())); 35 ASSERT_EQ(expected.value(), actual.value());
36 ASSERT_EQ(expected.numericValueType(), actual.numericValueType()); 36 ASSERT_EQ(expected.numericValueType(), actual.numericValueType());
37 ASSERT_DOUBLE_EQ(expected.numericValue(), actual.numericValue()); 37 ASSERT_DOUBLE_EQ(expected.numericValue(), actual.numericValue());
38 break; 38 break;
39 case NumberToken: 39 case NumberToken:
40 ASSERT_EQ(expected.numericSign(), actual.numericSign()); 40 ASSERT_EQ(expected.numericSign(), actual.numericSign());
41 // fallthrough 41 // fallthrough
42 case PercentageToken: 42 case PercentageToken:
43 ASSERT_EQ(expected.numericValueType(), actual.numericValueType()); 43 ASSERT_EQ(expected.numericValueType(), actual.numericValueType());
44 ASSERT_DOUBLE_EQ(expected.numericValue(), actual.numericValue()); 44 ASSERT_DOUBLE_EQ(expected.numericValue(), actual.numericValue());
45 break; 45 break;
46 case UnicodeRangeToken: 46 case UnicodeRangeToken:
47 ASSERT_EQ(expected.unicodeRangeStart(), actual.unicodeRangeStart()); 47 ASSERT_EQ(expected.unicodeRangeStart(), actual.unicodeRangeStart());
48 ASSERT_EQ(expected.unicodeRangeEnd(), actual.unicodeRangeEnd()); 48 ASSERT_EQ(expected.unicodeRangeEnd(), actual.unicodeRangeEnd());
49 break; 49 break;
50 case HashToken: 50 case HashToken:
51 ASSERT_EQ(String(expected.value()), String(actual.value())); 51 ASSERT_EQ(expected.value(), actual.value());
52 ASSERT_EQ(expected.getHashTokenType(), actual.getHashTokenType()); 52 ASSERT_EQ(expected.getHashTokenType(), actual.getHashTokenType());
53 break; 53 break;
54 default: 54 default:
55 break; 55 break;
56 } 56 }
57 } 57 }
58 58
59 void testTokens(const String& string, const CSSParserToken& token1, const CSSPar serToken& token2 = CSSParserToken(EOFToken), const CSSParserToken& token3 = CSSP arserToken(EOFToken)) 59 void testTokens(const String& string, const CSSParserToken& token1, const CSSPar serToken& token2 = CSSParserToken(EOFToken), const CSSParserToken& token3 = CSSP arserToken(EOFToken))
60 { 60 {
61 Vector<CSSParserToken> expectedTokens; 61 Vector<CSSParserToken> expectedTokens;
62 expectedTokens.append(token1); 62 expectedTokens.append(token1);
63 if (token2.type() != EOFToken) { 63 if (token2.type() != EOFToken) {
64 expectedTokens.append(token2); 64 expectedTokens.append(token2);
65 if (token3.type() != EOFToken) 65 if (token3.type() != EOFToken)
66 expectedTokens.append(token3); 66 expectedTokens.append(token3);
67 } 67 }
68 68
69 CSSParserTokenRange expected(expectedTokens); 69 CSSParserTokenRange expected(expectedTokens);
70 70
71 CSSTokenizer::Scope actualScope(string); 71 CSSTokenizer::Scope actualScope(string);
72 CSSParserTokenRange actual = actualScope.tokenRange(); 72 CSSParserTokenRange actual = actualScope.tokenRange();
73 73
74 // Just check that serialization doesn't hit any asserts 74 // Just check that serialization doesn't hit any asserts
75 actual.serialize(); 75 actual.serialize();
76 76
77 while (!expected.atEnd() || !actual.atEnd()) 77 while (!expected.atEnd() || !actual.atEnd())
78 compareTokens(expected.consume(), actual.consume()); 78 compareTokens(expected.consume(), actual.consume());
79 } 79 }
80 80
81 static CSSParserString toParserString(const String& string) 81 static CSSParserToken ident(const String& string) { return CSSParserToken(IdentT oken, string); }
82 { 82 static CSSParserToken atKeyword(const String& string) { return CSSParserToken(At KeywordToken, string); }
83 CSSParserString result; 83 static CSSParserToken string(const String& string) { return CSSParserToken(Strin gToken, string); }
84 result.init(string); 84 static CSSParserToken function(const String& string) { return CSSParserToken(Fun ctionToken, string); }
85 return result; 85 static CSSParserToken url(const String& string) { return CSSParserToken(UrlToken , string); }
86 } 86 static CSSParserToken hash(const String& string, HashTokenType type) { return CS SParserToken(type, string); }
87
88 static CSSParserToken ident(const String& string) { return CSSParserToken(IdentT oken, toParserString(string)); }
89 static CSSParserToken atKeyword(const String& string) { return CSSParserToken(At KeywordToken, toParserString(string)); }
90 static CSSParserToken string(const String& string) { return CSSParserToken(Strin gToken, toParserString(string)); }
91 static CSSParserToken function(const String& string) { return CSSParserToken(Fun ctionToken, toParserString(string)); }
92 static CSSParserToken url(const String& string) { return CSSParserToken(UrlToken , toParserString(string)); }
93 static CSSParserToken hash(const String& string, HashTokenType type) { return CS SParserToken(type, toParserString(string)); }
94 static CSSParserToken delim(char c) { return CSSParserToken(DelimiterToken, c); } 87 static CSSParserToken delim(char c) { return CSSParserToken(DelimiterToken, c); }
95 88
96 static CSSParserToken unicodeRange(UChar32 start, UChar32 end) 89 static CSSParserToken unicodeRange(UChar32 start, UChar32 end)
97 { 90 {
98 return CSSParserToken(UnicodeRangeToken, start, end); 91 return CSSParserToken(UnicodeRangeToken, start, end);
99 } 92 }
100 93
101 static CSSParserToken number(NumericValueType type, double value, NumericSign si gn) 94 static CSSParserToken number(NumericValueType type, double value, NumericSign si gn)
102 { 95 {
103 return CSSParserToken(NumberToken, value, type, sign); 96 return CSSParserToken(NumberToken, value, type, sign);
104 } 97 }
105 98
106 static CSSParserToken dimension(NumericValueType type, double value, const Strin g& string) 99 static CSSParserToken dimension(NumericValueType type, double value, const Strin g& string)
107 { 100 {
108 CSSParserToken token = number(type, value, NoSign); // sign ignored 101 CSSParserToken token = number(type, value, NoSign); // sign ignored
109 token.convertToDimensionWithUnit(toParserString(string)); 102 token.convertToDimensionWithUnit(string);
110 return token; 103 return token;
111 } 104 }
112 105
113 static CSSParserToken percentage(NumericValueType type, double value) 106 static CSSParserToken percentage(NumericValueType type, double value)
114 { 107 {
115 CSSParserToken token = number(type, value, NoSign); // sign ignored 108 CSSParserToken token = number(type, value, NoSign); // sign ignored
116 token.convertToPercentage(); 109 token.convertToPercentage();
117 return token; 110 return token;
118 } 111 }
119 112
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 blockWatcher.handleToken(range.consume()); 486 blockWatcher.handleToken(range.consume());
494 level = blockWatcher.blockLevel(); 487 level = blockWatcher.blockLevel();
495 maxLevel = std::max(level, maxLevel); 488 maxLevel = std::max(level, maxLevel);
496 } 489 }
497 ASSERT_EQ(testCases[i].maxLevel, maxLevel); 490 ASSERT_EQ(testCases[i].maxLevel, maxLevel);
498 ASSERT_EQ(testCases[i].finalLevel, level); 491 ASSERT_EQ(testCases[i].finalLevel, level);
499 } 492 }
500 } 493 }
501 494
502 } // namespace blink 495 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698