Debian Codegraph @

test/com/google/javascript/jscomp/ConvertToDottedPropertiesTest.java

raw symbols SCIP
1 /*
2 * Copyright 2007 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 /**
20 * Tests for {@link ConvertToDottedProperties}.
21 *
22 */
23 public class ConvertToDottedPropertiesTest extends CompilerTestCase {
24 @Override public CompilerPass getProcessor(Compiler compiler) {
25 return new ConvertToDottedProperties(compiler);
26 }
27
28 public void testConvert() {
29 test("a['p']", "a.p");
30 test("a['_p_']", "a._p_");
31 test("a['_']", "a._");
32 test("a['$']", "a.$");
33 test("a.b.c['p']", "a.b.c.p");
34 test("a.b['c'].p", "a.b.c.p");
35 test("a['p']();", "a.p();");
36 test("a()['p']", "a().p");
37 // ASCII in Unicode is safe.
38 test("a['\u0041A']", "a.AA");
39 }
40
41 public void testDoNotConvert() {
42 testSame("a[0]");
43 testSame("a['']");
44 testSame("a[' ']");
45 testSame("a[',']");
46 testSame("a[';']");
47 testSame("a[':']");
48 testSame("a['.']");
49 testSame("a['0']");
50 testSame("a['p ']");
51 testSame("a['p' + '']");
52 testSame("a[p]");
53 testSame("a[P]");
54 testSame("a[$]");
55 testSame("a[p()]");
56 testSame("a['default']");
57 // Ignorable control characters are ok in Java identifiers, but not in JS.
58 testSame("a['A\u0004']");
59 // upper case lower half of o from phonetic extensions set.
60 // valid in Safari, not in Firefox, IE.
61 test("a['\u1d17A']", "a['\u1d17A']");
62 // Latin capital N with tilde - nice if we handled it, but for now let's
63 // only allow simple Latin (aka ASCII) to be converted.
64 test("a['\u00d1StuffAfter']", "a['\u00d1StuffAfter']");
65 }
66
67
68 public void testQuotedProps() {
69 testSame("({'':0})");
70 testSame("({'1.0':0})");
71 testSame("({'\u1d17A':0})");
72 testSame("({'a\u0004b':0})");
73 }
74
75 public void test5746867() {
76 testSame("var a = { '$\\\\' : 5 };");
77 testSame("var a = { 'x\\\\u0041$\\\\' : 5 };");
78 }
79 }