Skip to content

Commit 51b9f83

Browse files
committed
Add tests for array creation
1 parent 63ab6f8 commit 51b9f83

File tree

1 file changed

+70
-0
lines changed
  • ScriptingExample/src/test/java/org/openzen/zenscript/scriptingexample/tests/actual_test/arrays

1 file changed

+70
-0
lines changed

ScriptingExample/src/test/java/org/openzen/zenscript/scriptingexample/tests/actual_test/arrays/ArrayCreationTests.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,76 @@ public List<Class<?>> getRequiredClasses() {
2020
return requiredClasses;
2121
}
2222

23+
@Test
24+
public void basic() {
25+
ScriptBuilder.create()
26+
.add("var result = [1, 2, 3];")
27+
.add("println(result[0]);")
28+
.add("println(result.length);")
29+
.execute(this);
30+
31+
logger.assertPrintOutputSize(2);
32+
logger.assertPrintOutput(0, "1");
33+
logger.assertPrintOutput(1, "3");
34+
}
35+
36+
@Test
37+
public void sized() {
38+
ScriptBuilder.create()
39+
.add("var result = new int[](1);")
40+
.add("println(result[0]);")
41+
.execute(this);
42+
43+
logger.assertPrintOutputSize(1);
44+
logger.assertPrintOutput(0, "0");
45+
}
46+
47+
@Test
48+
public void sizedWithDefaultValue() {
49+
ScriptBuilder.create()
50+
.add("var x = new int[](10, 8);")
51+
.add("println(x[5]);")
52+
.add("println(x.length);")
53+
.execute(this);
54+
55+
logger.assertPrintOutputSize(2);
56+
logger.assertPrintOutput(0, "8");
57+
logger.assertPrintOutput(1, "10");
58+
}
59+
60+
@Test
61+
public void multiDimSized() {
62+
ScriptBuilder.create()
63+
.add("var x = new int[,](10, 10);")
64+
.add("println(x[5, 0]);")
65+
.execute(this);
66+
67+
logger.assertPrintOutputSize(1);
68+
logger.assertPrintOutput(0, "0");
69+
}
70+
71+
@Test
72+
public void multiDimSizedWithDefault() {
73+
ScriptBuilder.create()
74+
.add("var x = new int[,](10, 10, 7);")
75+
.add("println(x[5, 0]);")
76+
.execute(this);
77+
78+
logger.assertPrintOutputSize(1);
79+
logger.assertPrintOutput(0, "7");
80+
}
81+
82+
@Test
83+
public void callback() {
84+
ScriptBuilder.create()
85+
.add("var result = new int[](10, (index as usize) => 4);")
86+
.add("println(result[0]);")
87+
.execute(this);
88+
89+
logger.assertPrintOutputSize(1);
90+
logger.assertPrintOutput(0, "4");
91+
}
92+
2393
@Test
2494
public void varargCreationShouldUseProperType() {
2595
ScriptBuilder.create()

0 commit comments

Comments
 (0)