OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CSSParserToken.h" | 5 #include "core/css/parser/CSSParserToken.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 static CSSParserString toParserString(const String& string) | 11 static CSSParserToken ident(const String& string) { return CSSParserToken(IdentT
oken, string); } |
12 { | |
13 CSSParserString result; | |
14 result.init(string); | |
15 return result; | |
16 } | |
17 | |
18 static CSSParserToken ident(const String& string) { return CSSParserToken(IdentT
oken, toParserString(string)); } | |
19 static CSSParserToken dimension(double value, const String& unit) | 12 static CSSParserToken dimension(double value, const String& unit) |
20 { | 13 { |
21 CSSParserToken token(NumberToken, value, NumberValueType, NoSign); | 14 CSSParserToken token(NumberToken, value, NumberValueType, NoSign); |
22 token.convertToDimensionWithUnit(toParserString(unit)); | 15 token.convertToDimensionWithUnit(unit); |
23 return token; | 16 return token; |
24 } | 17 } |
25 | 18 |
26 TEST(CSSParserTokenTest, IdentTokenEquality) | 19 TEST(CSSParserTokenTest, IdentTokenEquality) |
27 { | 20 { |
28 String foo8Bit("foo"); | 21 String foo8Bit("foo"); |
29 String bar8Bit("bar"); | 22 String bar8Bit("bar"); |
30 String foo16Bit = String::make16BitFrom8BitSource(foo8Bit.characters8(), foo
8Bit.length()); | 23 String foo16Bit = String::make16BitFrom8BitSource(foo8Bit.characters8(), foo
8Bit.length()); |
31 | 24 |
32 EXPECT_EQ(ident(foo8Bit), ident(foo16Bit)); | 25 EXPECT_EQ(ident(foo8Bit), ident(foo16Bit)); |
33 EXPECT_EQ(ident(foo16Bit), ident(foo8Bit)); | 26 EXPECT_EQ(ident(foo16Bit), ident(foo8Bit)); |
34 EXPECT_EQ(ident(foo16Bit), ident(foo16Bit)); | 27 EXPECT_EQ(ident(foo16Bit), ident(foo16Bit)); |
35 EXPECT_NE(ident(bar8Bit), ident(foo8Bit)); | 28 EXPECT_NE(ident(bar8Bit), ident(foo8Bit)); |
36 EXPECT_NE(ident(bar8Bit), ident(foo16Bit)); | 29 EXPECT_NE(ident(bar8Bit), ident(foo16Bit)); |
37 } | 30 } |
38 | 31 |
39 TEST(CSSParserTokenTest, DimensionTokenEquality) | 32 TEST(CSSParserTokenTest, DimensionTokenEquality) |
40 { | 33 { |
41 String em8Bit("em"); | 34 String em8Bit("em"); |
42 String rem8Bit("rem"); | 35 String rem8Bit("rem"); |
43 String em16Bit = String::make16BitFrom8BitSource(em8Bit.characters8(), em8Bi
t.length()); | 36 String em16Bit = String::make16BitFrom8BitSource(em8Bit.characters8(), em8Bi
t.length()); |
44 | 37 |
45 EXPECT_EQ(dimension(1, em8Bit), dimension(1, em16Bit)); | 38 EXPECT_EQ(dimension(1, em8Bit), dimension(1, em16Bit)); |
46 EXPECT_EQ(dimension(1, em8Bit), dimension(1, em8Bit)); | 39 EXPECT_EQ(dimension(1, em8Bit), dimension(1, em8Bit)); |
47 EXPECT_NE(dimension(1, em8Bit), dimension(1, rem8Bit)); | 40 EXPECT_NE(dimension(1, em8Bit), dimension(1, rem8Bit)); |
48 EXPECT_NE(dimension(2, em8Bit), dimension(1, em16Bit)); | 41 EXPECT_NE(dimension(2, em8Bit), dimension(1, em16Bit)); |
49 } | 42 } |
50 | 43 |
51 } // namespace blink | 44 } // namespace blink |
OLD | NEW |