package org.simantics.graph.compiler.tests; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import org.junit.Before; import org.junit.Test; import org.simantics.graph.compiler.CompilationResult; import org.simantics.graph.compiler.ExternalFileLoader; import org.simantics.graph.compiler.GraphCompiler; import org.simantics.graph.compiler.GraphCompilerPreferences; import org.simantics.graph.compiler.internal.ltk.ISource; import org.simantics.graph.compiler.internal.ltk.LocalResourceSource; import org.simantics.graph.representation.TransferableGraph1; import junit.framework.Assert; public class GraphCompilerTests { @Before public void initialize() { } public CompilationResult compile(String source) throws Exception { ArrayList sources = new ArrayList(); sources.add(new LocalResourceSource(GraphCompilerTests.class, source)); ArrayList dependencies = new ArrayList(); dependencies.add(GraphCompiler.read(GraphCompilerTests.class.getResourceAsStream("graph.tg"))); ExternalFileLoader fileLoader = new ExternalFileLoader() { @Override public byte[] load(String fileName) throws IOException { throw new FileNotFoundException(); } }; GraphCompilerPreferences preferences = new GraphCompilerPreferences(); preferences.validate = true; return GraphCompiler.compile( "1.0", sources, dependencies, fileLoader, preferences); } @Test public void testUndefinedVariable() throws Exception { CompilationResult result = compile("graphs/UndefinedVariable.pgraph"); Assert.assertEquals(1, result.getErrors().size()); } @Test public void testUndefinedConcept() throws Exception { CompilationResult result = compile("graphs/UndefinedConcept.pgraph"); Assert.assertEquals(1, result.getErrors().size()); } @Test public void testDomainAndRangeSyntax() throws Exception { CompilationResult result = compile("graphs/DomainAndRangeSyntax.pgraph"); Assert.assertEquals(0, result.getErrors().size()); } @Test public void testLists() throws Exception { CompilationResult result = compile("graphs/Lists.pgraph"); Assert.assertEquals(0, result.getErrors().size()); Assert.assertEquals(3 /*InstanceOf*/ + 2 /*Element*/ + 3 /*Next*/, result.getGraph().statements.length/4); result.getGraph().print(); } }