X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Ftests%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Ftests%2FGraphCompilerTests.java;fp=bundles%2Forg.simantics.graph.compiler%2Ftests%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Ftests%2FGraphCompilerTests.java;h=7c5a07cb208bf747aef7f3d4f1bc736adb86fffb;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graph.compiler/tests/org/simantics/graph/compiler/tests/GraphCompilerTests.java b/bundles/org.simantics.graph.compiler/tests/org/simantics/graph/compiler/tests/GraphCompilerTests.java new file mode 100644 index 000000000..7c5a07cb2 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/tests/org/simantics/graph/compiler/tests/GraphCompilerTests.java @@ -0,0 +1,73 @@ +package org.simantics.graph.compiler.tests; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +import junit.framework.Assert; + +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.representation.TransferableGraph1; +import org.simantics.ltk.ISource; +import org.simantics.ltk.LocalResourceSource; + +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(); + } +}