Skip to content

Commit

Permalink
add failing unit tests from wiki and try-ctop page
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Apr 11, 2014
1 parent 9f17e8f commit 7de63c7
Show file tree
Hide file tree
Showing 76 changed files with 6,058 additions and 3,659 deletions.
50 changes: 43 additions & 7 deletions tests/error-tests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
CToP.transform(document.querySelectorAll('math'));
function formatXml(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
xml.split('\r\n').map(function(node,index) {
var indent = 0;
if (node.match( /.+<\/\w[^>]*>$/ )) {
indent = 0;
} else if (node.match( /^<\/\w/ )) {
if (pad != 0) {
pad -= 1;
}
} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
indent = 1;
} else {
indent = 0;
}

var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';
}

formatted += padding + node + '\r\n';
pad += indent;
});

return formatted;
}

Array.prototype.map.call(document.querySelectorAll('.unit'),function(unit) {
var math = unit.querySelector('math').outerHTML;
var t = document.createElement('pre');
t.textContent = math;
unit.appendChild(t);
try {
var mathNodes = unit.querySelectorAll('math');
CToP.transform(mathNodes);
var math = unit.querySelector('math').outerHTML;
var t = document.createElement('pre');
t.textContent = formatXml(math);
unit.appendChild(t);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,unit]);
}
catch(e) {
console.log(e);
}
})

MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
Loading

0 comments on commit 7de63c7

Please sign in to comment.