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