From 93522cad1f86b1dc5100a3e9d72c7139858dde2a Mon Sep 17 00:00:00 2001 From: aravindpg Date: Fri, 19 Aug 2016 11:01:37 -0700 Subject: [PATCH] [NTI] Convert ReplaceCssNames to run with NTI. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130770311 --- .../jscomp/ReplaceCssNamesTest.java | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/test/com/google/javascript/jscomp/ReplaceCssNamesTest.java b/test/com/google/javascript/jscomp/ReplaceCssNamesTest.java index 5f6b4c56748..b8e3be1a3dc 100644 --- a/test/com/google/javascript/jscomp/ReplaceCssNamesTest.java +++ b/test/com/google/javascript/jscomp/ReplaceCssNamesTest.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.javascript.rhino.Node; - import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -31,7 +30,7 @@ * 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 */ boolean useReplacementMap; @@ -63,6 +62,10 @@ public final class ReplaceCssNamesTest extends CompilerTestCase { Map cssNames; public ReplaceCssNamesTest() { + super(LINE_JOINER.join( + DEFAULT_EXTERNS, + "Object.prototype.getClass;", + "goog.getCssName;")); } @Override protected CompilerPass getProcessor(Compiler compiler) { @@ -106,7 +109,13 @@ protected int getNumRepetitions() { 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; test("var x = goog.getCssName('goog-footer-active')", "var x = 'goog-footer-active'"); @@ -126,6 +135,16 @@ public void testDoNotUseReplacementMap() { assertEquals(expected, cssNames); } + public void testDoNotUseReplacementMapOti() { + this.mode = TypeInferenceMode.OTI_ONLY; + doNotUseReplacementMap(); + } + + public void testDoNotUseReplacementMapNti() { + this.mode = TypeInferenceMode.NTI_ONLY; + doNotUseReplacementMap(); + } + public void testOneArgWithUnknownStringLiterals() { test("var x = goog.getCssName('unknown')", "var x = 'unknown'", null, UNKNOWN_SYMBOL_WARNING); @@ -135,7 +154,7 @@ public void testOneArgWithUnknownStringLiterals() { "setClass('ab')", null, UNKNOWN_SYMBOL_WARNING); } - public void testOneArgWithSimpleStringLiterals() { + private void oneArgWithSimpleStringLiterals() { test("var x = goog.getCssName('buttonbar')", "var x = 'b'"); test("el.className = goog.getCssName('colorswatch')", @@ -151,7 +170,17 @@ public void testOneArgWithSimpleStringLiterals() { 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')", "var x = 'g-f-a'"); test("el.className = goog.getCssName('goog-colorswatch-disabled')", @@ -170,6 +199,16 @@ public void testOneArgWithCompositeClassNames() { assertEquals(expected, cssNames); } + public void testOneArgWithCompositeClassNamesOti() { + this.mode = TypeInferenceMode.OTI_ONLY; + oneArgWithCompositeClassNames(); + } + + public void testoOeArgWithCompositeClassNamesNti() { + this.mode = TypeInferenceMode.NTI_ONLY; + oneArgWithCompositeClassNames(); + } + public void testOneArgWithCompositeClassNamesFull() { renamingMap = getFullMap(); @@ -206,8 +245,8 @@ public void testTwoArgsWithStringLiterals() { public void testTwoArsWithVariableFirstArg() { test("var x = goog.getCssName(baseClass, 'active')", "var x = baseClass + '-a'"); - test("el.className = goog.getCssName(this.getClass(), 'disabled')", - "el.className = this.getClass() + '-d'"); + test("el.className = goog.getCssName((new Object).getClass(), 'disabled')", + "el.className = (new Object).getClass() + '-d'"); test("setClass(goog.getCssName(BASE_CLASS, 'disabled'))", "setClass(BASE_CLASS + '-d')"); }