1 package org.simantics.graph.compiler.tests;
\r
3 import java.io.FileNotFoundException;
\r
4 import java.io.IOException;
\r
5 import java.util.ArrayList;
\r
7 import junit.framework.Assert;
\r
9 import org.junit.Before;
\r
10 import org.junit.Test;
\r
11 import org.simantics.graph.compiler.CompilationResult;
\r
12 import org.simantics.graph.compiler.ExternalFileLoader;
\r
13 import org.simantics.graph.compiler.GraphCompiler;
\r
14 import org.simantics.graph.compiler.GraphCompilerPreferences;
\r
15 import org.simantics.graph.representation.TransferableGraph1;
\r
16 import org.simantics.ltk.ISource;
\r
17 import org.simantics.ltk.LocalResourceSource;
\r
19 public class GraphCompilerTests {
\r
22 public void initialize() {
\r
26 public CompilationResult compile(String source) throws Exception {
\r
27 ArrayList<ISource> sources = new ArrayList<ISource>();
\r
28 sources.add(new LocalResourceSource(GraphCompilerTests.class, source));
\r
29 ArrayList<TransferableGraph1> dependencies = new ArrayList<TransferableGraph1>();
\r
30 dependencies.add(GraphCompiler.read(GraphCompilerTests.class.getResourceAsStream("graph.tg")));
\r
31 ExternalFileLoader fileLoader = new ExternalFileLoader() {
\r
33 public byte[] load(String fileName) throws IOException {
\r
34 throw new FileNotFoundException();
\r
37 GraphCompilerPreferences preferences = new GraphCompilerPreferences();
\r
38 preferences.validate = true;
\r
39 return GraphCompiler.compile(
\r
48 public void testUndefinedVariable() throws Exception {
\r
49 CompilationResult result = compile("graphs/UndefinedVariable.pgraph");
\r
50 Assert.assertEquals(1, result.getErrors().size());
\r
54 public void testUndefinedConcept() throws Exception {
\r
55 CompilationResult result = compile("graphs/UndefinedConcept.pgraph");
\r
56 Assert.assertEquals(1, result.getErrors().size());
\r
60 public void testDomainAndRangeSyntax() throws Exception {
\r
61 CompilationResult result = compile("graphs/DomainAndRangeSyntax.pgraph");
\r
62 Assert.assertEquals(0, result.getErrors().size());
\r
66 public void testLists() throws Exception {
\r
67 CompilationResult result = compile("graphs/Lists.pgraph");
\r
68 Assert.assertEquals(0, result.getErrors().size());
\r
69 Assert.assertEquals(3 /*InstanceOf*/ + 2 /*Element*/ + 3 /*Next*/,
\r
70 result.getGraph().statements.length/4);
\r
71 result.getGraph().print();
\r