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