Debian Codegraph @

test/com/google/javascript/jscomp/ClosureCodeRemovalTest.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 * Tests for {@link ClosureCodeRemoval}
21 *
22 * @author [email protected] (Robby Walker)
23 */
24 public class ClosureCodeRemovalTest extends CompilerTestCase {
25
26 private static String EXTERNS = "var window;";
27
28 public ClosureCodeRemovalTest() {
29 super(EXTERNS);
30 }
31
32 public void testRemoveAbstract() {
33 test("function Foo() {}; Foo.prototype.doSomething = goog.abstractMethod;",
34 "function Foo() {};");
35 }
36
37 public void testRemoveMultiplySetAbstract() {
38 test("function Foo() {}; Foo.prototype.doSomething = " +
39 "Foo.prototype.doSomethingElse = Foo.prototype.oneMore = " +
40 "goog.abstractMethod;",
41 "function Foo() {};");
42 }
43
44 public void testDoNotRemoveNormal() {
45 testSame("function Foo() {}; Foo.prototype.doSomething = function() {};");
46 }
47
48 public void testDoNotRemoveOverride() {
49 test("function Foo() {}; Foo.prototype.doSomething = goog.abstractMethod;" +
50 "function Bar() {}; goog.inherits(Bar, Foo);" +
51 "Bar.prototype.doSomething = function() {}",
52 "function Foo() {}; function Bar() {}; goog.inherits(Bar, Foo);" +
53 "Bar.prototype.doSomething = function() {}");
54 }
55
56 public void testDoNotRemoveNonQualifiedName() {
57 testSame("document.getElementById('x').y = goog.abstractMethod;");
58 }
59
60 public void testStopRemovalAtNonQualifiedName() {
61 test("function Foo() {}; function Bar() {};" +
62 "Foo.prototype.x = document.getElementById('x').y = Bar.prototype.x" +
63 " = goog.abstractMethod;",
64 "function Foo() {}; function Bar() {};" +
65 "Foo.prototype.x = document.getElementById('x').y = " +
66 "goog.abstractMethod;");
67 }
68
69 public void testAssertionRemoval1() {
70 test("var x = goog.asserts.assert(y(), 'message');", "var x = y();");
71 }
72
73 public void testAssertionRemoval2() {
74 test("goog.asserts.assert(y(), 'message');", "");
75 }
76
77 public void testAssertionRemoval3() {
78 test("goog.asserts.assert();", "");
79 }
80
81 public void testAssertionRemoval4() {
82 test("var x = goog.asserts.assert();", "var x = void 0;");
83 }
84
85 @Override
86 protected ClosureCodeRemoval getProcessor(Compiler compiler) {
87 return new ClosureCodeRemoval(compiler, true, true);
88 }
89 }