Skip to content

Commit

Permalink
Add tests for array creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 authored and kindlich committed May 28, 2024
1 parent 44a5123 commit 5f9995f
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,76 @@ public List<Class<?>> getRequiredClasses() {
return requiredClasses;
}

@Test
public void basic() {
ScriptBuilder.create()
.add("var result = [1, 2, 3];")
.add("println(result[0]);")
.add("println(result.length);")
.execute(this);

logger.assertPrintOutputSize(2);
logger.assertPrintOutput(0, "1");
logger.assertPrintOutput(1, "3");
}

@Test
public void sized() {
ScriptBuilder.create()
.add("var result = new int[](1);")
.add("println(result[0]);")
.execute(this);

logger.assertPrintOutputSize(1);
logger.assertPrintOutput(0, "0");
}

@Test
public void sizedWithDefaultValue() {
ScriptBuilder.create()
.add("var x = new int[](10, 8);")
.add("println(x[5]);")
.add("println(x.length);")
.execute(this);

logger.assertPrintOutputSize(2);
logger.assertPrintOutput(0, "8");
logger.assertPrintOutput(1, "10");
}

@Test
public void multiDimSized() {
ScriptBuilder.create()
.add("var x = new int[,](10, 10);")
.add("println(x[5, 0]);")
.execute(this);

logger.assertPrintOutputSize(1);
logger.assertPrintOutput(0, "0");
}

@Test
public void multiDimSizedWithDefault() {
ScriptBuilder.create()
.add("var x = new int[,](10, 10, 7);")
.add("println(x[5, 0]);")
.execute(this);

logger.assertPrintOutputSize(1);
logger.assertPrintOutput(0, "7");
}

@Test
public void callback() {
ScriptBuilder.create()
.add("var result = new int[](10, (index as usize) => 4);")
.add("println(result[0]);")
.execute(this);

logger.assertPrintOutputSize(1);
logger.assertPrintOutput(0, "4");
}

@Test
public void varargCreationShouldUseProperType() {
ScriptBuilder.create()
Expand Down

0 comments on commit 5f9995f

Please sign in to comment.