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" | |
tkent
2016/04/27 08:21:18
Please don't use platform/Logging.h.
kojii
2016/04/27 08:45:20
Done, sorry, copied from somewhere.
| |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace blink { | |
11 | |
12 static void TestIsPotentialCustomElementName(const AtomicString& str, bool expec ted) | |
tkent
2016/04/27 08:21:18
Function name should start with lower case latter
kojii
2016/04/27 08:45:20
Done, confused with test names, sorry.
| |
13 { | |
14 if (expected) { | |
15 EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str)) | |
16 << str << " should be PotentialCustomElementName."; | |
17 } else { | |
18 EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str)) | |
19 << str << " should NOT be PotentialCustomElementName."; | |
20 } | |
21 } | |
22 | |
23 static void TestIsPotentialCustomElementNameChar(UChar32 c, bool expected) | |
tkent
2016/04/27 08:21:18
Ditto.
kojii
2016/04/27 08:45:20
Done.
| |
24 { | |
25 LChar str8[] = "a-X"; | |
26 UChar str16[] = { 'a', '-', 'X', '\0', '\0' }; | |
27 AtomicString str; | |
28 if (c <= 0xFF) { | |
29 str8[2] = c; | |
30 str = str8; | |
31 } else { | |
32 size_t i = 2; | |
33 U16_APPEND_UNSAFE(str16, i, c); | |
34 str16[i] = 0; | |
35 str = str16; | |
36 } | |
37 TestIsPotentialCustomElementName(str, expected); | |
38 } | |
39 | |
40 TEST(CustomElementTest, TestIsPotentialCustomElementName) | |
41 { | |
42 struct { | |
43 bool expected; | |
44 AtomicString str; | |
45 } tests[] = { | |
46 { false, "" }, | |
47 { false, "a" }, | |
48 { false, "A" }, | |
49 | |
50 { false, "A-" }, | |
51 { false, "0-" }, | |
52 | |
53 { true, "a-" }, | |
54 { true, "a-a" }, | |
55 { true, "aa-" }, | |
56 { true, "aa-a" }, | |
57 { true, reinterpret_cast<const UChar*>(u"aa-\x6F22\x5B57") }, // Two CJK Unified Ideographs | |
58 { true, reinterpret_cast<const UChar*>(u"aa-\xD840\xDC0B") }, // Surroga te pair U+2000B | |
59 | |
60 { false, "a-A" }, | |
61 { false, "a-Z" }, | |
62 }; | |
63 for (auto test : tests) | |
64 TestIsPotentialCustomElementName(test.str, test.expected); | |
65 } | |
66 | |
67 TEST(CustomElementTest, TestIsPotentialCustomElementNameChar) | |
68 { | |
69 | |
tkent
2016/04/27 08:21:18
This blank line looks unnecessary.
kojii
2016/04/27 08:45:20
Done.
| |
70 struct { | |
71 UChar32 from, to; | |
72 } ranges[] = { | |
73 { '-', '.' }, // "-" | "." need to merge to test -1/+1. | |
74 { '0', '9' }, | |
75 { '_', '_' }, | |
76 { 'a', 'z' }, | |
77 { 0xB7, 0xB7 }, | |
78 { 0xC0, 0xD6 }, | |
79 { 0xD8, 0xF6 }, | |
80 { 0xF8, 0x37D }, // [#xF8-#x2FF] | [#x300-#x37D] need to merge to test - 1/+1. | |
81 { 0x37F, 0x1FFF }, | |
82 { 0x200C, 0x200D }, | |
83 { 0x203F, 0x2040 }, | |
84 { 0x2070, 0x218F }, | |
85 { 0x2C00, 0x2FEF }, | |
86 { 0x3001, 0xD7FF }, | |
87 { 0xF900, 0xFDCF }, | |
88 { 0xFDF0, 0xFFFD }, | |
89 { 0x10000, 0xEFFFF }, | |
90 }; | |
91 for (auto range : ranges) { | |
92 TestIsPotentialCustomElementNameChar(range.from - 1, false); | |
93 for (UChar32 c = range.from; c <= range.to; ++c) | |
94 TestIsPotentialCustomElementNameChar(c, true); | |
95 TestIsPotentialCustomElementNameChar(range.to + 1, false); | |
96 } | |
97 } | |
98 | |
99 TEST(CustomElementTest, TestIsPotentialCustomElementNameCharFalse) | |
100 { | |
101 | |
tkent
2016/04/27 08:21:18
This blank line looks unnecessary.
kojii
2016/04/27 08:45:20
Done.
| |
102 struct { | |
103 UChar32 from, to; | |
104 } ranges[] = { | |
105 { 'A', 'Z' }, | |
106 }; | |
107 for (auto range : ranges) { | |
108 for (UChar32 c = range.from; c <= range.to; ++c) | |
109 TestIsPotentialCustomElementNameChar(c, false); | |
110 } | |
111 } | |
112 | |
113 } // namespace blink | |
OLD | NEW |