Skip to content

Commit

Permalink
update test runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Nov 14, 2024
1 parent 787a275 commit 65c6505
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
20 changes: 19 additions & 1 deletion tests/jme-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11744,6 +11744,9 @@ var TBool = types.TBool = function(b) {
jme.registerType(TBool,'boolean');

/** HTML DOM element.
*
* If the element has the attribute `data-interactive="false"` then it can be safely copied and embedded multiple times.
* If the attribute is not present or has any other value, then it's assumed that it can't be safely copied.
*
* @memberof Numbas.jme.types
* @augments Numbas.jme.token
Expand All @@ -11769,6 +11772,11 @@ var THTML = types.THTML = function(html) {
this.value = Array.from(elem.childNodes);
this.html = elem.innerHTML;
}
THTML.prototype = {
isInteractive: function() {
return this.value.some(e => e.getAttribute('data-interactive') !== 'false');
}
}
jme.registerType(THTML,'html');

/** List of elements of any data type.
Expand Down Expand Up @@ -14494,7 +14502,9 @@ newBuiltin('html',[TString],THTML,null, {
container.innerHTML = args[0].value;
var subber = new jme.variables.DOMcontentsubber(scope);
subber.subvars(container);
return new THTML(Array.from(container.childNodes));
var nodes = Array.from(container.childNodes);
nodes.forEach(node => node.setAttribute('data-interactive', 'false'));
return new THTML(nodes);
}
});
newBuiltin('isnonemptyhtml',[TString],TBool,function(html) {
Expand All @@ -14515,6 +14525,7 @@ newBuiltin('image',[TString, '[number]', '[number]'],THTML,null, {
}
var subber = new jme.variables.DOMcontentsubber(scope);
var element = subber.subvars(img);
element.setAttribute('data-interactive', 'false');
return new THTML(element);
}
});
Expand Down Expand Up @@ -14990,6 +15001,7 @@ newBuiltin('scientificnumberhtml', [TDecimal], THTML, function(n) {
var bits = math.parseScientific(n.re.toExponential());
var s = document.createElement('span');
s.innerHTML = math.niceRealNumber(bits.significand)+' × 10<sup>'+bits.exponent+'</sup>';
s.setAttribute('data-interactive', 'false');
return s;
});
newBuiltin('scientificnumberhtml', [TNum], THTML, function(n) {
Expand All @@ -14999,6 +15011,7 @@ newBuiltin('scientificnumberhtml', [TNum], THTML, function(n) {
var bits = math.parseScientific(math.niceRealNumber(n,{style:'scientific', scientificStyle:'plain'}));
var s = document.createElement('span');
s.innerHTML = math.niceRealNumber(bits.significand)+' × 10<sup>'+bits.exponent+'</sup>';
s.setAttribute('data-interactive', 'false');
return s;
});

Expand Down Expand Up @@ -16558,6 +16571,7 @@ newBuiltin('table',[TList,TList],THTML, null, {
row.appendChild(td);
}
}
table.setAttribute('data-interactive','false');
return new THTML(table);
}
});
Expand All @@ -16576,6 +16590,7 @@ newBuiltin('table',[TList],THTML, null, {
row.appendChild(td);
}
}
table.setAttribute('data-interactive','false');
return new THTML(table);
}
});
Expand Down Expand Up @@ -20063,6 +20078,9 @@ jme.variables = /** @lends Numbas.jme.variables */ {
function doToken(token) {
if(jme.isType(token,'html')) {
token = jme.castToType(token,'html');
if(!token.isInteractive()) {
return token.value.map(e => e.cloneNode(true));
}
if(token.value.numbas_embedded) {
throw(new Numbas.Error('jme.subvars.html inserted twice'))
}
Expand Down
4 changes: 0 additions & 4 deletions tests/jme/doc-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2549,10 +2549,6 @@ export default
{
"in": "gauss_jordan_elimination(matrix([1,2,3,5],[5,6,9,11],[6,9,12,15]))",
"out": "matrix([1,0,0,-2],[0,1,0,-1],[0,0,1,3])"
},
{
"in": "gauss_jordan_elimination(matrix([0,1],[1,0]))",
"out": "matrix([1,0],[0,1])"
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions tests/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,10 @@ Numbas.locale = {
"analysis.view results": "View results",
"analysis.upload files": "Upload files",
"analysis.upload more": "Upload more files",
"analysis.back to results": "Back to results",
"analysis.review": "Review",
"analysis.review this": "Review this attempt",
"analysis.reviewing attempt": "Reviewing attempt by {{student_name}}.",
"analysis.attempt data": "Attempt data",
"analysis.select format": "Select data to show",
"analysis.download this table": "Download this table",
Expand Down
24 changes: 21 additions & 3 deletions tests/numbas-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11335,6 +11335,9 @@ var TBool = types.TBool = function(b) {
jme.registerType(TBool,'boolean');

/** HTML DOM element.
*
* If the element has the attribute `data-interactive="false"` then it can be safely copied and embedded multiple times.
* If the attribute is not present or has any other value, then it's assumed that it can't be safely copied.
*
* @memberof Numbas.jme.types
* @augments Numbas.jme.token
Expand All @@ -11360,6 +11363,11 @@ var THTML = types.THTML = function(html) {
this.value = Array.from(elem.childNodes);
this.html = elem.innerHTML;
}
THTML.prototype = {
isInteractive: function() {
return this.value.some(e => e.getAttribute('data-interactive') !== 'false');
}
}
jme.registerType(THTML,'html');

/** List of elements of any data type.
Expand Down Expand Up @@ -14085,7 +14093,9 @@ newBuiltin('html',[TString],THTML,null, {
container.innerHTML = args[0].value;
var subber = new jme.variables.DOMcontentsubber(scope);
subber.subvars(container);
return new THTML(Array.from(container.childNodes));
var nodes = Array.from(container.childNodes);
nodes.forEach(node => node.setAttribute('data-interactive', 'false'));
return new THTML(nodes);
}
});
newBuiltin('isnonemptyhtml',[TString],TBool,function(html) {
Expand All @@ -14106,6 +14116,7 @@ newBuiltin('image',[TString, '[number]', '[number]'],THTML,null, {
}
var subber = new jme.variables.DOMcontentsubber(scope);
var element = subber.subvars(img);
element.setAttribute('data-interactive', 'false');
return new THTML(element);
}
});
Expand Down Expand Up @@ -14581,6 +14592,7 @@ newBuiltin('scientificnumberhtml', [TDecimal], THTML, function(n) {
var bits = math.parseScientific(n.re.toExponential());
var s = document.createElement('span');
s.innerHTML = math.niceRealNumber(bits.significand)+' × 10<sup>'+bits.exponent+'</sup>';
s.setAttribute('data-interactive', 'false');
return s;
});
newBuiltin('scientificnumberhtml', [TNum], THTML, function(n) {
Expand All @@ -14590,6 +14602,7 @@ newBuiltin('scientificnumberhtml', [TNum], THTML, function(n) {
var bits = math.parseScientific(math.niceRealNumber(n,{style:'scientific', scientificStyle:'plain'}));
var s = document.createElement('span');
s.innerHTML = math.niceRealNumber(bits.significand)+' × 10<sup>'+bits.exponent+'</sup>';
s.setAttribute('data-interactive', 'false');
return s;
});

Expand Down Expand Up @@ -16149,6 +16162,7 @@ newBuiltin('table',[TList,TList],THTML, null, {
row.appendChild(td);
}
}
table.setAttribute('data-interactive','false');
return new THTML(table);
}
});
Expand All @@ -16167,6 +16181,7 @@ newBuiltin('table',[TList],THTML, null, {
row.appendChild(td);
}
}
table.setAttribute('data-interactive','false');
return new THTML(table);
}
});
Expand Down Expand Up @@ -19654,6 +19669,9 @@ jme.variables = /** @lends Numbas.jme.variables */ {
function doToken(token) {
if(jme.isType(token,'html')) {
token = jme.castToType(token,'html');
if(!token.isInteractive()) {
return token.value.map(e => e.cloneNode(true));
}
if(token.value.numbas_embedded) {
throw(new Numbas.Error('jme.subvars.html inserted twice'))
}
Expand Down Expand Up @@ -23041,7 +23059,7 @@ Question.prototype = /** @lends Numbas.Question.prototype */
q.xml = doc.selectSingleNode('question');
q.xml.setAttribute('number',q.number);
});
q.signals.on('variablesGenerated', function() {
q.signals.on(['variablesGenerated', 'rulesetsMade'], function() {
var partNodes = q.xml.selectNodes('parts/part');
switch(q.partsMode) {
case 'all':
Expand Down Expand Up @@ -23261,7 +23279,7 @@ Question.prototype = /** @lends Numbas.Question.prototype */
tryLoad(variablesTest,['condition','maxRuns'],q.variablesTest);
}
q.signals.trigger('variableDefinitionsLoaded');
q.signals.on('variablesGenerated', function() {
q.signals.on(['variablesGenerated', 'rulesetsMade'], function() {
var parts = tryGet(data,'parts');
if(parts) {
switch(q.partsMode) {
Expand Down

0 comments on commit 65c6505

Please sign in to comment.