Added functionality and dark mode to doctests. And other changes in maps.
This commit is contained in:
Vendored
+7481
-7480
File diff suppressed because one or more lines are too long
Vendored
+115
-7
@@ -121,6 +121,60 @@
|
||||
return stringified
|
||||
}
|
||||
|
||||
/**
|
||||
* When dealing with floating point numbers,
|
||||
* floating point imprecision may occur. Therefore a simple
|
||||
* equality check is not sufficient.
|
||||
*
|
||||
* The expectPointPrecision method compares two points by calculating their difference
|
||||
* and accepting the result as far as it is lower than the defined acceptable error.
|
||||
*
|
||||
* @static
|
||||
* @param {number} a - Number a to test.
|
||||
* @param {number} b - Number b to test against.
|
||||
* @param {number} accetableError - Defines the value of how much the two numbers may differ, that the test still passes.
|
||||
* @memberof Doctest
|
||||
*/
|
||||
static expectPointPrecision(pointA, pointB, accetableError = 0.000001) {
|
||||
if (Math.abs(pointA.x - pointB.x) > accetableError || Math.abs(pointA.y - pointB.y) > accetableError) {
|
||||
throw new Error(
|
||||
`Testing difference of Points ${this.pprint(pointA)} and ${this.pprint(
|
||||
pointB
|
||||
)} exceeded the acceptable error of ${accetableError} (x:${Math.abs(
|
||||
pointB.x - pointA.x
|
||||
)}, y: ${Math.abs(pointB.y - pointA.y)}).`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When dealing with floating point numbers,
|
||||
* floating point imprecision may occur. Therefore a simple
|
||||
* equality check is not sufficient.
|
||||
*
|
||||
* The expectPrecise method compares two numbers by calculating their difference
|
||||
* and accepting the result as far as it is lower than the defined acceptable error.
|
||||
*
|
||||
* @static
|
||||
* @param {number} a - Number a to test.
|
||||
* @param {number} b - Number b to test against.
|
||||
* @param {number} accetableError - Defines the value of how much the two numbers may differ, that the test still passes.
|
||||
* @memberof Doctest
|
||||
*/
|
||||
static expectPrecision(a, b, accetableError = 0.000001) {
|
||||
let aFloat = parseFloat(a);
|
||||
let bFloat = parseFloat(b);
|
||||
|
||||
console.log(aFloat);
|
||||
if (isNaN(aFloat) || isNaN(bFloat) || Math.abs(bFloat - aFloat) > accetableError) {
|
||||
throw new Error(
|
||||
`Testing difference of ${this.pprint(a)} and ${this.pprint(
|
||||
b
|
||||
)} exceeded the acceptable error of ${accetableError} (${Math.abs(bFloat - aFloat)}).`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
static expect(expr, value) {
|
||||
if (this.pprint(expr) != this.pprint(value)) {
|
||||
//throw new Error("got `" + expr + "` but expected `" + value + "`.")
|
||||
@@ -181,7 +235,51 @@
|
||||
let doctest = doctests[i];
|
||||
let code = this.stripLeadingLines(doctest.innerHTML);
|
||||
let text = this.highlight(code);
|
||||
|
||||
let container = document.createElement('div');
|
||||
container.className = 'doctest-wrapper';
|
||||
|
||||
let titleParent = container;
|
||||
if (doctest.hasAttribute('data-collapsible')) {
|
||||
let collapsibleToggle = document.createElement('div');
|
||||
|
||||
let icon = document.createElement('i');
|
||||
icon.className = 'material-icons';
|
||||
collapsibleToggle.appendChild(icon);
|
||||
|
||||
collapsibleToggle.className = 'doctest-collapsible-toggle';
|
||||
collapsibleToggle.style = 'min-height: 10px;';
|
||||
titleParent = collapsibleToggle;
|
||||
container.appendChild(collapsibleToggle);
|
||||
|
||||
const collapsedClass = 'collapsed';
|
||||
|
||||
function setToggleMode(collapse) {
|
||||
if (collapse) {
|
||||
container.classList.add(collapsedClass);
|
||||
icon.innerText = 'arrow_drop_down';
|
||||
} else {
|
||||
container.classList.remove(collapsedClass);
|
||||
icon.innerText = 'arrow_drop_up';
|
||||
}
|
||||
}
|
||||
|
||||
function determineToggleMode() {
|
||||
setToggleMode(!container.classList.contains(collapsedClass));
|
||||
}
|
||||
|
||||
setToggleMode(doctest.hasAttribute('data-collapsed'));
|
||||
collapsibleToggle.addEventListener('click', determineToggleMode);
|
||||
}
|
||||
if (doctest.hasAttribute('data-title')) {
|
||||
let title = document.createElement('h6');
|
||||
title.innerText = doctest.getAttribute('data-title');
|
||||
title.className = 'doctest-section-title';
|
||||
titleParent.appendChild(title);
|
||||
}
|
||||
|
||||
let pre = document.createElement('pre');
|
||||
pre.className = 'hljs doctest';
|
||||
// See http://stackoverflow.com/questions/1068280/javascript-regex-multiline-flag-doesnt-work
|
||||
// let re = /Doctest\.expect\(([\s\S]*)[\,\s\S]*([\s\S]*)\)/g
|
||||
let lines = text.value ? text.value.split('\n') : text.split('\n');
|
||||
@@ -196,7 +294,9 @@
|
||||
better.push(line);
|
||||
}
|
||||
pre.innerHTML = better.join('\n'); // text.value.replace(re, ">>> $1\n$2")
|
||||
doctest.parentNode.replaceChild(pre, doctest);
|
||||
container.appendChild(pre);
|
||||
|
||||
doctest.parentNode.replaceChild(container, doctest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10962,6 +11062,7 @@
|
||||
|
||||
remove() {
|
||||
this.button = null;
|
||||
this._stopThisSpeechIfPlaying();
|
||||
this.context.removeEventListener('DOMNodeRemoved', this._domWasChanged);
|
||||
super.remove();
|
||||
}
|
||||
@@ -10979,12 +11080,18 @@
|
||||
context.addEventListener('DOMNodeRemoved', this._domWasChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't remember why this was required - SO 20-11-2019
|
||||
*/
|
||||
_domWasChanged(event) {
|
||||
if (this.context == null) this._stop();
|
||||
else if (
|
||||
this.context['lastSpeechNode'] == window.speechSynthesis['speechPluginNode'] &&
|
||||
event.target == this.context
|
||||
) {
|
||||
if (event.target == this.context) this._stopThisSpeechIfPlaying();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the module if it is set in the context.
|
||||
*/
|
||||
_stopThisSpeechIfPlaying() {
|
||||
if (this.context == null || this.context['lastSpeechNode'] == window.speechSynthesis['speechPluginNode']) {
|
||||
this._stop();
|
||||
}
|
||||
}
|
||||
@@ -11008,7 +11115,6 @@
|
||||
* SO -17.07.19
|
||||
*/
|
||||
|
||||
let activeNode = window.speechSynthesis['speechPluginNode'];
|
||||
this._updateText();
|
||||
}
|
||||
|
||||
@@ -11050,6 +11156,8 @@
|
||||
this.context.classList.add('speech-plugin-is-reading');
|
||||
}
|
||||
|
||||
closed() {}
|
||||
|
||||
_cleanupText(node) {
|
||||
let text = node.textContent;
|
||||
text = this._removeShy(text);
|
||||
|
||||
Vendored
+346
-960
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user