Skip to content

Commit

Permalink
Added type interpretation to output (web-platform-tests#3461)
Browse files Browse the repository at this point in the history
The assertionType property was not being used in the test output.  It
now is used to augment the title of assertions and the error message
output to assist users with interpretation of the requirements of
the test and the results of running the test.
  • Loading branch information
halindrome authored and sideshowbarker committed Aug 13, 2016
1 parent 787e025 commit 4e54048
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
38 changes: 34 additions & 4 deletions annotation-model/scripts/JSONtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ function JSONtest(params) {
.then(function (assertContents) {
// assertContents has assertions in document order

var typeMap = {
'must' : "<b>[MANDATORY]</b> ",
'may' : "<b>[OPTIONAL]</b> ",
'should' : "<b>[RECOMMENDED]</b> "
};

var assertIdx = 0;

// populate the display of assertions that are being exercised
Expand All @@ -140,14 +146,27 @@ function JSONtest(params) {
if (level === 0) {
list.push(assertContents[assertIdx]);
}
var type = assertContents[assertIdx].hasOwnProperty('assertionType') ? assertContents[assertIdx].assertionType : "must" ;

// ensure type defaults to must
if (!typeMap.hasOwnProperty(type)) {
type = "must";
}

this.AssertionText += "<li>" + assertContents[assertIdx++].title;
this.AssertionText += "<li>" + typeMap[type] + assertContents[assertIdx++].title;
this.AssertionText += "<ol>";
buildList(assertions.assertions, level+1) ;
this.AssertionText += "</ol></li>\n";
} else {
// it is NOT a conditionObject - must be an array
assertions.forEach( function(assert) {
var type = assert.hasOwnProperty('assertionType') ? assert.assertionType : "must" ;

// ensure type defaults to must
if (!typeMap.hasOwnProperty(type)) {
type = "must";
}

if (typeof assert === "object" && Array.isArray(assert)) {
this.AssertionText += "<ol>";
// it is a nested list - recurse
Expand All @@ -158,15 +177,15 @@ function JSONtest(params) {
list.push(assertContents[assertIdx]);
}
// there is a condition object in the array
this.AssertionText += "<li>" + assertContents[assertIdx++].title;
this.AssertionText += "<li>" + typeMap[type] + assertContents[assertIdx++].title;
this.AssertionText += "<ol>";
buildList(assert, level+1) ; // capture the children too
this.AssertionText += "</ol></li>\n";
} else {
if (level === 0) {
list.push(assertContents[assertIdx]);
}
this.AssertionText += "<li>" + assertContents[assertIdx++].title + "</li>\n";
this.AssertionText += "<li>" + typeMap[type] + assertContents[assertIdx++].title + "</li>\n";
}
}.bind(this));
}
Expand Down Expand Up @@ -306,6 +325,13 @@ JSONtest.prototype = {
compareWith = 'and';
}

var typeMap = {
'must' : "",
'may' : "INFORMATIONAL: ",
'should' : "WARNING: "
};


// for each assertion (in order) load the external json schema if
// one is referenced, or use the inline schema if supplied
// validate content against the referenced schema
Expand All @@ -318,6 +344,10 @@ JSONtest.prototype = {

var expected = assert.hasOwnProperty('expectedResult') ? assert.expectedResult : 'valid' ;
var message = assert.hasOwnProperty('message') ? assert.message : "Result was not " + expected;
var type = assert.hasOwnProperty('assertionType') ? assert.assertionType : "must" ;
if (!typeMap.hasOwnProperty(type)) {
type = "must";
}

// first - what is the type of the assert
if (typeof assert === "object" && !Array.isArray(assert)) {
Expand Down Expand Up @@ -442,7 +472,7 @@ JSONtest.prototype = {
}
if (result === false) {
// test result was unexpected; use message
assert_true(result, message + err);
assert_true(result, typeMap[type] + message + err);
} else {
assert_true(result, err) ;
}
Expand Down
5 changes: 2 additions & 3 deletions annotation-model/tools/template
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ var runningTest = new JSONtest( {
</script>
</head>
<body>
<p>Fill the textarea below with JSON output from your annotation client
<p>Fill the textarea below with JSON output from your annotation client
implementation that supports the following criteria:</p>
<div id="testDescription"></div>
<p>Specifically, the following assertions will be evaluated:</p>
<div id="assertion"></div>
<form name="annotation" id="annotation">
<textarea name="annotation-input" id="annotation-input" style="width: 90%; height: 10em" >
</textarea>
<textarea name="annotation-input" id="annotation-input" style="width: 90%; height: 10em" ></textarea>
<p><input type="button" id="annotation-run" name="Loading..." value="Loading...">
<input style="display: none" type="button" id="annotation-close"
name="Close" value="Close"></p>
Expand Down

0 comments on commit 4e54048

Please sign in to comment.