Search in sources :

Example 1 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class DumpSpecReader method addSpecExample.

@Override
protected void addSpecExample(SpecExample example) {
    DataHolder options;
    boolean ignoredCase = false;
    try {
        options = testCase.getOptions(example, example.getOptionsSet());
    } catch (AssumptionViolatedException ignored) {
        ignoredCase = true;
        options = null;
    }
    if (options != null && options.get(FAIL)) {
        ignoredCase = true;
    }
    String parseSource = example.getSource();
    if (options != null && options.get(RenderingTestCase.NO_FILE_EOL)) {
        parseSource = trimTrailingEOL(parseSource);
    }
    Node node = testCase.parser().withOptions(options).parse(parseSource);
    final String actualHTML = testCase.renderer().withOptions(options).render(node);
    final String actualAST = testCase.ast(node);
    String html = !ignoredCase && testCase.useActualHtml() ? actualHTML : example.getHtml();
    String ast = example.getAst() == null ? null : (!ignoredCase ? actualAST : example.getAst());
    // allow other formats to accumulate
    testCase.addSpecExample(example, node, options, ignoredCase, actualHTML, actualAST);
    // include source so that diff can be used to update spec
    addSpecExample(sb, example.getSource(), html, ast, example.getOptionsSet(), testCase.includeExampleCoords(), example.getSection(), example.getExampleNumber());
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 2 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class RenderingTestCase method assertRendering.

protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = source;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String html = renderer().withOptions(options).render(node);
    testCase(node, options);
    actualHtml(html, optionsSet);
    boolean useActualHtml = useActualHtml();
    // include source for better assertion errors
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, source, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, source, useActualHtml ? html : expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(source, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(source, useActualHtml ? html : expectedHtml, "", optionsSet);
    }
    specExample(expected, actual, optionsSet);
    if (options != null && options.get(FAIL)) {
        thrown.expect(ComparisonFailure.class);
    }
    assertEquals(expected, actual);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 3 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboAppHtmlParserTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, optionsSet);
    boolean useActualHtml = useActualHtml();
    // include source for better assertion errors
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
    }
    specExample(expected, actual, optionsSet);
    if (options != null && options.get(FAIL)) {
        thrown.expect(ComparisonFailure.class);
    }
    assertEquals(expected, actual);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 4 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboFlexmarkHtmlAttributesParserTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, optionsSet);
    boolean useActualHtml = useActualHtml();
    // include source for better assertion errors
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
    }
    specExample(expected, actual, optionsSet);
    if (options != null && options.get(FAIL)) {
        thrown.expect(ComparisonFailure.class);
    }
    assertEquals(expected, actual);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 5 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboFlexmarkHtmlParserTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, optionsSet);
    boolean useActualHtml = useActualHtml();
    // include source for better assertion errors
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
    }
    specExample(expected, actual, optionsSet);
    if (options != null && options.get(FAIL)) {
        thrown.expect(ComparisonFailure.class);
    }
    assertEquals(expected, actual);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Aggregations

DataHolder (com.vladsch.flexmark.util.options.DataHolder)13 Node (com.vladsch.flexmark.ast.Node)11 Parser (com.vladsch.flexmark.parser.Parser)2 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)2 Document (com.vladsch.flexmark.ast.Document)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)1 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)1 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 ComparisonFailure (org.junit.ComparisonFailure)1 Test (org.junit.Test)1