Skip to content

Commit

Permalink
Add tests for usnistgov#235 regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-nist committed Dec 29, 2022
1 parent 605d505 commit 04bc6e5
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
28 changes: 28 additions & 0 deletions toolchains/xslt-M4/testing/issue_235_regression-metaschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<METASCHEMA xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0">
<schema-name>issue-235-test-schema</schema-name>
<schema-version>0.1</schema-version>
<short-name>oscal-value-testing-mini</short-name>
<namespace>http://csrc.nist.gov/ns/metaschema/unit-tests</namespace>
<json-base-uri>http://csrc.nist.gov/ns/oscal</json-base-uri>
<define-assembly name="root-assembly">
<formal-name>Issue 235 Regression Test</formal-name>
<description>A sample Metaschema definition for <a href="https://github.com/usnistgov/metaschema/issues/235">regression testing</a>.</description>
<root-name>root</root-name>
<model>
<define-field name="field1" as-type="uri">
<formal-name>Field 1</formal-name>
<description>An example field with a flag constrained with optional values.</description>
<!--<json-value-key>id</json-value-key>-->
<define-flag name="optional-flag" as-type="string">
<constraint>
<allowed-values allow-other="yes">
<enum value="value1"/>
<enum value="value2"/>
</allowed-values>
</constraint>
</define-flag>
</define-field>
</model>
</define-assembly>
</METASCHEMA>
144 changes: 144 additions & 0 deletions toolchains/xslt-M4/testing/issue_235_regression.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:mv="http://g"
stylesheet="../converter-gen/supermodel-to-json.xsl">
<x:scenario label="Regression Test for usnistgov/metaschema#235">
<x:scenario label="If a document instance has a field has no value or flag defined">
<x:context mode="write-json">
<!--
<root xmlns="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field1 optional-flag="value2">https://example.com</field1>
</root>
-->
<assembly xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel"
name="root-assembly"
key="root"
gi="root"
namespace="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field collapsible="no"
as-type="uri"
name="field1"
key="field1"
gi="field1">
<value as-type="uri" key="STRVALUE" in-json="string"/>
</field>
</assembly>
</x:context>
<x:expect label="the JSON serialization XML format should be correct.">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<map key="root">
<map key="field1">
<string key="STRVALUE"/>
</map>
</map>
</map>
</x:expect>
</x:scenario>
<x:scenario label="If a document instance has a field with a value defined and no optional flag defined">
<x:context mode="write-json">
<!--
<root xmlns="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field1>https://example.com</field1>
</root>
-->
<assembly xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel"
name="root-assembly"
key="root"
gi="root"
namespace="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field collapsible="no"
as-type="uri"
name="field1"
key="field1"
gi="field1">
<value as-type="uri" key="STRVALUE" in-json="string">https://example.com</value>
</field>
</assembly>
</x:context>
<x:expect label="the JSON serialization XML format should be correct.">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<map key="root">
<map key="field1">
<string key="STRVALUE">https://example.com</string>
</map>
</map>
</map>
</x:expect>
</x:scenario>
<x:scenario label="If a document instance has its optional flag and a value defined">
<x:context mode="write-json">
<!--
<root xmlns="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field1 optional-flag="value2">https://example.com</field1>
</root>
-->
<assembly xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel"
name="root-assembly"
key="root"
gi="root"
namespace="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field collapsible="no"
as-type="uri"
name="field1"
key="field1"
gi="field1">
<flag in-json="string"
as-type="string"
name="optional-flag"
key="optional-flag"
gi="optional-flag">value2</flag>
<value as-type="uri" key="STRVALUE" in-json="string">https://example.com</value>
</field>
</assembly>
</x:context>
<x:expect label="the JSON serialization XML format should be correct.">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<map key="root">
<map key="field1">
<string key="optional-flag">value2</string>
<string key="STRVALUE">https://example.com</string>
</map>
</map>
</map>
</x:expect>
</x:scenario>
<x:scenario label="If a document instance has its optional flag defined and no value defined">
<x:context mode="write-json">
<!--
<root xmlns="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field1 optional-flag="value2"/>
</root>
-->
<assembly xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel"
name="root-assembly"
key="root"
gi="root"
namespace="http://csrc.nist.gov/ns/metaschema/unit-tests">
<field collapsible="no"
as-type="uri"
name="field1"
key="field1"
gi="field1">
<flag in-json="string"
as-type="string"
name="optional-flag"
key="optional-flag"
gi="optional-flag">value2</flag>
<value as-type="uri" key="STRVALUE" in-json="string"/>
</field>
</assembly>
</x:context>
<x:expect label="the JSON serialization XML format should be correct.">
<map xmlns="http://www.w3.org/2005/xpath-functions">
<map key="root">
<map key="field1">
<string key="optional-flag">value2</string>
<string key="STRVALUE"/>
</map>
</map>
</map>
</x:expect>
</x:scenario>
</x:scenario>
</x:description>

0 comments on commit 04bc6e5

Please sign in to comment.