| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |
} |