Skip to content

Commit 6d162d4

Browse files
committed
Extra type tests.
1 parent 80a26f7 commit 6d162d4

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/test/java/org/byteskript/skript/test/TypesTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ public void basic_use() throws Throwable {
3636
function.invoke();
3737
}
3838

39+
@Test
40+
public void multiple_inheritance() throws Throwable {
41+
final Member function = script.getFunction("multiple_inheritance");
42+
assert function != null;
43+
function.invoke();
44+
}
45+
46+
@Test
47+
public void java_implement() throws Throwable {
48+
final Member function = script.getFunction("java_implement");
49+
assert function != null;
50+
function.invoke();
51+
}
52+
3953
}

src/test/resources/types.bsk

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
template type Thing:
3+
function empty_func:
34
function my_func:
45
return: String
56
function another_func:
@@ -27,7 +28,6 @@ type Box:
2728
trigger:
2829
return "Hello?"
2930

30-
3131
function basic_use:
3232
trigger:
3333
set {thing} to a new Box
@@ -42,3 +42,50 @@ function basic_use:
4242
set {boolean} to bonk() from {thing}
4343
assert {boolean} is true: "Member function didn't return correctly."
4444
assert another_func() from {thing} is 10: "Template default function didn't return correctly."
45+
46+
template type Shape:
47+
function get_sides:
48+
49+
template type Quadrilateral:
50+
template: Shape
51+
function get_sides:
52+
trigger:
53+
return 4
54+
55+
type Square:
56+
template: Quadrilateral
57+
58+
type Rectangle:
59+
template: Quadrilateral
60+
61+
function multiple_inheritance:
62+
trigger:
63+
set {square} to a new Square
64+
set {rectangle} to a new Rectangle
65+
assert {square} exists: "Type creation failed."
66+
assert {rectangle} exists: "Type creation failed."
67+
assert {square} is a Square: "Type self-comparison failed."
68+
assert {square} is a Quadrilateral: "Type super-comparison failed."
69+
assert {square} is a Shape: "Type inherited super-comparison failed."
70+
assert {rectangle} is a Rectangle: "Type self-comparison failed."
71+
assert {rectangle} is a Quadrilateral: "Type super-comparison failed."
72+
assert {rectangle} is a Shape: "Type inherited super-comparison failed."
73+
assert get_sides() from {square} is 4: "Type default function failed."
74+
assert get_sides() from {rectangle} is 4: "Type default function failed."
75+
76+
type Getter:
77+
template: java/util/function/Supplier
78+
function get:
79+
trigger:
80+
return "hello"
81+
82+
function java_implement:
83+
trigger:
84+
set {getter} to a new Getter
85+
assert {getter} is a Getter: "Type self-comparison failed."
86+
set {class} to get_class("java.util.function.Supplier")
87+
assert {getter} is a {class}: "Type java super-comparison failed."
88+
set {var} to get() from {getter}
89+
assert {var} is "hello": "Supplier get method failed."
90+
set {var} to result of {getter}
91+
assert {var} is "hello": "Supplier result-of failed."

0 commit comments

Comments
 (0)