Search in sources :

Example 11 with DataHolder

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

the class RenderingTestCase method getOptions.

/**
 * process comma separated list of option sets and combine them for final set to use
 *
 * @param example    spec example instance for which options are being processed
 * @param optionSets comma separate list of option set names
 * @return combined set from applying these options together
 */
public DataHolder getOptions(SpecExample example, String optionSets) {
    if (optionSets == null)
        return null;
    String[] optionNames = optionSets.replace('\u00A0', ' ').split(",");
    DataHolder options = null;
    boolean isFirst = true;
    for (String optionName : optionNames) {
        String option = optionName.trim();
        if (option.isEmpty() || option.startsWith("-"))
            continue;
        if (option.equals(IGNORE_OPTION_NAME)) {
            // noinspection ConstantConditions
            throwIgnoredOption(example, optionSets, option);
        } else if (option.equals(FAIL_OPTION_NAME)) {
            if (options == null) {
                options = new MutableDataSet().set(FAIL, true);
            } else {
                options = new MutableDataSet(options).set(FAIL, true);
            }
        } else if (option.equals(NO_FILE_EOL_OPTION_NAME)) {
            if (options == null) {
                options = new MutableDataSet().set(NO_FILE_EOL, true);
            } else {
                options = new MutableDataSet(options).set(NO_FILE_EOL, true);
            }
        } else if (option.equals(FILE_EOL_OPTION_NAME)) {
            if (options == null) {
                options = new MutableDataSet().set(NO_FILE_EOL, false);
            } else {
                options = new MutableDataSet(options).set(NO_FILE_EOL, true);
            }
        } else {
            if (options == null) {
                options = options(option);
                if (options == null) {
                    throw new IllegalStateException("Option " + option + " is not implemented in the RenderingTestCase subclass");
                }
            } else {
                DataHolder dataSet = options(option);
                if (dataSet != null) {
                    if (isFirst) {
                        options = new MutableDataSet(options);
                        isFirst = false;
                    }
                    ((MutableDataSet) options).setAll(dataSet);
                } else {
                    throw new IllegalStateException("Option " + option + " is not implemented in the RenderingTestCase subclass");
                }
            }
            if (IGNORE.getFrom(options)) {
                // noinspection ConstantConditions
                throwIgnoredOption(example, optionSets, option);
            }
        }
    }
    return options;
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet)

Example 12 with DataHolder

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

the class RenderingTestCase method assertAst.

// protected void assertAst(String source, String expectedAst) {
// assertAst(source, expectedAst, null);
// }
protected void assertAst(String source, String expectedAst, 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 ast = ast(node);
    actualAst(ast, optionsSet);
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, source, "", expectedAst, optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, source, "", ast, optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(source, "", expectedAst, optionsSet);
        actual = DumpSpecReader.addSpecExample(source, "", ast, 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) ComparisonFailure(org.junit.ComparisonFailure) Node(com.vladsch.flexmark.ast.Node)

Example 13 with DataHolder

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

the class RenderingTestCase method assertRenderingAst.

// protected void assertRenderingAst(String source, String expectedHtml, String expectedAst) {
// assertRenderingAst(source, expectedHtml, expectedAst, null);
// }
protected void assertRenderingAst(String source, String expectedHtml, String expectedAst, String optionsSet) {
    // assert options != null || optionsSet == null || optionsSet.isEmpty() : "Non empty optionsSet without any option customizations";
    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);
    String ast = ast(node);
    actualAst(ast, 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, expectedAst, optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, source, useActualHtml ? html : expectedHtml, ast, optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(source, expectedHtml, expectedAst, optionsSet);
        actual = DumpSpecReader.addSpecExample(source, useActualHtml ? html : expectedHtml, ast, 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