test parseMultiScript
This commit is contained in:
parent
7ef8dee78c
commit
7f8da417a3
|
@ -1,5 +1,14 @@
|
|||
package io.gitlab.jfronny.muscript.compiler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface SourceFS {
|
||||
String read(String file);
|
||||
|
||||
record Immutable(Map<String, String> files) implements SourceFS {
|
||||
@Override
|
||||
public String read(String file) {
|
||||
return files.get(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package io.gitlab.jfronny.muscript.test;
|
||||
|
||||
import io.gitlab.jfronny.muscript.StandardLib;
|
||||
import io.gitlab.jfronny.muscript.compiler.Parser;
|
||||
import io.gitlab.jfronny.muscript.compiler.SourceFS;
|
||||
import io.gitlab.jfronny.muscript.data.Scope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class MultiScriptTest {
|
||||
final SourceFS FS = new SourceFS.Immutable(Map.of(
|
||||
"main.mu", """
|
||||
#include import1.mu
|
||||
func(4)""",
|
||||
"import1.mu", """
|
||||
#include import2.mu
|
||||
func = {c->fn2(c-1, c)}""",
|
||||
"import2.mu", """
|
||||
#include import3.mu
|
||||
fn = {a->a}""",
|
||||
"import3.mu", """
|
||||
#include import2.mu
|
||||
fn = {a->a*2}
|
||||
fn2 = {a, b -> fn(a)+b}"""
|
||||
));
|
||||
|
||||
final Scope scope = StandardLib.createScope()
|
||||
.set("throw", args -> {
|
||||
throw new IllegalArgumentException("No");
|
||||
});
|
||||
|
||||
@Test
|
||||
void simpleMultifile() {
|
||||
assertEquals(7, Parser.parseMultiScript("main.mu", FS).run(scope).asNumber().getValue());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue