Skip to content

Commit

Permalink
Add tests around nullability
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 672641108
  • Loading branch information
mollyibot authored and copybara-github committed Sep 9, 2024
1 parent 7896c43 commit 6aacae3
Show file tree
Hide file tree
Showing 9 changed files with 431 additions and 0 deletions.
17 changes: 17 additions & 0 deletions javatests/jsinterop/generator/externs/nullabletypes/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load(
"//javatests/jsinterop/generator:jsinterop_generator_test.bzl",
"jsinterop_generator_test",
)

package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)

jsinterop_generator_test(
name = "nullabletypes",
srcs = ["nullabletypes.js"],
expected_output = glob([
"*.java.txt",
]),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsPropertyMap;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class ClassWithNullableRefs {
@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface AnonymousUnionTypeWithNullUnionType {
@JsOverlay
static ClassWithNullableRefs.AnonymousUnionTypeWithNullUnionType of(Object o) {
return Js.cast(o);
}

@JsOverlay
default double asDouble() {
return Js.asDouble(this);
}

@JsOverlay
default String asString() {
return Js.asString(this);
}

@JsOverlay
default boolean isDouble() {
return (Object) this instanceof Double;
}

@JsOverlay
default boolean isString() {
return (Object) this instanceof String;
}
}

@JsFunction
public interface NullableAnonymousFunctionTypeRefFn {
boolean onInvoke(String p0);
}

@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface NullableAnonymousRecordRefFieldType {
@JsOverlay
static ClassWithNullableRefs.NullableAnonymousRecordRefFieldType create() {
return Js.uncheckedCast(JsPropertyMap.of());
}

@JsProperty
String getBar();

@JsProperty
double getFoo();

@JsProperty
void setBar(String bar);

@JsProperty
void setFoo(double foo);
}

@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface NullableAnonymousUnionTypeRef2UnionType {
@JsOverlay
static ClassWithNullableRefs.NullableAnonymousUnionTypeRef2UnionType of(Object o) {
return Js.cast(o);
}

@JsOverlay
default double asDouble() {
return Js.asDouble(this);
}

@JsOverlay
default String asString() {
return Js.asString(this);
}

@JsOverlay
default boolean isDouble() {
return (Object) this instanceof Double;
}

@JsOverlay
default boolean isString() {
return (Object) this instanceof String;
}
}

@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface NullableAnonymousUnionTypeRefUnionType {
@JsOverlay
static ClassWithNullableRefs.NullableAnonymousUnionTypeRefUnionType of(Object o) {
return Js.cast(o);
}

@JsOverlay
default double asDouble() {
return Js.asDouble(this);
}

@JsOverlay
default String asString() {
return Js.asString(this);
}

@JsOverlay
default boolean isDouble() {
return (Object) this instanceof Double;
}

@JsOverlay
default boolean isString() {
return (Object) this instanceof String;
}
}

@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface NullableUnionTypeRefUnionType {
@JsOverlay
static ClassWithNullableRefs.NullableUnionTypeRefUnionType of(Object o) {
return Js.cast(o);
}

@JsOverlay
default double asDouble() {
return Js.asDouble(this);
}

@JsOverlay
default String asString() {
return Js.asString(this);
}

@JsOverlay
default boolean isDouble() {
return (Object) this instanceof Double;
}

@JsOverlay
default boolean isString() {
return (Object) this instanceof String;
}
}

@JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
public interface UnionTypeWithNullRefUnionType {
@JsOverlay
static ClassWithNullableRefs.UnionTypeWithNullRefUnionType of(Object o) {
return Js.cast(o);
}

@JsOverlay
default double asDouble() {
return Js.asDouble(this);
}

@JsOverlay
default String asString() {
return Js.asString(this);
}

@JsOverlay
default boolean isDouble() {
return (Object) this instanceof Double;
}

@JsOverlay
default boolean isString() {
return (Object) this instanceof String;
}
}

public ClassWithNullableRefs.AnonymousUnionTypeWithNullUnionType anonymousUnionTypeWithNull;
public ClassWithNullableRefs.NullableAnonymousFunctionTypeRefFn nullableAnonymousFunctionTypeRef;
public ClassWithNullableRefs.NullableAnonymousRecordRefFieldType nullableAnonymousRecordRef;
public ClassWithNullableRefs.NullableAnonymousUnionTypeRefUnionType nullableAnonymousUnionTypeRef;
public ClassWithNullableRefs.NullableAnonymousUnionTypeRef2UnionType
nullableAnonymousUnionTypeRef2;
public SimpleEnum nullableEnumRef;
public NullableFunctionType nullableFunctionTypeRef;
public SimpleInterface nullableInterfaceRef;
public double nullableNumber;
public SimpleRecord nullableRecordRef;
public String nullableString;
public NullableTypeDefOfRecord nullableTypeDefOfRecordRef;
public ClassWithNullableRefs.NullableUnionTypeRefUnionType nullableUnionTypeRef;
public SimpleClass simpleClassRef;
public ClassWithNullableRefs.UnionTypeWithNullRefUnionType unionTypeWithNullRef;

public native SimpleRecord methodWithNullableParam(SimpleInterface foo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsFunction;

@JsFunction
public interface NullableFunctionType {
boolean onInvoke(String p0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsPropertyMap;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface NullableTypeDefOfRecord {
@JsOverlay
static NullableTypeDefOfRecord create() {
return Js.uncheckedCast(JsPropertyMap.of());
}

@JsProperty
String getBar();

@JsProperty
double getFoo();

@JsProperty
void setBar(String bar);

@JsProperty
void setFoo(double foo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class SimpleClass {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsEnum;
import jsinterop.annotations.JsPackage;

@JsEnum(isNative = true, namespace = JsPackage.GLOBAL)
public enum SimpleEnum {
A,
B;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface SimpleInterface {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package jsinterop.generator.externs.nullabletypes;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface SimpleRecord {}
Loading

0 comments on commit 6aacae3

Please sign in to comment.