1 package org.simantics.scl.compiler.tests.markdown;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.io.StringReader;
7 import java.nio.charset.Charset;
9 import org.simantics.scl.compiler.markdown.internal.MarkdownParser;
10 import org.simantics.scl.compiler.markdown.nodes.Node;
12 public class RunMarkdownTests {
14 public static int FAILED = 0;
15 public static int SUCCEEDED = 1;
16 public static int SKIPPED = 2;
18 public static void main(String[] args) throws IOException {
19 BufferedReader reader = new BufferedReader(
20 new InputStreamReader(
21 RunMarkdownTests.class.getResourceAsStream("spec.txt"),
22 Charset.forName("UTF-8")));
24 StringBuilder in = new StringBuilder();
25 StringBuilder out = new StringBuilder();
32 String line = reader.readLine();
37 if(line.equals("```````````````````````````````` example"))
50 if(line.equals("````````````````````````````````")) {
52 int status = test(testId, in.toString(), out.toString());
53 if(status == SUCCEEDED)
55 else if(status == FAILED)
59 in = new StringBuilder();
60 out = new StringBuilder();
72 System.out.println("Passed: " + passed + "/" + testId);
73 System.out.println("Failed: " + failed + "/" + testId);
74 System.out.println("Skipped: " + skipped + "/" + testId);
77 public static int test(int id, String in, String out) throws IOException {
78 MarkdownParser parser = new MarkdownParser();
79 Node node = parser.parseDocument(new StringReader(in.replace('\u2192', '\t')));
81 String result = node.toHtml().replace('\t', '\u2192');
83 boolean passed = result.equals(out);
86 System.out.println("Example " + id); // + (passed ? " passed" : " failed"));
87 System.out.println("---- in --------------------------------------------------------------------");
88 System.out.println(in);
89 System.out.println("---- expected --------------------------------------------------------------");
90 System.out.println(out);
91 System.out.println("---- actual ----------------------------------------------------------------");
92 System.out.println(result);
93 System.out.println("----------------------------------------------------------------------------");
97 return passed ? SUCCEEDED : FAILED;