Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/MediaQueryTokenizer.h" | 6 #include "core/css/parser/MediaQueryTokenizer.h" |
| 7 | 7 |
| 8 #include "wtf/PassOwnPtr.h" | 8 #include "wtf/PassOwnPtr.h" |
| 9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
| 10 | 10 |
| 11 namespace WebCore { | 11 namespace WebCore { |
| 12 | 12 |
| 13 typedef pair<String, MediaQueryTokenType* > TestCase; | 13 typedef pair<String, MediaQueryTokenType* > TestCase; |
| 14 TEST(MediaQueryTokenizerTest, Basic) | 14 TEST(MediaQueryTokenizerTest, Basic) |
| 15 { | 15 { |
| 16 Vector<TestCase> testcases; | 16 Vector<TestCase> testcases; |
| 17 MediaQueryTokenType tokenTypeArr[] = {LeftParenthesisToken, IdentToken, Colo nToken, WhitespaceToken, PercentageToken, RightParenthesisToken, EOFToken }; | 17 MediaQueryTokenType tokenTypeArr[] = {LeftParenthesisToken, IdentToken, Colo nToken, WhitespaceToken, PercentageToken, RightParenthesisToken, EOFToken }; |
| 18 TestCase testCase1("(max-width: 50%)", (MediaQueryTokenType*)&tokenTypeArr); | 18 TestCase testCase1("(max-width: 50%)", (MediaQueryTokenType*)&tokenTypeArr); |
| 19 testcases.append(testCase1); | 19 testcases.append(testCase1); |
| 20 Vector<MediaQueryToken> tokens; | 20 Vector<MediaQueryToken> tokens; |
| 21 MediaQueryTokenizer::tokenize(testcases[0].first, tokens); | 21 MediaQueryTokenizer::tokenize(testcases[0].first, tokens); |
| 22 for (size_t i = 0; i < tokens.size(); i++) { | 22 for (size_t i = 0; i < tokens.size(); i++) { |
| 23 ASSERT_EQ(testcases[0].second[i], tokens[i].type()); | 23 ASSERT_EQ(testcases[0].second[i], tokens[i].type()); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 void testToken(UChar c, MediaQueryTokenType tokenType) | |
| 28 { | |
| 29 Vector<MediaQueryToken> tokens; | |
| 30 StringBuilder input; | |
| 31 input.append(c); | |
| 32 MediaQueryTokenizer::tokenize(input.toString(), tokens); | |
| 33 ASSERT_EQ(tokens[0].type(), tokenType); | |
| 34 } | |
| 35 | |
| 36 TEST(MediaQueryTokenizerCodepointsTest, Basic) | |
| 37 { | |
| 38 for (UChar c = 0; c <= SCHAR_MAX; ++c) { | |
| 39 if (isASCIIDigit(c)) | |
| 40 testToken(c, NumberToken); | |
| 41 else if (isASCIIAlpha(c)) | |
| 42 testToken(c, IdentToken); | |
| 43 else if (c == '_') | |
| 44 testToken(c, IdentToken); | |
| 45 else if (c == '\r' || c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
| 46 testToken(c, WhitespaceToken); | |
| 47 else if (c == '(') | |
| 48 testToken(c, LeftParenthesisToken); | |
| 49 else if (c == ')') | |
| 50 testToken(c, RightParenthesisToken); | |
| 51 else if (c == '.' || c == '+' || c == '-' || c == '/' || c == '\\') | |
| 52 testToken(c, DelimiterToken); | |
| 53 else if (c == ',') | |
| 54 testToken(c, CommaToken); | |
| 55 else if (c == ':') | |
| 56 testToken(c, ColonToken); | |
| 57 else if (c == ';') | |
| 58 testToken(c, SemicolonToken); | |
| 59 else if (!c) | |
| 60 testToken(c, EOFToken); | |
| 61 else | |
| 62 testToken(c, DelimiterToken); | |
| 63 } | |
| 64 testToken(1098, IdentToken); | |
|
eseidel
2014/03/18 21:29:53
So everything above SCHAR_MAX is an IdentToken, co
| |
| 65 } | |
| 66 | |
| 27 } // namespace | 67 } // namespace |
| OLD | NEW |