Skip to content

Commit

Permalink
Move DEFAULT_EXTERNS to CompilerTestCase and make it public.
Browse files Browse the repository at this point in the history
In a follow-up CL, we will start using these from unit-test files that enable the new type inference.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124159809
  • Loading branch information
dimvar authored and blickly committed Jun 7, 2016
1 parent 7e5ecf4 commit 8fa5468
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 78 deletions.
83 changes: 80 additions & 3 deletions test/com/google/javascript/jscomp/CompilerTestCase.java
Expand Up @@ -160,6 +160,83 @@ public abstract class CompilerTestCase extends TestCase {

private String filename = "testcode";

static final String ACTIVE_X_OBJECT_DEF =
"/**\n" +
" * @param {string} progId\n" +
" * @param {string=} opt_location\n" +
" * @constructor\n" +
" * @see http://msdn.microsoft.com/en-us/library/7sw4ddf8.aspx\n" +
" */\n" +
"function ActiveXObject(progId, opt_location) {}\n";

/** A default set of externs for testing. */
public static final String DEFAULT_EXTERNS =
LINE_JOINER.join(
"/**",
" * @interface",
" * @template KEY1, VALUE1",
" */",
"function IObject() {};",
"/**",
" * @record",
" * @extends IObject<number, VALUE2>",
" * @template VALUE2",
" */",
"function IArrayLike() {};",
"/**",
" * @type{number}",
" */",
"IArrayLike.prototype.length;",
"/**",
" * @constructor",
" * @param {*=} opt_value",
" * @return {!Object}",
" */",
"function Object(opt_value) {}",
"Object.defineProperties = function(obj, descriptors) {};",
"/** @constructor",
" * @param {*} var_args */ ",
"function Function(var_args) {}",
"/** @type {!Function} */ Function.prototype.apply;",
"/** @type {!Function} */ Function.prototype.bind;",
"/** @type {!Function} */ Function.prototype.call;",
"/** @type {number} */",
"Function.prototype.length;",
"/** @constructor",
" * @param {*=} arg",
" * @return {string} */",
"function String(arg) {}",
"/** @param {number} sliceArg */",
"String.prototype.slice = function(sliceArg) {};",
"/** @type {number} */ String.prototype.length;",
"/**",
" * @template T",
" * @constructor ",
" * @implements {IArrayLike<T>} ",
" * @param {*} var_args",
" * @return {!Array.<?>}",
" */",
"function Array(var_args) {}",
"/** @type {number} */ Array.prototype.length;",
"/**",
" * @param {...T} var_args",
" * @return {number} The new length of the array.",
" * @this {{length: number}|Array.<T>}",
" * @template T",
" * @modifies {this}",
" */",
"Array.prototype.push = function(var_args) {};",
"/**",
" * @constructor",
" * @template T",
" * @implements {IArrayLike<T>}",
" */",
"function Arguments() {}",
"/** @type {number} */",
"Arguments.prototype.length;",
"/** @type {?} */ var unknown;", // For producing unknowns in tests.
ACTIVE_X_OBJECT_DEF);

/**
* Constructs a test.
*
Expand Down Expand Up @@ -331,7 +408,7 @@ public void enableTypeCheck() {

// Run the new type inference after the test pass. Useful for testing passes
// that rewrite the AST prior to typechecking, eg, AngularPass or PolymerPass.
void enableNewTypeInference() {
public void enableNewTypeInference() {
this.newTypeInferenceEnabled = true;
this.runNTIAfterProcessing = true;
}
Expand All @@ -348,11 +425,11 @@ public void enableLineNumberCheck(boolean newVal) {
*
* @see TypeCheck
*/
void disableTypeCheck() {
public void disableTypeCheck() {
typeCheckEnabled = false;
}

void disableNewTypeInference() {
public void disableNewTypeInference() {
this.newTypeInferenceEnabled = false;
}

Expand Down
75 changes: 1 addition & 74 deletions test/com/google/javascript/jscomp/CompilerTypeTestCase.java
Expand Up @@ -26,15 +26,6 @@

abstract class CompilerTypeTestCase extends BaseJSTypeTestCase {

static final String ACTIVE_X_OBJECT_DEF =
"/**\n" +
" * @param {string} progId\n" +
" * @param {string=} opt_location\n" +
" * @constructor\n" +
" * @see http://msdn.microsoft.com/en-us/library/7sw4ddf8.aspx\n" +
" */\n" +
"function ActiveXObject(progId, opt_location) {}\n";

static final String CLOSURE_DEFS =
"var goog = {};" +
"goog.inherits = function(x, y) {};" +
Expand Down Expand Up @@ -66,71 +57,7 @@ abstract class CompilerTypeTestCase extends BaseJSTypeTestCase {

/** A default set of externs for testing. */
static final String DEFAULT_EXTERNS =
LINE_JOINER.join(
"/**",
" * @interface",
" * @template KEY1, VALUE1",
" */",
"function IObject() {};",
"/**",
" * @record",
" * @extends IObject<number, VALUE2>",
" * @template VALUE2",
" */",
"function IArrayLike() {};",
"/**",
" * @type{number}",
" */",
"IArrayLike.prototype.length;",
"/**",
" * @constructor",
" * @param {*=} opt_value",
" * @return {!Object}",
" */",
"function Object(opt_value) {}",
"Object.defineProperties = function(obj, descriptors) {};",
"/** @constructor",
" * @param {*} var_args */ ",
"function Function(var_args) {}",
"/** @type {!Function} */ Function.prototype.apply;",
"/** @type {!Function} */ Function.prototype.bind;",
"/** @type {!Function} */ Function.prototype.call;",
"/** @type {number} */",
"Function.prototype.length;",
"/** @constructor",
" * @param {*=} arg",
" * @return {string} */",
"function String(arg) {}",
"/** @param {number} sliceArg */",
"String.prototype.slice = function(sliceArg) {};",
"/** @type {number} */ String.prototype.length;",
"/**",
" * @template T",
" * @constructor ",
" * @implements {IArrayLike<T>} ",
" * @param {*} var_args",
" * @return {!Array.<?>}",
" */",
"function Array(var_args) {}",
"/** @type {number} */ Array.prototype.length;",
"/**",
" * @param {...T} var_args",
" * @return {number} The new length of the array.",
" * @this {{length: number}|Array.<T>}",
" * @template T",
" * @modifies {this}",
" */",
"Array.prototype.push = function(var_args) {};",
"/**",
" * @constructor",
" * @template T",
" * @implements {IArrayLike<T>}",
" */",
"function Arguments() {}",
"/** @type {number} */",
"Arguments.prototype.length;",
"/** @type {?} */ var unknown;", // For producing unknowns in tests.
ACTIVE_X_OBJECT_DEF);
CompilerTestCase.DEFAULT_EXTERNS;

protected Compiler compiler;

Expand Down
Expand Up @@ -1837,7 +1837,7 @@ public void testAbstractMethod4() {

public void testActiveXObject() {
testSame(
CompilerTypeTestCase.ACTIVE_X_OBJECT_DEF,
CompilerTestCase.ACTIVE_X_OBJECT_DEF,
"var x = new ActiveXObject();", null);
assertEquals(
"?",
Expand Down

0 comments on commit 8fa5468

Please sign in to comment.