Skip to content

Commit

Permalink
[NTI] Convert ReplaceCssNames to run with NTI.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130770311
  • Loading branch information
aravind-pg authored and brad4d committed Aug 22, 2016
1 parent 92d5667 commit 93522ca
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions test/com/google/javascript/jscomp/ReplaceCssNamesTest.java
Expand Up @@ -22,7 +22,6 @@
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;

import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
Expand All @@ -31,7 +30,7 @@
* Tests for ReplaceCssNames.java. * Tests for ReplaceCssNames.java.
* *
*/ */
public final class ReplaceCssNamesTest extends CompilerTestCase { public final class ReplaceCssNamesTest extends TypeICompilerTestCase {
/** Whether to pass the map of replacements as opposed to null */ /** Whether to pass the map of replacements as opposed to null */
boolean useReplacementMap; boolean useReplacementMap;


Expand Down Expand Up @@ -63,6 +62,10 @@ public final class ReplaceCssNamesTest extends CompilerTestCase {
Map<String, Integer> cssNames; Map<String, Integer> cssNames;


public ReplaceCssNamesTest() { public ReplaceCssNamesTest() {
super(LINE_JOINER.join(
DEFAULT_EXTERNS,
"Object.prototype.getClass;",
"goog.getCssName;"));
} }


@Override protected CompilerPass getProcessor(Compiler compiler) { @Override protected CompilerPass getProcessor(Compiler compiler) {
Expand Down Expand Up @@ -106,7 +109,13 @@ protected int getNumRepetitions() {
return 1; return 1;
} }


public void testDoNotUseReplacementMap() { // NOTE(aravindpg): The ccsNames field is populated by each test method, and then compared
// to expected. So, our usual strategy of running both NTI and OTI for each test doesn't work
// here. We need to run all three methods in doNotUseReplacementMap with OTI before we can
// run them with NTI. That's why we refactored this code to call doNotUseReplacementMap from
// two places.

private void doNotUseReplacementMap() {
useReplacementMap = false; useReplacementMap = false;
test("var x = goog.getCssName('goog-footer-active')", test("var x = goog.getCssName('goog-footer-active')",
"var x = 'goog-footer-active'"); "var x = 'goog-footer-active'");
Expand All @@ -126,6 +135,16 @@ public void testDoNotUseReplacementMap() {
assertEquals(expected, cssNames); assertEquals(expected, cssNames);
} }


public void testDoNotUseReplacementMapOti() {
this.mode = TypeInferenceMode.OTI_ONLY;
doNotUseReplacementMap();
}

public void testDoNotUseReplacementMapNti() {
this.mode = TypeInferenceMode.NTI_ONLY;
doNotUseReplacementMap();
}

public void testOneArgWithUnknownStringLiterals() { public void testOneArgWithUnknownStringLiterals() {
test("var x = goog.getCssName('unknown')", test("var x = goog.getCssName('unknown')",
"var x = 'unknown'", null, UNKNOWN_SYMBOL_WARNING); "var x = 'unknown'", null, UNKNOWN_SYMBOL_WARNING);
Expand All @@ -135,7 +154,7 @@ public void testOneArgWithUnknownStringLiterals() {
"setClass('ab')", null, UNKNOWN_SYMBOL_WARNING); "setClass('ab')", null, UNKNOWN_SYMBOL_WARNING);
} }


public void testOneArgWithSimpleStringLiterals() { private void oneArgWithSimpleStringLiterals() {
test("var x = goog.getCssName('buttonbar')", test("var x = goog.getCssName('buttonbar')",
"var x = 'b'"); "var x = 'b'");
test("el.className = goog.getCssName('colorswatch')", test("el.className = goog.getCssName('colorswatch')",
Expand All @@ -151,7 +170,17 @@ public void testOneArgWithSimpleStringLiterals() {
assertEquals(expected, cssNames); assertEquals(expected, cssNames);
} }


public void testOneArgWithCompositeClassNames() { public void testOneArgWithSimpleStringLiteralsOti() {
this.mode = TypeInferenceMode.OTI_ONLY;
oneArgWithSimpleStringLiterals();
}

public void testOneArgWithSimpleStringLiteralsNti() {
this.mode = TypeInferenceMode.NTI_ONLY;
oneArgWithSimpleStringLiterals();
}

private void oneArgWithCompositeClassNames() {
test("var x = goog.getCssName('goog-footer-active')", test("var x = goog.getCssName('goog-footer-active')",
"var x = 'g-f-a'"); "var x = 'g-f-a'");
test("el.className = goog.getCssName('goog-colorswatch-disabled')", test("el.className = goog.getCssName('goog-colorswatch-disabled')",
Expand All @@ -170,6 +199,16 @@ public void testOneArgWithCompositeClassNames() {
assertEquals(expected, cssNames); assertEquals(expected, cssNames);
} }


public void testOneArgWithCompositeClassNamesOti() {
this.mode = TypeInferenceMode.OTI_ONLY;
oneArgWithCompositeClassNames();
}

public void testoOeArgWithCompositeClassNamesNti() {
this.mode = TypeInferenceMode.NTI_ONLY;
oneArgWithCompositeClassNames();
}

public void testOneArgWithCompositeClassNamesFull() { public void testOneArgWithCompositeClassNamesFull() {
renamingMap = getFullMap(); renamingMap = getFullMap();


Expand Down Expand Up @@ -206,8 +245,8 @@ public void testTwoArgsWithStringLiterals() {
public void testTwoArsWithVariableFirstArg() { public void testTwoArsWithVariableFirstArg() {
test("var x = goog.getCssName(baseClass, 'active')", test("var x = goog.getCssName(baseClass, 'active')",
"var x = baseClass + '-a'"); "var x = baseClass + '-a'");
test("el.className = goog.getCssName(this.getClass(), 'disabled')", test("el.className = goog.getCssName((new Object).getClass(), 'disabled')",
"el.className = this.getClass() + '-d'"); "el.className = (new Object).getClass() + '-d'");
test("setClass(goog.getCssName(BASE_CLASS, 'disabled'))", test("setClass(goog.getCssName(BASE_CLASS, 'disabled'))",
"setClass(BASE_CLASS + '-d')"); "setClass(BASE_CLASS + '-d')");
} }
Expand Down

0 comments on commit 93522ca

Please sign in to comment.