Skip to content

Commit

Permalink
Migrates "test/com/google/javascript/jscomp/*.java" to use JUnit4 run…
Browse files Browse the repository at this point in the history
…ner and annotations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213040721
  • Loading branch information
nreid260 authored and tjgq committed Sep 18, 2018
1 parent bc6fd1b commit 0ffed17
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 124 deletions.

Large diffs are not rendered by default.

352 changes: 264 additions & 88 deletions test/com/google/javascript/jscomp/FunctionInjectorTest.java

Large diffs are not rendered by default.

29 changes: 27 additions & 2 deletions test/com/google/javascript/jscomp/FunctionRewriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@

package com.google.javascript.jscomp;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests for {@link FunctionRewriter}
*
*/
@RunWith(JUnit4.class)
public final class FunctionRewriterTest extends CompilerTestCase {

private static final String RETURNARG_HELPER =
Expand Down Expand Up @@ -48,6 +54,7 @@ public final class FunctionRewriterTest extends CompilerTestCase {
"}";

@Override
@Before
public void setUp() throws Exception {
super.setUp();
disableLineNumberCheck();
Expand All @@ -64,6 +71,7 @@ protected int getNumRepetitions() {
return 1;
}

@Test
public void testEs6Class() {
// There is never any benefit to replacing ES6 class methods
checkCompilesToSame(
Expand Down Expand Up @@ -92,6 +100,7 @@ public void testEs6Class() {
"}"), 10);
}

@Test
public void testReplaceReturnConst1() {
String source = "a.prototype.foo = function() {return \"foobar\"}";
checkCompilesToSame(source, 3);
Expand All @@ -101,10 +110,12 @@ public void testReplaceReturnConst1() {
4);
}

@Test
public void testReplaceReturnConst2() {
checkCompilesToSame("a.prototype.foo = function() {return foobar}", 10);
}

@Test
public void testReplaceReturnConst3() {
String source = "a.prototype.foo = function() {return void 0;}";
checkCompilesToSame(source, 3);
Expand All @@ -114,6 +125,7 @@ public void testReplaceReturnConst3() {
4);
}

@Test
public void testReplaceGetter1() {
String source = "a.prototype.foo = function() {return this.foo_}";
checkCompilesToSame(source, 3);
Expand All @@ -123,10 +135,12 @@ public void testReplaceGetter1() {
4);
}

@Test
public void testReplaceGetter2() {
checkCompilesToSame("a.prototype.foo = function() {return}", 10);
}

@Test
public void testReplaceSetter1() {
String source = "a.prototype.foo = function(v) {this.foo_ = v}";
checkCompilesToSame(source, 4);
Expand All @@ -136,16 +150,19 @@ public void testReplaceSetter1() {
5);
}

@Test
public void testReplaceSetterWithDefault() {
String source = "a.prototype.foo = function(v = 1) {this.foo_ = v}";
checkCompilesToSame(source, 10);
}

@Test
public void testReplaceSetterWithDestructuring() {
String source = "a.prototype.foo = function({v}) {this.foo_ = v}";
checkCompilesToSame(source, 10);
}

@Test
public void testReplaceSetter2() {
String source = "a.prototype.foo = function(v, v2) {this.foo_ = v}";
checkCompilesToSame(source, 3);
Expand All @@ -155,15 +172,18 @@ public void testReplaceSetter2() {
4);
}

@Test
public void testReplaceSetter3() {
checkCompilesToSame("a.prototype.foo = function() {this.foo_ = v}", 10);
}

@Test
public void testReplaceSetter4() {
checkCompilesToSame(
"a.prototype.foo = function(v, v2) {this.foo_ = v2}", 10);
}

@Test
public void testReplaceEmptyFunction1() {
String source = "a.prototype.foo = function() {}";
checkCompilesToSame(source, 4);
Expand All @@ -173,10 +193,12 @@ public void testReplaceEmptyFunction1() {
5);
}

@Test
public void testReplaceEmptyFunction2() {
checkCompilesToSame("function foo() {}", 10);
}

@Test
public void testReplaceEmptyFunction3() {
String source = "var foo = function() {}";
checkCompilesToSame(source, 4);
Expand All @@ -186,8 +208,7 @@ public void testReplaceEmptyFunction3() {
5);
}



@Test
public void testReplaceIdentityFunction1() {
String source = "a.prototype.foo = function(a) {return a}";
checkCompilesToSame(source, 2);
Expand All @@ -197,18 +218,22 @@ public void testReplaceIdentityFunction1() {
3);
}

@Test
public void testReplaceIdentityFunctionWithDefault() {
checkCompilesToSame("a.prototype.foo = function(a = 1) {return a}", 10);
}

@Test
public void testReplaceIdentityFunctionWithDestructuring() {
checkCompilesToSame("a.prototype.foo = function({a}) {return a}", 10);
}

@Test
public void testReplaceIdentityFunction2() {
checkCompilesToSame("a.prototype.foo = function(a) {return a + 1}", 10);
}

@Test
public void testIssue538() {
checkCompilesToSame( "/** @constructor */\n" +
"WebInspector.Setting = function() {}\n" +
Expand Down
29 changes: 25 additions & 4 deletions test/com/google/javascript/jscomp/FunctionToBlockMutatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,34 @@
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* @author johnlenz@google.com (John Lenz)
*/
/** @author johnlenz@google.com (John Lenz) */
@RunWith(JUnit4.class)
public final class FunctionToBlockMutatorTest extends TestCase {

private boolean needsDefaultResult;
private boolean isCallInLoop;

@Override
@Before
public void setUp() {
needsDefaultResult = false;
isCallInLoop = false;
}

@Test
public void testMutateNoReturnWithoutResultAssignment() {
helperMutate(
"function foo(){}; foo();",
"{}",
"foo");
}

@Test
public void testMutateNoReturnWithResultAssignment() {
needsDefaultResult = true;
helperMutate(
Expand All @@ -55,28 +61,31 @@ public void testMutateNoReturnWithResultAssignment() {
"foo");
}


@Test
public void testMutateNoValueReturnWithoutResultAssignment() {
helperMutate(
"function foo(){return;}; foo();",
"{}",
"foo", null);
}

@Test
public void testMutateNoValueReturnWithResultAssignment() {
helperMutate(
"function foo(){return;}; var result = foo();",
"{result = void 0}",
"foo");
}

@Test
public void testMutateValueReturnWithoutResultAssignment() {
helperMutate(
"function foo(){return true;}; foo();",
"{true;}",
"foo", null);
}

@Test
public void testMutateValueReturnWithResultAssignment() {
needsDefaultResult = true;
helperMutate(
Expand All @@ -85,6 +94,7 @@ public void testMutateValueReturnWithResultAssignment() {
"foo", "x");
}

@Test
public void testMutateWithMultipleReturns() {
needsDefaultResult = true;
helperMutate(
Expand All @@ -105,6 +115,7 @@ public void testMutateWithMultipleReturns() {
"foo");
}

@Test
public void testMutateWithParameters1() {
// Simple call with useless parameter
helperMutate(
Expand All @@ -113,6 +124,7 @@ public void testMutateWithParameters1() {
"foo", null);
}

@Test
public void testMutateWithParameters2() {
// Simple call with parameter
helperMutate(
Expand All @@ -121,6 +133,7 @@ public void testMutateWithParameters2() {
"foo", null);
}

@Test
public void testMutateWithParameters3() {
// Parameter has side-effects.
helperMutate(
Expand All @@ -129,6 +142,7 @@ public void testMutateWithParameters3() {
"foo", null);
}

@Test
public void testMutate8() {
// Parameter has side-effects.
helperMutate(
Expand All @@ -137,6 +151,7 @@ public void testMutate8() {
"foo", null);
}

@Test
public void testMutateInitializeUninitializedVars1() {
isCallInLoop = true;
helperMutate(
Expand All @@ -146,6 +161,7 @@ public void testMutateInitializeUninitializedVars1() {
null);
}

@Test
public void testMutateInitializeUninitializedVars2() {
helperMutate(
"function foo(a) {for(var b in c)return a;}; foo(1);",
Expand All @@ -163,6 +179,7 @@ public void testMutateInitializeUninitializedVars2() {
null);
}

@Test
public void testMutateInitializeUninitializedLets1() {
isCallInLoop = true;
helperMutate(
Expand All @@ -172,6 +189,7 @@ public void testMutateInitializeUninitializedLets1() {
null);
}

@Test
public void testMutateInitializeUninitializedLets2() {
helperMutate(
"function foo(a) {for(let b in c)return a;}; foo(1);",
Expand All @@ -189,6 +207,7 @@ public void testMutateInitializeUninitializedLets2() {
null);
}

@Test
public void testMutateCallInLoopVars1() {
String src = lines(
"function foo(a) {",
Expand All @@ -214,6 +233,7 @@ public void testMutateCallInLoopVars1() {
null);
}

@Test
public void testMutateFunctionDefinition() {
// Function declarations are rewritten as function expressions.
helperMutate(
Expand All @@ -223,6 +243,7 @@ public void testMutateFunctionDefinition() {
null);
}

@Test
public void testMutateFunctionDefinitionHoisting() {
helperMutate(
lines(
Expand Down

0 comments on commit 0ffed17

Please sign in to comment.