fix ParserTest

This commit is contained in:
dfsek
2022-06-16 23:40:52 -07:00
parent 36682bc04c
commit 036a166909
@@ -8,12 +8,15 @@
package structure; package structure;
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.Objects;
import com.dfsek.terra.addons.terrascript.parser.Parser; import com.dfsek.terra.addons.terrascript.parser.Parser;
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException; import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
@@ -29,7 +32,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
public class ParserTest { public class ParserTest {
@Test @Test
public void parse() throws IOException, ParseException { public void parse() throws IOException, ParseException {
Parser parser = new Parser(IOUtils.toString(getClass().getResourceAsStream("/test.tesf"), Charset.defaultCharset())); Parser parser = new Parser(IOUtils.toString(Objects.requireNonNull(getClass().getResourceAsStream("/test.tesf")), Charset.defaultCharset()));
parser.registerFunction("test", new FunctionBuilder<Test1>() { parser.registerFunction("test", new FunctionBuilder<Test1>() {
@Override @Override
@@ -54,13 +57,13 @@ public class ParserTest {
}); });
long l = System.nanoTime(); long l = System.nanoTime();
Block block = parser.parse(); Executable block = parser.parse();
long t = System.nanoTime() - l; long t = System.nanoTime() - l;
System.out.println("Took " + (double) t / 1000000); System.out.println("Took " + (double) t / 1000000);
block.apply(null, new Scope()); block.execute(null);
block.apply(null, new Scope()); block.execute(null);
} }
private static class Test1 implements Function<Void> { private static class Test1 implements Function<Void> {