Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/dom/custom/CustomElement.h" | |
| 6 | |
| 7 #include "platform/Logging.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 static void TestIsPotentialCustomElementNameChar(UChar32 c, bool expected) | |
| 13 { | |
| 14 LChar str8[] = "a-X"; | |
| 15 UChar str16[] = { 'a', '-', 'X', '\0', '\0' }; | |
| 16 AtomicString str; | |
| 17 if (c <= 0xFF) { | |
| 18 str8[2] = c; | |
| 19 str = str8; | |
| 20 } else { | |
| 21 size_t i = 2; | |
| 22 U16_APPEND_UNSAFE(str16, i, c); | |
| 23 str16[i] = 0; | |
| 24 str = str16; | |
| 25 } | |
| 26 if (expected) | |
| 27 EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str)) << str; | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
WDYT about making this message more descriptive, e
kojii
2016/04/27 03:52:13
Done, thanks for the suggestion.
| |
| 28 else | |
| 29 EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str)) << str; | |
| 30 } | |
| 31 | |
| 32 TEST(CustomElementTest, TestIsPotentialCustomElementName) | |
| 33 { | |
| 34 struct { | |
| 35 bool expected; | |
| 36 AtomicString str; | |
| 37 } tests[] = { | |
| 38 { false, "" }, | |
| 39 { false, "a" }, | |
| 40 { false, "A" }, | |
| 41 | |
| 42 { false, "A-" }, | |
| 43 { false, "0-" }, | |
| 44 | |
| 45 { true, "a-" }, | |
| 46 { true, "a-a" }, | |
| 47 { true, "aa-" }, | |
| 48 { true, "aa-a" }, | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
WDYT about including some multibyte strings here?
kojii
2016/04/27 03:52:13
Done.
| |
| 49 }; | |
| 50 for (auto test : tests) { | |
| 51 if (test.expected) | |
| 52 EXPECT_TRUE(CustomElement::isPotentialCustomElementName(test.str)) < < test.str; | |
| 53 else | |
| 54 EXPECT_FALSE(CustomElement::isPotentialCustomElementName(test.str)) << test.str; | |
| 55 } | |
| 56 | |
| 57 struct { | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
Let's split these into two tests at this point; an
kojii
2016/04/27 03:52:13
Done.
| |
| 58 UChar32 from, to; | |
| 59 } ranges[] = { | |
| 60 { '-', '.' }, | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
Bit subtle given how the spec treats these, but OK
| |
| 61 { '0', '9' }, | |
| 62 { '_', '_' }, | |
| 63 { 0xB7, 0xB7 }, | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
What about good old a-z? And how about an explicit
kojii
2016/04/27 03:52:13
Done.
| |
| 64 { 0xC0, 0xD6 }, | |
| 65 { 0xD8, 0xF6 }, | |
| 66 { 0xF8, 0x37D }, | |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
See my comment on CharacterPropertyDataGenerator.h
kojii
2016/04/27 03:52:13
Done, added comments.
| |
| 67 { 0x37F, 0x1FFF }, | |
| 68 { 0x200C, 0x200D }, | |
| 69 { 0x203F, 0x2040 }, | |
| 70 { 0x2070, 0x218F }, | |
| 71 { 0x2C00, 0x2FEF }, | |
| 72 { 0x3001, 0xD7FF }, | |
| 73 { 0xF900, 0xFDCF }, | |
| 74 { 0xFDF0, 0xFFFD }, | |
| 75 { 0x10000, 0xEFFFF }, | |
| 76 }; | |
| 77 for (auto range : ranges) { | |
| 78 TestIsPotentialCustomElementNameChar(range.from - 1, false); | |
| 79 for (UChar32 c = range.from; c <= range.to; ++c) | |
| 80 TestIsPotentialCustomElementNameChar(c, true); | |
| 81 TestIsPotentialCustomElementNameChar(range.to + 1, false); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace blink | |
| OLD | NEW |