package scotch.compiler.analyzer; import static scotch.compiler.syntax.reference.DefinitionReference.moduleRef; import static scotch.util.TestUtil.scopeRef; import java.util.function.Function; import org.junit.Test; import scotch.compiler.Compiler; import scotch.compiler.IsolatedCompilerTest; import scotch.compiler.syntax.definition.DefinitionGraph; public class NameAccumulatorTest extends IsolatedCompilerTest { @Test public void shouldDefineFirstLevelValues() { compile( "module scotch.test", "fn a b = a b" ); shouldNotHaveErrors(); shouldBeDefined(moduleRef("scotch.test"), "scotch.test.fn"); } @Test public void shouldDefinePatternArguments() { compile( "module scotch.test", "fn a b = a b" ); shouldNotHaveErrors(); shouldBeDefined(scopeRef("scotch.test.(fn#0#0)"), "a"); shouldBeDefined(scopeRef("scotch.test.(fn#0#0)"), "b"); } @Test public void shouldParseMultipleDrawFromsInDoNotation() { compile( "module scotch.test", "addedStuff = do", " x <- Just 3", " y <- Just 2", " return $ x + y" ); shouldNotHaveErrors(); shouldBeDefined(scopeRef("scotch.test.(addedStuff#0)"), "x"); shouldBeDefined(scopeRef("scotch.test.(addedStuff#1)"), "x"); } @Override protected Function<scotch.compiler.Compiler, DefinitionGraph> compile() { return Compiler::accumulateNames; } }