This is a reproduction repo to explain and experiment with usnistgov/OSCAL#1127 with a set of minimal viable examples.
This was developed and compiled on a recent, updated system with Windows 10 Version 20H2 (OS Build 19042.1469) and Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.6 with the default .NET Runtime set to 4.8.04084, with the compilation profile set to .NET 6.0.
To use this, download the repository in your preferred location on your filesystem. Open the Regexted.sln
solution file for the Visual Studio project, or run the following commands for a configured Visual Studio 2022 Developer PowerShell and/or Visual Studio 2022 Developer Command Prompt.
dotnet build
dotnet test
NOTE: If you review the C# Xunit test suite, you will notice the names of the classes, XML Schema XSD file, valid XML input, and invalid XML input for the given schema are named according to their ID and located in the ./Fixtures
sub-directory.
ID | Regexp | Valid | Invalid | Rationale | Schema Fails to Compile w/ Runtime Error? | Accepts Valid XML? | Rejects Invalid XML? | Notes |
---|---|---|---|---|---|---|---|---|
SchemaPattern1 | A | A | B | matches only "A" (numeric character reference) | X | X | ||
SchemaPattern2 | A | A | B | literal | X | X | ||
SchemaPattern3 | [A-Z] | A | a | matches A-Z (range) | X | X | ||
SchemaPattern4 | [\d-[0]]\D | 7A | 0A | character class with exclusion | X | X | ||
SchemaPattern5 | 𐀀 | 𐀀 | 𐀁 | Unicode | X | X | ||
SchemaPattern6 | [𐀀-] | 𐀀 | A | big range of upper Unicode | X | "The Pattern constraining facet is invalid - Invalid pattern ..." |
||
SchemaPattern7 | [\c-[𐀀-]] | A | 𐀀 | XML name characters except for big range of upper Unicode | X | "The Pattern constraining facet is invalid - Invalid pattern ..." |
||
SchemaPattern8 | [𐀀-𐀐] | 𐀁 | A | More unicode range testing | X | "The Pattern constraining facet is invalid - Invalid pattern ..." |
||
SchemaPattern9 | \c |
A | % | More unicode range testing | X | X | ||
SchemaPattern10 | [\c-[𐀀-]] | 𐀀 | B | More unicode range testing | X | "The Pattern constraining facet is invalid - Invalid pattern ..." |
||
SchemaPattern11 | [𐀀-𐀐] | A1 | 1A | More unicode range testing | X | "The Pattern constraining facet is invalid - Invalid pattern ..." |
||
SchemaPattern12 | [\i-[:]][\c-[:]]* | A1 | 1a | More unicode range testing | X | X |
OK, let's look at this test.
public void Invalid()
{
string schema = $"{fixture.contextPath}{pattern}.xsd";
XDocument document = XDocument.Load($"{fixture.contextPath}{pattern}Invalid.xml");
XmlValidator validator = new XmlValidator(fixture.namespaceUri, fixture.namespacePrefix, schema, document);
validator.Validate();
Assert.True(
!validator.hasRuntimeErrors &&
validator.hasValidationErrors &&
validator.hasCompletedValidation
);
}
What do the validator
boolean attributes mean and how do they relate to the testing rubric?
-
validator.hasRuntimeErrors
: when loading the XML document, the schema, or compiling the schema into native form in the .NET runtime, there was an exception. Given our tests, this most always means the XML schema's XSD file is invalid, and what are often testing here. This attribute equates toSchema Fails to Compile w/ Runtime Error?
in the table above. -
validator.hasValidationErrors
: when validating the XML document against the schema,false
means it was validated successfully without errors. A value oftrue
means it validated and errors were found. Not used explicitly in the test, theList<string>
list of validation errors can be retrieved withvalidator.validationErrors
attribute of the class instance. This attribute determines whetherAccepts Valid XML?
Rejects Invalid XML?
columns and explain "did the schema validate as intended?" scenarios. -
validator.hasCompletedValidation
: when validating the XML document, a schema validation attempt may throw an exception and we want to be aware of that. This field should always have a value oftrue
or we had unexpected behavior in our tests, this can be checked in conjuction withhasRuntimeErrors
to know if schema compilation was successful, validation occurred, but values in a test document caused trouble.