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

Side by Side Diff: Source/core/css/parser/MediaQueryTokenizerTest.cpp

Issue 203343004: Fixed an assert related to MediaQuerytokenizer code points table (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: A better test Created 6 years, 9 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
« no previous file with comments | « Source/core/css/parser/MediaQueryTokenizer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 <= 1000; ++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 if (c > SCHAR_MAX)
62 testToken(c, IdentToken);
63 else
64 testToken(c, DelimiterToken);
65 }
66 testToken(USHRT_MAX, IdentToken);
67 }
68
27 } // namespace 69 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/parser/MediaQueryTokenizer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698