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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp

Issue 1916013004: Implement PotentialCustomElementName (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tkent review Created 4 years, 7 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
OLDNEW
(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 "testing/gtest/include/gtest/gtest.h"
8
9 namespace blink {
10
11 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec ted)
12 {
13 if (expected) {
14 EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str))
15 << str << " should be PotentialCustomElementName.";
16 } else {
17 EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str))
18 << str << " should NOT be PotentialCustomElementName.";
19 }
20 }
21
22 static void testIsPotentialCustomElementNameChar(UChar32 c, bool expected)
23 {
24 LChar str8[] = "a-X";
25 UChar str16[] = { 'a', '-', 'X', '\0', '\0' };
26 AtomicString str;
27 if (c <= 0xFF) {
28 str8[2] = c;
29 str = str8;
30 } else {
31 size_t i = 2;
32 U16_APPEND_UNSAFE(str16, i, c);
33 str16[i] = 0;
34 str = str16;
35 }
36 testIsPotentialCustomElementName(str, expected);
37 }
38
39 TEST(CustomElementTest, TestIsPotentialCustomElementName)
40 {
41 struct {
42 bool expected;
43 AtomicString str;
44 } tests[] = {
45 { false, "" },
46 { false, "a" },
47 { false, "A" },
48
49 { false, "A-" },
50 { false, "0-" },
51
52 { true, "a-" },
53 { true, "a-a" },
54 { true, "aa-" },
55 { true, "aa-a" },
56 { true, reinterpret_cast<const UChar*>(u"aa-\x6F22\x5B57") }, // Two CJK Unified Ideographs
57 { true, reinterpret_cast<const UChar*>(u"aa-\xD840\xDC0B") }, // Surroga te pair U+2000B
58
59 { false, "a-A" },
60 { false, "a-Z" },
61 };
62 for (auto test : tests)
63 testIsPotentialCustomElementName(test.str, test.expected);
64 }
65
66 TEST(CustomElementTest, TestIsPotentialCustomElementNameChar)
67 {
68 struct {
69 UChar32 from, to;
70 } ranges[] = {
71 { '-', '.' }, // "-" | "." need to merge to test -1/+1.
72 { '0', '9' },
73 { '_', '_' },
74 { 'a', 'z' },
75 { 0xB7, 0xB7 },
76 { 0xC0, 0xD6 },
77 { 0xD8, 0xF6 },
78 { 0xF8, 0x37D }, // [#xF8-#x2FF] | [#x300-#x37D] need to merge to test - 1/+1.
79 { 0x37F, 0x1FFF },
80 { 0x200C, 0x200D },
81 { 0x203F, 0x2040 },
82 { 0x2070, 0x218F },
83 { 0x2C00, 0x2FEF },
84 { 0x3001, 0xD7FF },
85 { 0xF900, 0xFDCF },
86 { 0xFDF0, 0xFFFD },
87 { 0x10000, 0xEFFFF },
88 };
89 for (auto range : ranges) {
90 testIsPotentialCustomElementNameChar(range.from - 1, false);
91 for (UChar32 c = range.from; c <= range.to; ++c)
92 testIsPotentialCustomElementNameChar(c, true);
93 testIsPotentialCustomElementNameChar(range.to + 1, false);
94 }
95 }
96
97 TEST(CustomElementTest, TestIsPotentialCustomElementNameCharFalse)
98 {
99 struct {
100 UChar32 from, to;
101 } ranges[] = {
102 { 'A', 'Z' },
103 };
104 for (auto range : ranges) {
105 for (UChar32 c = range.from; c <= range.to; ++c)
106 testIsPotentialCustomElementNameChar(c, false);
107 }
108 }
109
110 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.cpp ('k') | third_party/WebKit/Source/platform/text/Character.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698