From 622ad8cbb4984833458875d4c48e88432891abfc Mon Sep 17 00:00:00 2001 From: pTalanov Date: Mon, 1 Oct 2012 20:42:44 +0400 Subject: [PATCH] Add checks that test that there are no redundant toString calls for numbers and strings in string templates --- .../k2js/test/semantics/StringTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StringTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StringTest.java index 10432222541..f9a95e0374e 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StringTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StringTest.java @@ -16,6 +16,13 @@ package org.jetbrains.k2js.test.semantics; +import org.jetbrains.k2js.config.EcmaVersion; + +import java.io.FileInputStream; +import java.io.IOException; + +import static com.intellij.openapi.util.io.FileUtil.loadTextAndClose; + /** * @author Pavel Talanov */ @@ -35,14 +42,17 @@ public final class StringTest extends AbstractExpressionTest { public void testIntInTemplate() throws Exception { fooBoxIsValue("my age is 3"); + checkHasNoToStringCalls(); } public void testStringInTemplate() throws Exception { fooBoxIsValue("oHelloo"); + checkHasNoToStringCalls(); } public void testMultipleExpressionsInTemplate() throws Exception { fooBoxIsValue("left = 3\nright = 2\nsum = 5\n"); + checkHasNoToStringCalls(); } public void testObjectToStringCallInTemplate() throws Exception { @@ -60,4 +70,13 @@ public final class StringTest extends AbstractExpressionTest { public void testKt2227_2() throws Exception { fooBoxTest(); } + + private void checkHasNoToStringCalls() throws IOException { + for (EcmaVersion ecmaVersion : DEFAULT_ECMA_VERSIONS) { + String filePath = getOutputFilePath(getTestName(true) + ".kt", ecmaVersion); + //noinspection IOResourceOpenedButNotSafelyClosed + String text = loadTextAndClose(new FileInputStream(filePath)); + assertFalse(filePath + " should not contain toString calls", text.contains("toString")); + } + } }