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.html.HtmlGenerationContext;
11 import org.simantics.scl.compiler.markdown.internal.MarkdownParser;
12 import org.simantics.scl.compiler.markdown.nodes.Node;
14 public class MarkdownTests {
16 public static int FAILED = 0;
17 public static int SUCCEEDED = 1;
18 public static int SKIPPED = 2;
21 public void markdownTests() throws IOException {
22 BufferedReader reader = new BufferedReader(
23 new InputStreamReader(
24 MarkdownTests.class.getResourceAsStream("spec.txt"),
25 Charset.forName("UTF-8")));
27 StringBuilder in = new StringBuilder();
28 StringBuilder out = new StringBuilder();
35 String line = reader.readLine();
40 if(line.equals("```````````````````````````````` example"))
53 if(line.equals("````````````````````````````````")) {
55 int status = test(testId, in.toString(), out.toString());
56 if(status == SUCCEEDED)
58 else if(status == FAILED)
62 in = new StringBuilder();
63 out = new StringBuilder();
75 System.out.println("Passed: " + passed + "/" + testId);
76 System.out.println("Failed: " + failed + "/" + testId);
77 System.out.println("Skipped: " + skipped + "/" + testId);
80 public static int test(int id, String in, String out) throws IOException {
81 if(in.contains("\u2192"))
83 MarkdownParser parser = new MarkdownParser();
84 Node node = parser.parseDocument(new StringReader(in.replace('\u2192', '\t')));
86 String result = node.toHtml(HtmlGenerationContext.TEST_DEFAULT).replace('\t', '\u2192');
88 boolean passed = result.equals(out);
91 System.out.println("Example " + id); // + (passed ? " passed" : " failed"));
92 System.out.println("---- in --------------------------------------------------------------------");
93 System.out.println(in);
94 System.out.println("---- expected --------------------------------------------------------------");
95 System.out.println(out);
96 System.out.println("---- actual ----------------------------------------------------------------");
97 System.out.println(result);
98 System.out.println("----------------------------------------------------------------------------");
102 return passed ? SUCCEEDED : FAILED;