JS backend: fix "is Boolean" check.

This commit is contained in:
Zalim Bashorov
2014-12-08 17:34:54 +03:00
parent 2ccc027ba5
commit e378bde43e
4 changed files with 42 additions and 0 deletions
@@ -51,4 +51,8 @@ public class RTTITest extends SingleFileTranslationTest {
public void testStdlibEmptyListClass() throws Exception {
checkFooBoxIsOk();
}
public void testIsJsPrimitiveType() throws Exception {
checkFooBoxIsOk();
}
}
@@ -93,6 +93,9 @@ public final class PatternTranslator extends AbstractTranslator {
if (NamePredicate.STRING.apply(typeName)) {
jsSTypeName = "string";
}
else if (NamePredicate.BOOLEAN.apply(typeName)) {
jsSTypeName = "boolean";
}
else if (NamePredicate.LONG.apply(typeName)) {
return JsAstUtils.isLong(expressionToMatch);
}
@@ -59,6 +59,9 @@ public final class NamePredicate implements Predicate<Name> {
@NotNull
public static final NamePredicate NUMBER = new NamePredicate("Number");
@NotNull
public static final NamePredicate BOOLEAN = new NamePredicate("Boolean");
@NotNull
public static final NamePredicate CHAR = new NamePredicate(PrimitiveType.CHAR.getTypeName());
@@ -0,0 +1,32 @@
package foo
enum class Type {
NUMBER
STRING
BOOLEAN
OBJECT
}
fun test(a: Any, actualType: Type) {
assertEquals(actualType == Type.NUMBER, a is Int, "$a is Int")
assertEquals(actualType == Type.NUMBER, a is Number, "$a is Number")
assertEquals(actualType == Type.NUMBER, a is Double, "$a is Double")
assertEquals(actualType == Type.BOOLEAN, a is Boolean, "$a is Boolean")
assertEquals(actualType == Type.STRING, a is String, "$a is String")
}
fun box(): String {
test(1, Type.NUMBER)
test(12.3, Type.NUMBER)
test(12.3f, Type.NUMBER)
test("text", Type.STRING)
test(true, Type.BOOLEAN)
test(false, Type.BOOLEAN)
test(object {}, Type.OBJECT)
return "OK"
}