Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright 2008 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 /**
21 * Tests for {@link RenameLabels}.
22 */
23 public class RenameLabelsTest extends CompilerTestCase {
24
25 @Override
26 protected CompilerPass getProcessor(Compiler compiler) {
27 return new RenameLabels(compiler);
28 }
29
30
31 public void testRenameInFunction() {
32 test("function x(){ Foo:a(); }",
33 "function x(){ a(); }");
34 test("function x(){ Foo:{ a(); break Foo; } }",
35 "function x(){ a:{ a(); break a; } }");
36 test("function x() { " +
37 "Foo:{ " +
38 "function goo() {" +
39 "Foo: {" +
40 "a(); " +
41 "break Foo; " +
42 "}" +
43 "}" +
44 "}" +
45 "}",
46 "function x(){function goo(){a:{ a(); break a; }}}");
47 test("function x() { " +
48 "Foo:{ " +
49 "function goo() {" +
50 "Foo: {" +
51 "a(); " +
52 "break Foo; " +
53 "}" +
54 "}" +
55 "break Foo;" +
56 "}" +
57 "}",
58 "function x(){a:{function goo(){a:{ a(); break a; }} break a;}}");
59 }
60
61 public void testRenameGlobals() {
62 test("Foo:{a();}",
63 "a();");
64 test("Foo:{a(); break Foo;}",
65 "a:{a(); break a;}");
66 test("Foo:{Goo:a(); break Foo;}",
67 "a:{a(); break a;}");
68 test("Foo:{Goo:while(1){a(); continue Goo; break Foo;}}",
69 "a:{b:while(1){a(); continue b;break a;}}");
70 test("Foo:Goo:while(1){a(); continue Goo; break Foo;}",
71 "a:b:while(1){a(); continue b;break a;}");
72
73 test("Foo:Bar:X:{ break Bar; }",
74 "a:{ break a; }");
75 test("Foo:Bar:X:{ break Bar; break X; }",
76 "a:b:{ break a; break b;}");
77 test("Foo:Bar:X:{ break Bar; break Foo; }",
78 "a:b:{ break b; break a;}");
79
80 test("Foo:while (1){a(); break;}",
81 "while (1){a(); break;}");
82
83 // Remove label that is not referenced.
84 test("Foo:{a(); while (1) break;}",
85 "a(); while (1) break;");
86 }
87
88 public void testRenameReused() {
89 test("foo:{break foo}; foo:{break foo}", "a:{break a};a:{break a}");
90 }
91
92 }