Skip to content

Commit

Permalink
Continuing reorganization; Adding XSpec showing (2) small examples of…
Browse files Browse the repository at this point in the history
… successful unit tests demonstrating Markdown/markup conversion usnistgov#213 cf usnistgov/OSCAL#1151 (one XSpec each way); Obfuscated one of the unit tests
  • Loading branch information
wendellpiez committed Jul 28, 2022
1 parent 6c15452 commit 0eb11bb
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test-suite/metaschema-xspec/markdown-types/markdown-mix.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:m="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel"
stylesheet="../../../toolchains/xslt-M4/converter-gen/markdown-to-supermodel-xml-converter.xsl"
run-as="external">

<x:scenario label="When converting markdown to markup">

<x:scenario label="to show it works on a simple line of content">
<x:call template="parse-markdown">
<x:param name="markdown-str" select="'Here''s some *paragraph* content.'" />
<x:param name="each-word" select="true()" />
</x:call>
<x:expect label="expressed as markup" select=".">
<p>Here's some <em>paragraph</em> content.</p>
</x:expect>
</x:scenario>

<x:scenario label="and also working on a couple of lines">
<x:variable name="in" as="xs:string" xml:space="preserve">
Here's some *paragraph* content.

And a **second** paragraph.

</x:variable>
<x:call template="parse-markdown">
<x:param name="markdown-str" select="$in" />
</x:call>
<x:expect label="expressed as markup" select=".">
<p>Here's some <em>paragraph</em> content.</p>
<p>And a <strong>second</strong> paragraph.</p>
</x:expect>
</x:scenario>

<x:scenario label="reproducing OSCAL Issue #1151">
<!-- note in this example extra initial indenting can perturb the inferencing -->
<!-- we should split this into two, one for nesting, the other for superfluous indent-->
<!-- but also test under Commonmark etc.! https://babelmark.github.io/ note that superfluous indents are not handled by many Markdown processors -->
<x:variable name="in" as="xs:string" xml:space="preserve"> * list item one
* list item two
* list item three
* list item four
- item 4 subitem 1
- item 4 subitem 2</x:variable>
<x:call template="parse-markdown">
<x:param name="markdown-str" select="$in" />
</x:call>
<x:expect label="expressed as markup" select=".">
<ul>
<li>list item one</li>
<li>list item two</li>
<li>list item three</li>
<li>list item four<ul>
<li>item 4 sub 1</li>
<li>item 4 sub 2</li></ul>
</li>
</ul>
</x:expect>
</x:scenario>

<x:scenario label="OSCAL Issue #1151 but left flush, no gratuitous indenting">
<x:variable name="in" as="xs:string" xml:space="preserve">* list item one
* list item two
* list item three
* list item four
- item 4 subitem 1
- item 4 subitem 2</x:variable>
<x:call template="parse-markdown">
<x:param name="markdown-str" select="$in" />
</x:call>
<x:expect label="expressed as markup" select=".">
<ul>
<li>list item one</li>
<li>list item two</li>
<li>list item three</li>
<li>list item four<ul>
<li>item 4 sub 1</li>
<li>item 4 sub 2</li></ul>
</li>
</ul>
</x:expect>
</x:scenario>
</x:scenario>
</x:description>
39 changes: 39 additions & 0 deletions test-suite/metaschema-xspec/markdown-types/markup-mix.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:m="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
stylesheet="../../../toolchains/xslt-M4/converter-gen/xml-to-markdown.xsl"
run-as="external">

<!-- For testing conversions from Markup to Markdown -->

<!-- source elements in metaschema namespace, which the XSLT matches
- this XSLT is cloned (not copied) into derivative converters -->

<x:scenario label="When converting markdown to markup">

<x:scenario label="to show it works on a simple line of content">
<x:context mode="md">
<p>Here's some <em>paragraph</em> content.</p>
</x:context>
<x:expect label="one line shows a case of italic" xmlns="http://www.w3.org/2005/xpath-functions">
<string>Here's some *paragraph* content.</string>
</x:expect>
</x:scenario>

<x:scenario label="and also working on a couple of lines">
<x:context mode="md">
<p>Here's some <em>paragraph</em> content.</p>
<p>And a <strong>second</strong> paragraph.</p>
</x:context>
<x:expect label="double-spaced lines show some italics and bold" xmlns="http://www.w3.org/2005/xpath-functions">
<string>Here's some *paragraph* content.</string>
<string/>
<string>And a **second** paragraph.</string>
</x:expect>
</x:scenario>

</x:scenario>
</x:description>
17 changes: 17 additions & 0 deletions test-suite/metaschema-xspec/markdown-types/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Metaschema processing XSpec testing - Markdown to Markup conversion and back

Unit testing for Markdown processors supporting OSCAL Markdown.

By defining edge cases, this aims to show a deterministic bidirectional mapping, or failing that a demonstration of where issues remain in defining or implementing such a mapping.


To run XSpec, we suggest either an XML IDE or a command line tool as described in [XSpec documentation in Github](https://github.com/xspec/xspec/wiki).

## Markdown to markup

File `markdown-mix.xspec` has two simple (working) cases and one currently breaking case.

## Markup to Markdown

File `markup-mix.xspec` has two simple (working) cases for demonstration.

File renamed without changes.

0 comments on commit 0eb11bb

Please sign in to comment.