Failed test on kotlin-js-test module

Hello. I've added some changes to stdlib and running maven test on whole libraries module. I receive errors on test for kotlin-js-module after my changes applied. Can anybody tell me how I can resolve this issue? As I don't see what actually fails and where should I dig:( Thanks.

Can you show build output?

For sure. It is full mvn test on libraries with debug enabled. http://pastebin.com/Erhhwi6x Fail connected with illecgal call of method in kotlin, it's Char.isWhitespace() which doen't exists in JS as I undertand. So can I anyhow add it to JS runtime to make tests run under JVM and JS?

Do you use isWhitespace?

Yes, you can implement this function for JS runtime, for JVM it’s already exists (see /libraries/stdlib/src/kotlin/Char.kt).

I think a solution would be as follows:

Rename /libraries/stdlib/src/kotlin/Char.kt to /libraries/stdlib/src/kotlin/CharJVM.kt (to avoid conflicts)

Create implementation in /js/js.libraries/src/core/CharCode.kt

Add “/core/CharCode.kt” to LIB_FILES_WITH_CODE in /js/js.translator/src/org/jetbrains/k2js/config/Config.java

And of course write some tests :slight_smile:

You can see java implementation or js-specification (or https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=Core_JavaScript_1.8_Guide%2FRegular_Expressions#special-white-space).

If you have any questions please feel free to write here.

I stuck on the third step: Added new file to kotlin named CharCode.kt, but I cannot recognize what kind of code should I add there, as in files in the same package there is a valid kotlin code but referring to js package with most of methods implemented as "js.noImpl". Can I write implementation only in native kotlin or with use of js? On adding this code

package js

native public fun Char.isWhitespace() : Boolean = /^s$/.test(this.toString())

I get an error:

[ERROR] /core/CharCode.kt: (3, 50) Expecting an expression
[ERROR] /core/CharCode.kt: (3, 51) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 52) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 53) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 55) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 56) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 57) Expecting package directive or top level declaration
[ERROR] /core/CharCode.kt: (3, 79) Expecting package directive or top level declaration


And also I have a question about tests:
Where should I add them and where can I find any examples?

Kt-file should to contain valid kotlin-code.

native is annotation and means that method or class will be implemented on JS and noImpl is placeholder.

Implementation might look something like this:

``

val UNICODE_WHITESPASES = " nrt​u00A0u1680​u180eu2000​u2001u2002​u2003u2004​u2005u2006​u2007u2008​u2009u200a​u2028u2029​u2028u2029​u202fu205f​u3000"
fun Char.isWhitespace() : Boolean = this in UNICODE_WHITESPASES

But it’s doesn’t work now for JS-Backend. And I have next workaround:

``

val UNICODE_WHITESPASES = " nrt​u00A0u1680​u180eu2000​u2001u2002​u2003u2004​u2005u2006​u2007u2008​u2009u200a​u2028u2029​u2028u2029​u202fu205f​u3000"
fun Char.isWhitespace() : Boolean = UNICODE_WHITESPASES.indexOf(“$this”) != -1

Most of the tests for JS located in “/js/js.translator/testFiles/”.

You can see examples of how to include tests to build in “/js/js.tests/test/org/jetbrains/k2js/test/semantics/”

for example:
/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibMapTest.java uses /libraries/stdlib/test/js/MapJsTest.kt which contains JUnit like test class
/js/js.tests/test/org/jetbrains/k2js/test/semantics/StandardClassesTest.java uses from /js/js.translator/testFiles/standardClasses/cases/(see constructor) the sources which name same as test-cases
/js/js.tests/test/org/jetbrains/k2js/test/semantics/AdditionalTest.java uses all kt-files from /js/js.translator/testFiles/additional/cases/(see constructor).

You can find js files which will be generated after tests in “out” folder. For example, for StandardClassesTest in /js/js.translator/testFiles/standardClasses/out

Feel free to ask questions at any point.