| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.google.javascript.jscomp; |
| 17 |
|
| 18 |
import static com.google.javascript.jscomp.CheckProvides.MISSING_PROVIDE_WARNING; |
| 19 |
|
| 20 |
import com.google.javascript.jscomp.CheckLevel; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class CheckProvidesTest extends CompilerTestCase { |
| 27 |
@Override |
| 28 |
protected CompilerPass getProcessor(Compiler compiler) { |
| 29 |
return new CheckProvides(compiler, CheckLevel.WARNING); |
| 30 |
} |
| 31 |
|
| 32 |
public void testIrrelevant() { |
| 33 |
testSame("var str = 'g4';"); |
| 34 |
} |
| 35 |
|
| 36 |
public void testHarmlessProcedural() { |
| 37 |
testSame("goog.provide('X'); /** @constructor */ function X(){};"); |
| 38 |
} |
| 39 |
|
| 40 |
public void testHarmless() { |
| 41 |
String js = "goog.provide('X'); /** @constructor */ X = function(){};"; |
| 42 |
testSame(js); |
| 43 |
} |
| 44 |
|
| 45 |
public void testNoProvideInnerClass() { |
| 46 |
testSame( |
| 47 |
"goog.provide('X');\n" + |
| 48 |
"/** @constructor */ function X(){};" + |
| 49 |
"/** @constructor */ X.Y = function(){};"); |
| 50 |
} |
| 51 |
|
| 52 |
public void testMissingGoogProvide(){ |
| 53 |
String[] js = new String[]{"/** @constructor */ X = function(){};"}; |
| 54 |
String warning = "missing goog.provide('X')"; |
| 55 |
test(js, js, null, MISSING_PROVIDE_WARNING, warning); |
| 56 |
} |
| 57 |
|
| 58 |
public void testMissingGoogProvideWithNamespace(){ |
| 59 |
String[] js = new String[]{"goog = {}; " + |
| 60 |
"/** @constructor */ goog.X = function(){};"}; |
| 61 |
String warning = "missing goog.provide('goog.X')"; |
| 62 |
test(js, js, null, MISSING_PROVIDE_WARNING, warning); |
| 63 |
} |
| 64 |
|
| 65 |
public void testGoogProvideInWrongFileShouldCreateWarning(){ |
| 66 |
String bad = "/** @constructor */ X = function(){};"; |
| 67 |
String good = "goog.provide('X'); goog.provide('Y');" + |
| 68 |
"/** @constructor */ X = function(){};" + |
| 69 |
"/** @constructor */ Y = function(){};"; |
| 70 |
String[] js = new String[] {good, bad}; |
| 71 |
String warning = "missing goog.provide('X')"; |
| 72 |
test(js, js, null, MISSING_PROVIDE_WARNING, warning); |
| 73 |
} |
| 74 |
|
| 75 |
public void testGoogProvideMissingConstructorIsOkForNow(){ |
| 76 |
|
| 77 |
|
| 78 |
testSame(new String[]{"goog.provide('Y'); X = function(){};"}); |
| 79 |
} |
| 80 |
|
| 81 |
public void testIgnorePrivateConstructor() { |
| 82 |
String js = "/** @constructor*/ X_ = function(){};"; |
| 83 |
testSame(js); |
| 84 |
} |
| 85 |
|
| 86 |
public void testIgnorePrivatelyAnnotatedConstructor() { |
| 87 |
testSame("/** @private\n@constructor */ X = function(){};"); |
| 88 |
testSame("/** @constructor\n@private */ X = function(){};"); |
| 89 |
} |
| 90 |
} |