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/CSSTokenizer.h" | 6 #include "core/css/parser/CSSTokenizer.h" |
| 7 | 7 |
| 8 #include "core/css/parser/MediaQueryBlockWatcher.h" | 8 #include "core/css/parser/MediaQueryBlockWatcher.h" |
| 9 #include "wtf/PassOwnPtr.h" | 9 #include "wtf/PassOwnPtr.h" |
| 10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 typedef struct { | 14 typedef struct { |
| 15 const char* input; | 15 const char* input; |
| 16 const char* output; | 16 const char* output; |
| 17 } TestCase; | 17 } TestCase; |
| 18 | 18 |
| 19 typedef struct { | 19 typedef struct { |
| 20 const char* input; | 20 const char* input; |
| 21 const unsigned maxLevel; | 21 const unsigned maxLevel; |
| 22 const unsigned finalLevel; | 22 const unsigned finalLevel; |
| 23 } BlockTestCase; | 23 } BlockTestCase; |
| 24 | 24 |
| 25 TEST(CSSTokenizerTest, Basic) | 25 TEST(CSSTokenizerTest, Basic) |
| 26 { | 26 { |
| 27 TestCase testCases[] = { | 27 TestCase testCases[] = { |
| 28 { "(max-width: 50px)", "(max-width: 50px)" }, | 28 { "(max-width: 50px)", "(max-width: 50px)" }, |
| 29 { "(max-width: 1e+2px)", "(max-width: 100px)" }, | 29 { "(max-width: 1e+2px)", "(max-width: 100.000000px)" }, |
| 30 { "(max-width: 1e2px)", "(max-width: 100px)" }, | 30 { "(max-width: 1e2px)", "(max-width: 100.000000px)" }, |
| 31 { "(max-width: 1000e-1px)", "(max-width: 100px)" }, | 31 { "(max-width: 1000e-1px)", "(max-width: 100.000000px)" }, |
|
Yoav Weiss
2014/10/20 07:06:46
These tests would fail on some system locales, whe
Timothy Loh
2014/10/20 07:18:24
Good catch. There's probably a more appropriate fl
| |
| 32 { "(max-width: 50\\70\\78)", "(max-width: 50px)" }, | 32 { "(max-width: 50\\70\\78)", "(max-width: 50px)" }, |
| 33 { "(max-width: /* comment */50px)", "(max-width: 50px)" }, | 33 { "(max-width: /* comment */50px)", "(max-width: 50px)" }, |
| 34 { "(max-width: /** *commen*t */60px)", "(max-width: 60px)" }, | 34 { "(max-width: /** *commen*t */60px)", "(max-width: 60px)" }, |
| 35 { "(max-width: /** *commen*t **/70px)", "(max-width: 70px)" }, | 35 { "(max-width: /** *commen*t **/70px)", "(max-width: 70px)" }, |
| 36 { "(max-width: /** *commen*t **//**/80px)", "(max-width: 80px)" }, | 36 { "(max-width: /** *commen*t **//**/80px)", "(max-width: 80px)" }, |
| 37 { "(max-width: /*/ **/90px)", "(max-width: 90px)" }, | 37 { "(max-width: /*/ **/90px)", "(max-width: 90px)" }, |
| 38 { "(max-width: /*/ **/*100px)", "(max-width: '*'100px)" }, | 38 { "(max-width: /*/ **/*100px)", "(max-width: '*'100px)" }, |
| 39 { "(max-width: 110px/*)", "(max-width: 110px" }, | 39 { "(max-width: 110px/*)", "(max-width: 110px" }, |
| 40 { "(max-width: 120px)/*", "(max-width: 120px)" }, | 40 { "(max-width: 120px)/*", "(max-width: 120px)" }, |
| 41 { "(max-width: 130px)/**", "(max-width: 130px)" }, | 41 { "(max-width: 130px)/**", "(max-width: 130px)" }, |
| 42 { "(max-width: /***/140px)/**/", "(max-width: 140px)" }, | 42 { "(max-width: /***/140px)/**/", "(max-width: 140px)" }, |
| 43 { "(max-width: '40px')", "(max-width: 40px)" }, | 43 { "(max-width: '40px')", "(max-width: 40px)" }, |
| 44 { "(max-width: '40px", "(max-width: 40px" }, | 44 { "(max-width: '40px", "(max-width: 40px" }, |
| 45 { "(max-width: '40px\n", "(max-width: " }, | 45 { "(max-width: '40px\n", "(max-width: " }, |
| 46 { "(max-width: '40px\\", "(max-width: 40px" }, | 46 { "(max-width: '40px\\", "(max-width: 40px" }, |
| 47 { "(max-width: '40px\\\n", "(max-width: 40px" }, | 47 { "(max-width: '40px\\\n", "(max-width: 40px" }, |
| 48 { "(max-width: '40px\\\n')", "(max-width: 40px)" }, | 48 { "(max-width: '40px\\\n')", "(max-width: 40px)" }, |
| 49 { "(max-width: '40\\70\\78')", "(max-width: 40px)" }, | 49 { "(max-width: '40\\70\\78')", "(max-width: 40px)" }, |
| 50 { "(max-width: '40\\\npx')", "(max-width: 40px)" }, | 50 { "(max-width: '40\\\npx')", "(max-width: 40px)" }, |
| 51 { "(max-aspect-ratio: 5)", "(max-aspect-ratio: 5)" }, | 51 { "(max-aspect-ratio: 5)", "(max-aspect-ratio: 5)" }, |
| 52 { "(max-aspect-ratio: +5)", "(max-aspect-ratio: 5)" }, | 52 { "(max-aspect-ratio: +5)", "(max-aspect-ratio: 5)" }, |
| 53 { "(max-aspect-ratio: -5)", "(max-aspect-ratio: -5)" }, | 53 { "(max-aspect-ratio: -5)", "(max-aspect-ratio: -5)" }, |
| 54 { "(max-aspect-ratio: -+5)", "(max-aspect-ratio: '-'5)" }, | 54 { "(max-aspect-ratio: -+5)", "(max-aspect-ratio: '-'5)" }, |
| 55 { "(max-aspect-ratio: +-5)", "(max-aspect-ratio: '+'-5)" }, | 55 { "(max-aspect-ratio: +-5)", "(max-aspect-ratio: '+'-5)" }, |
| 56 { "(max-aspect-ratio: +bla5)", "(max-aspect-ratio: '+'bla5)" }, | 56 { "(max-aspect-ratio: +bla5)", "(max-aspect-ratio: '+'bla5)" }, |
| 57 { "(max-aspect-ratio: +5bla)", "(max-aspect-ratio: 5other)" }, | 57 { "(max-aspect-ratio: +5bla)", "(max-aspect-ratio: 5other)" }, |
| 58 { "(max-aspect-ratio: -bla)", "(max-aspect-ratio: -bla)" }, | 58 { "(max-aspect-ratio: -bla)", "(max-aspect-ratio: -bla)" }, |
| 59 { "(max-aspect-ratio: --bla)", "(max-aspect-ratio: '-'-bla)" }, | 59 { "(max-aspect-ratio: --bla)", "(max-aspect-ratio: '-'-bla)" }, |
| 60 { "5e0", "5.000000" }, | |
| 61 { "5.0", "5.000000" }, | |
| 62 { "5.", "5'.'" }, | |
| 63 { "5.0e-1", "0.500000" }, | |
| 64 { "5.e-1", "5'.'e-1" }, | |
| 60 { 0, 0 } // Do not remove the terminator line. | 65 { 0, 0 } // Do not remove the terminator line. |
| 61 }; | 66 }; |
| 62 | 67 |
| 63 for (int i = 0; testCases[i].input; ++i) { | 68 for (int i = 0; testCases[i].input; ++i) { |
| 64 Vector<CSSParserToken> tokens; | 69 Vector<CSSParserToken> tokens; |
| 65 CSSTokenizer::tokenize(testCases[i].input, tokens); | 70 CSSTokenizer::tokenize(testCases[i].input, tokens); |
| 66 StringBuilder output; | 71 StringBuilder output; |
| 67 for (size_t j = 0; j < tokens.size(); ++j) | 72 for (size_t j = 0; j < tokens.size(); ++j) |
| 68 output.append(tokens[j].textForUnitTests()); | 73 output.append(tokens[j].textForUnitTests()); |
| 69 ASSERT_STREQ(testCases[i].output, output.toString().ascii().data()); | 74 ASSERT_STREQ(testCases[i].output, output.toString().ascii().data()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 testToken(c, EOFToken); | 169 testToken(c, EOFToken); |
| 165 else if (c > SCHAR_MAX) | 170 else if (c > SCHAR_MAX) |
| 166 testToken(c, IdentToken); | 171 testToken(c, IdentToken); |
| 167 else | 172 else |
| 168 testToken(c, DelimiterToken); | 173 testToken(c, DelimiterToken); |
| 169 } | 174 } |
| 170 testToken(USHRT_MAX, IdentToken); | 175 testToken(USHRT_MAX, IdentToken); |
| 171 } | 176 } |
| 172 | 177 |
| 173 } // namespace | 178 } // namespace |
| OLD | NEW |