From ec7b0a1d3adadba61c7df605b6322286425bfe9d Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 5 Jul 2012 20:15:25 +0400 Subject: [PATCH] Trying to run stdlib unit tests as part or js.tests: first step --- .../org/jetbrains/k2js/test/BasicTest.java | 24 +++++-- .../k2js/test/semantics/JsUnitTestBase.java | 70 +++++++++++++++++++ .../k2js/test/semantics/StdLibTestBase.java | 30 ++------ .../k2js/test/utils/JsTestUtils.java | 2 +- .../k2js/test/utils/LibraryFilePathsUtil.java | 61 ++++++++++++++++ .../k2js/translate/context/NamingScope.java | 4 +- .../k2js/translate/test/JSTestGenerator.java | 23 +++--- .../k2js/translate/test/JSTester.java | 23 ++---- .../translate/test/PlainAssertionTester.java | 37 ++++++++++ .../k2js/translate/test/QUnitTester.java | 45 ++++++++++++ .../testFiles/jsTester/jsTester.js | 49 +++++++++++++ .../testFiles/jsTester/jsTester.kt | 25 +++++++ .../jsUnitTests/cases/test/ListTest.kt | 55 +++++++++++++++ 13 files changed, 391 insertions(+), 57 deletions(-) create mode 100644 js/js.tests/test/org/jetbrains/k2js/test/semantics/JsUnitTestBase.java create mode 100644 js/js.tests/test/org/jetbrains/k2js/test/utils/LibraryFilePathsUtil.java create mode 100644 js/js.translator/src/org/jetbrains/k2js/translate/test/PlainAssertionTester.java create mode 100644 js/js.translator/src/org/jetbrains/k2js/translate/test/QUnitTester.java create mode 100644 js/js.translator/testFiles/jsTester/jsTester.js create mode 100644 js/js.translator/testFiles/jsTester/jsTester.kt create mode 100644 js/js.translator/testFiles/jsUnitTests/cases/test/ListTest.kt diff --git a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java index 018d0068e65..400c52c18f0 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java @@ -43,8 +43,8 @@ public abstract class BasicTest extends TestWithEnvironment { private static final String CASES = "cases/"; private static final String OUT = "out/"; private static final String EXPECTED = "expected/"; - - public static final String JSLINT_LIB = pathToTestFilesRoot() + "jslint.js"; + + public static final String JSLINT_LIB = pathToTestFilesRoot() + "jslint.js"; @NotNull private String mainDirectory = ""; @@ -103,21 +103,35 @@ public abstract class BasicTest extends TestWithEnvironment { @NotNull MainCallParameters mainCallParameters, @NotNull Iterable ecmaVersions) throws Exception { for (EcmaVersion version : ecmaVersions) { - TranslationUtils.translateFiles(getProject(), files, getOutputFilePath(testName, version), mainCallParameters, version); + TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files), + getOutputFilePath(testName, version), mainCallParameters, version); } } - protected void runRhinoTests(@NotNull String filename, @NotNull Iterable ecmaVersions, @NotNull RhinoResultChecker checker) throws Exception { + @NotNull + private List withAdditionalFiles(@NotNull List files) { + List result = Lists.newArrayList(files); + result.addAll(additionalKotlinFiles()); + return result; + } + + protected void runRhinoTests(@NotNull String filename, @NotNull Iterable ecmaVersions, + @NotNull RhinoResultChecker checker) throws Exception { for (EcmaVersion ecmaVersion : ecmaVersions) { runRhinoTest(withAdditionalFiles(getOutputFilePath(filename, ecmaVersion), ecmaVersion), checker, getRhinoTestVariables(), ecmaVersion); } } - protected Map getRhinoTestVariables() throws Exception { + protected Map getRhinoTestVariables() throws Exception { return null; } + @NotNull + protected List additionalKotlinFiles() { + return Lists.newArrayList(); + } + protected static String casesDirectoryName() { return CASES; diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/JsUnitTestBase.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/JsUnitTestBase.java new file mode 100644 index 00000000000..ab16d71c08a --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/JsUnitTestBase.java @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.test.semantics; + +import closurecompiler.internal.com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.Config; +import org.jetbrains.k2js.config.EcmaVersion; +import org.jetbrains.k2js.test.MultipleFilesTranslationTest; + +import java.util.ArrayList; +import java.util.List; + +import static org.jetbrains.k2js.test.utils.LibraryFilePathsUtil.getAdditionalLibraryFiles; + +/** + * @author Pavel Talanov + */ +public class JsUnitTestBase extends MultipleFilesTranslationTest { + + @NotNull + private static final String JS_TESTS = pathToTestFilesRoot() + "jsTester/"; + @NotNull + protected static final String JS_TESTS_KT = JS_TESTS + "jsTester.kt"; + @NotNull + protected static final String JS_TESTS_JS = JS_TESTS + "jsTester.js"; + + public JsUnitTestBase() { + super("jsUnitTests/"); + } + + @NotNull + @Override + protected List additionalJSFiles(@NotNull EcmaVersion ecmaVersion) { + ArrayList result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion)); + result.add(JS_TESTS_JS); + return result; + } + + @NotNull + @Override + protected List additionalKotlinFiles() { + ArrayList result = Lists.newArrayList(); + List additionalLibraryFiles = getAdditionalLibraryFiles(); + additionalLibraryFiles.add(JS_TESTS_KT); + boolean removed = additionalLibraryFiles.remove(Config.LIBRARIES_LOCATION + "/stdlib/testCode.kt"); + assert removed; + result.addAll(additionalLibraryFiles); + return result; + + } + + public void testDummy() throws Exception { + checkFooBoxIsTrue("test"); + } +} diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java index ebd381d7bae..9efe3a96949 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java @@ -27,6 +27,7 @@ import org.jetbrains.jet.cli.js.K2JSCompilerArguments; import org.jetbrains.k2js.config.Config; import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.test.SingleFileTranslationTest; +import org.jetbrains.k2js.test.utils.LibraryFilePathsUtil; import javax.annotation.Nullable; import java.io.File; @@ -47,7 +48,7 @@ abstract class StdLibTestBase extends SingleFileTranslationTest { } private void compileFiles(@NotNull EnumSet ecmaVersions, @NotNull List files) throws Exception { - List libFiles = createLibFilesList(); + List libFiles = LibraryFilePathsUtil.getBasicLibraryFiles(); for (EcmaVersion version : ecmaVersions) { String outputFilePath = getOutputFilePath(getTestName(false) + ".compiler.kt", version); invokeCompiler(files, libFiles, version, outputFilePath); @@ -84,37 +85,20 @@ abstract class StdLibTestBase extends SingleFileTranslationTest { } @NotNull - private static List createLibFilesList() { - return Lists.transform(Config.LIB_FILE_NAMES, new Function() { - @Override - public String apply(@Nullable String s) { - return Config.LIBRARIES_LOCATION + s; - } - }); + private static List constructFilesToCompileList(@NotNull String sourceDir, @NotNull String[] stdLibFiles) { + List files = filesFromDir(sourceDir, stdLibFiles); + files.addAll(LibraryFilePathsUtil.getAdditionalLibraryFiles()); + return files; } @NotNull - private static List constructFilesToCompileList(@NotNull String sourceDir, @NotNull String[] stdLibFiles) { + private static List filesFromDir(@NotNull String sourceDir, @NotNull String[] stdLibFiles) { List files = Lists.newArrayList(); - File stdlibDir = new File(sourceDir); assertTrue("Cannot find stdlib source: " + stdlibDir, stdlibDir.exists()); for (String file : stdLibFiles) { files.add(new File(stdlibDir, file).getPath()); } - - // lets add the standard JS library files - Iterable names = Config.LIB_FILE_NAMES_DEPENDENT_ON_STDLIB; - for (String libFileName : names) { - System.out.println("Compiling " + libFileName); - files.add(Config.LIBRARIES_LOCATION + libFileName); - } - - // lets add the standard Kotlin library files - for (String libFileName : Config.STDLIB_FILE_NAMES) { - System.out.println("Compiling " + libFileName); - files.add(Config.STDLIB_LOCATION + libFileName); - } return files; } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java b/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java index 2f3165fc4e2..561ca2b0462 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/utils/JsTestUtils.java @@ -60,7 +60,7 @@ public final class JsTestUtils { @NotNull public static List getAllFilesInDir(@NotNull String dirName) { File dir = new File(dirName); - assert dir.isDirectory(); + assert dir.isDirectory() : dir + " is not a directory."; List fullFilePaths = new ArrayList(); for (String fileName : dir.list()) { fullFilePaths.add(dirName + "/" + fileName); diff --git a/js/js.tests/test/org/jetbrains/k2js/test/utils/LibraryFilePathsUtil.java b/js/js.tests/test/org/jetbrains/k2js/test/utils/LibraryFilePathsUtil.java new file mode 100644 index 00000000000..e58fb9965ae --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/utils/LibraryFilePathsUtil.java @@ -0,0 +1,61 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.test.utils; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.Config; + +import javax.annotation.Nullable; +import java.util.List; + +/** + * @author Pavel Talanov + */ +public final class LibraryFilePathsUtil { + private LibraryFilePathsUtil() { + } + + @NotNull + public static List getBasicLibraryFiles() { + return Lists.transform(Config.LIB_FILE_NAMES, new Function() { + @Override + public String apply(@Nullable String s) { + return Config.LIBRARIES_LOCATION + s; + } + }); + } + + @NotNull + public static List getAdditionalLibraryFiles() { + List additionalKotlinFiles = Lists.newArrayList(); + // lets add the standard JS library files + Iterable names = Config.LIB_FILE_NAMES_DEPENDENT_ON_STDLIB; + for (String libFileName : names) { + System.out.println("Compiling " + libFileName); + additionalKotlinFiles.add(Config.LIBRARIES_LOCATION + libFileName); + } + + // lets add the standard Kotlin library files + for (String libFileName : Config.STDLIB_FILE_NAMES) { + System.out.println("Compiling " + libFileName); + additionalKotlinFiles.add(Config.STDLIB_LOCATION + libFileName); + } + return additionalKotlinFiles; + } +} diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/context/NamingScope.java b/js/js.translator/src/org/jetbrains/k2js/translate/context/NamingScope.java index a05f2922308..03cdcd6b47a 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/context/NamingScope.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/context/NamingScope.java @@ -19,7 +19,6 @@ package org.jetbrains.k2js.translate.context; import com.google.dart.compiler.backend.js.ast.JsName; import com.google.dart.compiler.backend.js.ast.JsScope; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.name.NameUtils; import org.jetbrains.k2js.translate.utils.JsAstUtils; /** @@ -54,8 +53,7 @@ public final class NamingScope { } @NotNull - /*package*/ JsName declareUnobfuscatableName(@NotNull String name) { - NameUtils.requireIdentifier(name); + /*package*/ JsName declareUnobfuscatableName(@NotNull String name) { JsName declaredName = scope.declareName(name); declaredName.setObfuscatable(false); return declaredName; diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTestGenerator.java b/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTestGenerator.java index 1d901464e93..48b46e53fc9 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTestGenerator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTestGenerator.java @@ -36,6 +36,7 @@ import java.util.List; /** * @author Pavel Talanov */ +//TODO: use method object instead of static functions public final class JSTestGenerator { private JSTestGenerator() { } @@ -44,23 +45,27 @@ public final class JSTestGenerator { @NotNull Collection files, @NotNull JsBlock block) { List functionDescriptors = JetTestFunctionDetector.getTestFunctionDescriptors(context.bindingContext(), files); - doGenerateTestCalls(functionDescriptors, block, context); + doGenerateTestCalls(functionDescriptors, context, new PlainAssertionTester(block, context)); } private static void doGenerateTestCalls(@NotNull List functionDescriptors, - @NotNull JsBlock block, - @NotNull TranslationContext context) { + @NotNull TranslationContext context, @NotNull JSTester jsTester) { for (FunctionDescriptor functionDescriptor : functionDescriptors) { ClassDescriptor classDescriptor = JsDescriptorUtils.getContainingClass(functionDescriptor); if (classDescriptor == null) { return; } - JsExpression expression = ReferenceTranslator.translateAsFQReference(classDescriptor, context); - JsNew testClass = new JsNew(expression); - JsExpression functionToTestCall = CallBuilder.build(context).descriptor(functionDescriptor).receiver(testClass).translate(); - - JsStringLiteral testName = context.program().getStringLiteral(classDescriptor.getName() + "." + functionDescriptor.getName()); - (new JSTester(block, context)).constructTestMethodInvocation(functionToTestCall, testName); + generateCodeForTestMethod(context, functionDescriptor, classDescriptor, jsTester); } } + + private static void generateCodeForTestMethod(@NotNull TranslationContext context, + @NotNull FunctionDescriptor functionDescriptor, + @NotNull ClassDescriptor classDescriptor, @NotNull JSTester tester) { + JsExpression expression = ReferenceTranslator.translateAsFQReference(classDescriptor, context); + JsNew testClass = new JsNew(expression); + JsExpression functionToTestCall = CallBuilder.build(context).descriptor(functionDescriptor).receiver(testClass).translate(); + JsStringLiteral testName = context.program().getStringLiteral(classDescriptor.getName() + "." + functionDescriptor.getName()); + tester.constructTestMethodInvocation(functionToTestCall, testName); + } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTester.java b/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTester.java index 53623f93ca6..d82ab662a71 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTester.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/test/JSTester.java @@ -16,35 +16,26 @@ package org.jetbrains.k2js.translate.test; -import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.util.AstUtil; +import com.google.dart.compiler.backend.js.ast.JsBlock; +import com.google.dart.compiler.backend.js.ast.JsExpression; +import com.google.dart.compiler.backend.js.ast.JsStringLiteral; import org.jetbrains.annotations.NotNull; import org.jetbrains.k2js.translate.context.TranslationContext; -import static com.google.dart.compiler.util.AstUtil.newBlock; -import static com.google.dart.compiler.util.AstUtil.newInvocation; - /** * @author Pavel Talanov */ -public class JSTester { +public abstract class JSTester { @NotNull - private final JsBlock block; + protected final JsBlock block; @NotNull - private final TranslationContext context; - @NotNull - private static final JsNameRef TEST_FUN_REF = AstUtil.newQualifiedNameRef("QUnit.test"); + protected final TranslationContext context; public JSTester(@NotNull JsBlock block, @NotNull TranslationContext context) { this.block = block; this.context = context; } - void constructTestMethodInvocation(@NotNull JsExpression functionToTestCall, - @NotNull JsStringLiteral testName) { - JsFunction functionToTest = new JsFunction(this.context.jsScope()); - functionToTest.setBody(newBlock(functionToTestCall.makeStmt())); - block.getStatements().add(newInvocation(TEST_FUN_REF, testName, functionToTest).makeStmt()); - } + public abstract void constructTestMethodInvocation(@NotNull JsExpression call, @NotNull JsStringLiteral name); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/test/PlainAssertionTester.java b/js/js.translator/src/org/jetbrains/k2js/translate/test/PlainAssertionTester.java new file mode 100644 index 00000000000..4ccd99157aa --- /dev/null +++ b/js/js.translator/src/org/jetbrains/k2js/translate/test/PlainAssertionTester.java @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.translate.test; + +import com.google.dart.compiler.backend.js.ast.JsBlock; +import com.google.dart.compiler.backend.js.ast.JsExpression; +import com.google.dart.compiler.backend.js.ast.JsStringLiteral; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.translate.context.TranslationContext; + +/** + * @author Pavel Talanov + */ +public final class PlainAssertionTester extends JSTester { + public PlainAssertionTester(@NotNull JsBlock block, @NotNull TranslationContext context) { + super(block, context); + } + + @Override + public void constructTestMethodInvocation(@NotNull JsExpression call, @NotNull JsStringLiteral name) { + block.getStatements().add(call.makeStmt()); + } +} diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/test/QUnitTester.java b/js/js.translator/src/org/jetbrains/k2js/translate/test/QUnitTester.java new file mode 100644 index 00000000000..b19a7392edb --- /dev/null +++ b/js/js.translator/src/org/jetbrains/k2js/translate/test/QUnitTester.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.translate.test; + +import com.google.dart.compiler.backend.js.ast.*; +import com.google.dart.compiler.util.AstUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.translate.context.TranslationContext; + +import static com.google.dart.compiler.util.AstUtil.newBlock; +import static com.google.dart.compiler.util.AstUtil.newInvocation; + +/** + * @author Pavel Talanov + */ +public final class QUnitTester extends JSTester { + @NotNull + private static final JsNameRef TEST_FUN_REF = AstUtil.newQualifiedNameRef("QUnit.test"); + + public QUnitTester(@NotNull JsBlock block, @NotNull TranslationContext context) { + super(block, context); + } + + @Override + public void constructTestMethodInvocation(@NotNull JsExpression functionToTestCall, + @NotNull JsStringLiteral testName) { + JsFunction functionToTest = new JsFunction(this.context.jsScope()); + functionToTest.setBody(newBlock(functionToTestCall.makeStmt())); + block.getStatements().add(newInvocation(TEST_FUN_REF, testName, functionToTest).makeStmt()); + } +} diff --git a/js/js.translator/testFiles/jsTester/jsTester.js b/js/js.translator/testFiles/jsTester/jsTester.js new file mode 100644 index 00000000000..0b7b0698eb5 --- /dev/null +++ b/js/js.translator/testFiles/jsTester/jsTester.js @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*Asserter*/ + +var JsTests = (function() { + var out = null; + function setOut(newOut) { + out = newOut; + } + var Asserter = function(out) { + this.out = out; + this.assertTrue = function (message, actual) { + if (!actual) { + this.out.println(message); + } + }; + this.assertEquals = function (message, actual) { + + }; + }; + + var test = function(testName, testFun) { + try { + testFun(); + } + catch (fail) { + out.println("Test " + testName + " failed"); + } + }; + return { + test : test, + Asserter : Asserter, + setOut : setOut + } +})(); + diff --git a/js/js.translator/testFiles/jsTester/jsTester.kt b/js/js.translator/testFiles/jsTester/jsTester.kt new file mode 100644 index 00000000000..777da914bec --- /dev/null +++ b/js/js.translator/testFiles/jsTester/jsTester.kt @@ -0,0 +1,25 @@ +package kotlin.test + +import kotlin.test.* +import js.* + +public var asserter : Asserter = JsTestsAsserter() + +native("JsTests.Asserter") +public class JsTestsAsserter(): Asserter { + + native + public override fun assertTrue(message: String, actual: Boolean) = noImpl + + native + public override fun assertEquals(message: String, expected: Any?, actual: Any?) = noImpl + + native + public override fun assertNotNull(message: String, actual: Any?) = noImpl + + native + public override fun assertNull(message: String, actual: Any?) = noImpl + + native + public override fun fail(message: String) = noImpl +} \ No newline at end of file diff --git a/js/js.translator/testFiles/jsUnitTests/cases/test/ListTest.kt b/js/js.translator/testFiles/jsUnitTests/cases/test/ListTest.kt new file mode 100644 index 00000000000..352e4a5f497 --- /dev/null +++ b/js/js.translator/testFiles/jsUnitTests/cases/test/ListTest.kt @@ -0,0 +1,55 @@ +package test.collections + +import java.util.ArrayList +import kotlin.test.* +import org.junit.Test as test + +class ListTest { + + test fun toString() { + val data = arrayList("foo", "bar") + assertEquals("[foo, bar]", data.toString()) + } + + test fun head() { + val data = arrayList("foo", "bar") + assertEquals("foo", data.head) + } + + test fun tail() { + val data = arrayList("foo", "bar", "whatnot") + val actual = data.tail + val expected = arrayList("bar", "whatnot") + assertEquals(expected, actual) + } + + test fun first() { + val data = arrayList("foo", "bar") + assertEquals("foo", data.first) + } + + test fun last() { + val data = arrayList("foo", "bar") + assertEquals("bar", data.last) + } + + /* test fun withIndices() { + val data = arrayList("foo", "bar") + val wis = data.withIndices() + var index = 0 + for (withIndex in wis) { + assertEquals(withIndex._1, index) + assertEquals(withIndex._2, data[index]) + index++ + } + assertEquals(data.size(), index) + }*/ + + test fun lastIndex() { + val emptyData = ArrayList() + val data = arrayList("foo", "bar") + + assertEquals(-1, emptyData.lastIndex) + assertEquals(1, data.lastIndex) + } +}