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;
10 import org.simantics.scl.compiler.markdown.internal.MarkdownParser;
11 import org.simantics.scl.compiler.markdown.nodes.Node;
13 public class MarkdownTests {
15 public static int FAILED = 0;
16 public static int SUCCEEDED = 1;
17 public static int SKIPPED = 2;
20 public void markdownTests() throws IOException {
21 BufferedReader reader = new BufferedReader(
22 new InputStreamReader(
23 MarkdownTests.class.getResourceAsStream("spec.txt"),
24 Charset.forName("UTF-8")));
26 StringBuilder in = new StringBuilder();
27 StringBuilder out = new StringBuilder();
34 String line = reader.readLine();
39 if(line.equals("```````````````````````````````` example"))
52 if(line.equals("````````````````````````````````")) {
54 int status = test(testId, in.toString(), out.toString());
55 if(status == SUCCEEDED)
57 else if(status == FAILED)
61 in = new StringBuilder();
62 out = new StringBuilder();
74 System.out.println("Passed: " + passed + "/" + testId);
75 System.out.println("Failed: " + failed + "/" + testId);
76 System.out.println("Skipped: " + skipped + "/" + testId);
79 public static int test(int id, String in, String out) throws IOException {
80 MarkdownParser parser = new MarkdownParser();
81 Node node = parser.parseDocument(new StringReader(in.replace('\u2192', '\t')));
83 String result = node.toHtml().replace('\t', '\u2192');
85 boolean passed = result.equals(out);
88 System.out.println("Example " + id); // + (passed ? " passed" : " failed"));
89 System.out.println("---- in --------------------------------------------------------------------");
90 System.out.println(in);
91 System.out.println("---- expected --------------------------------------------------------------");
92 System.out.println(out);
93 System.out.println("---- actual ----------------------------------------------------------------");
94 System.out.println(result);
95 System.out.println("----------------------------------------------------------------------------");
99 return passed ? SUCCEEDED : FAILED;