Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { test } = require('zora');
/* This tests based on "The pitfalls of verifying floating-point computations" by David Monniaux */
/* [PDF] https://hal.archives-ouvertes.fr/hal-00128124/file/floating-point-article.pdf */
test('Simplified floating point paranoia in javascript', t => {
expected = Infinity;
actual = (1e308 + 1e308) / 1e308;
t.ok(actual == expected, 'Infinity');
actual = 0/0;
t.ok(isNaN(actual), 'NaN');
expected = 1.0000000000000002;
actual = 1 / (1 - Math.pow(2,-53))
t.ok(actual == expected, 'double rounding 1');
expected = Infinity;
actual = 1e1023 * (2 - Math.pow(2, -52))
t.ok(actual == expected, 'double rounding 2');
expected = 9007199254740994;
actual = 1 - 1/65536 + 9007199254740994;
t.ok(actual == expected, 'SSE2 rounding 1');
expected = 1.1125369292536007e-308;
actual = 1.5 * 2.2250738585072014e-308 - 2.2250738585072014e-308;
import {test} from "zora";
import {default as assign} from "../src/assign.js";
test("assign", assert => {
const a = {id: "foo", deep: {group: "A"}},
b = {id: "bar", deep: {value: 20}},
c = {deep: {group: "B"}, other: 2};
const obj = assign({}, a, b, c);
assert.equal(obj.id, "bar", "base value");
assert.equal(obj.deep.value, 20, "deep value");
assert.equal(obj.deep.group, "B", "deep value overwrite");
assert.equal(a.deep.group, "A", "non-destructive");
assert.equal(a.deep.value, undefined, "non-additive");
});
export default test;
import {test} from "zora";
import {default as TextBox} from "../src/TextBox.js";
test("TextBox", function *(assert) {
assert.end();
const height = 200,
width = 200,
x = 100,
y = 100;
let testBox;
yield cb => {
testBox = new TextBox()
.data([{text: "Hello D3plus, please wrap this sentence for me."}])
.fontSize(14)
.height(height)
.width(width)
import {test} from "zora";
import {default as titleCase} from "../src/titleCase.js";
test("titleCase", assert => {
assert.equal(titleCase("this-that"), "This-That", "Non-space Break");
assert.equal(titleCase("this and that"), "This and That", "Lowercase Word");
});
export default test;
import {test} from "zora";
import {default as textSplit, splitChars} from "../src/textSplit.js";
test("textSplit", assert => {
for (let i = 0; i < splitChars.length; i++) {
let char = splitChars[i];
if (char.startsWith("u")) char = String.fromCharCode(`0x${char.slice(1)}`);
const sentence = `test${char}test`;
const arr = textSplit(sentence);
const first = char === " " ? "test" : `test${char}`;
assert.ok(arr[0] === first && arr[1] === "test", `using "${char}"`);
}
assert.equal(textSplit("-4")[0], "-4", "string starting with split character");
assert.equal(textSplit("This & That")[1], "&", "solo split character");
const chinese = textSplit("里句。");
assert.ok(chinese[0] === "里" && chinese[1] === "句。", "simplified chinese");
import {test} from "zora";
import {default as constant} from "../src/constant.js";
test("constant", assert => {
assert.equal(constant(42)(), 42, "Number");
assert.equal(constant("value")(), "value", "String");
const arr = [1, 2, 3];
assert.equal(constant(arr)(), arr, "Array");
const obj = {foo: "bar"};
assert.equal(constant(obj)(), obj, "Object");
});
export default test;
import {test} from "zora";
import {default as textWidth} from "../src/textWidth.js";
test("textWidth", assert => {
const font = "Verdana";
const base = textWidth("Test", {"font-family": font, "font-size": 14}),
bigger = textWidth("Test", {"font-family": font, "font-size": 28}),
bolder = textWidth("Test", {"font-family": font, "font-size": 14, "font-weight": "bold"}),
longer = textWidth("TestTest", {"font-family": font, "font-size": 14});
assert.ok(base * 2 === longer, "string length");
assert.ok(base < bigger, "font-size");
assert.ok(base < bolder, "font-weight");
});
export default test;
import {test} from "zora";
import {default as strip} from "../src/strip.js";
test("strip", assert => {
assert.equal(strip("one two"), "one-two", "Space");
assert.equal(strip("one@two"), "onetwo", "Removed");
assert.equal(strip("á"), "a", "Diacritic");
});
export default test;
import {test} from "zora";
import {default as textWrap} from "../src/textWrap.js";
test("textWrap", assert => {
const font = "Verdana";
const sentence = "Hello D3plus, please wrap this sentence for me.",
testWrap = textWrap().fontFamily(font).fontSize(14)(sentence);
assert.ok(testWrap.lines[0] === "Hello D3plus, please wrap" &&
testWrap.lines[1] === "this sentence for me.", "returning wrapped lines");
assert.equal(testWrap.sentence, "Hello D3plus, please wrap this sentence for me.", "returning original sentence");
assert.equal(testWrap.truncated, false, "returning truncated boolean");
const spaceTest = "Two Space Test",
spaceWrap = textWrap().fontFamily(font).fontSize(14)(spaceTest);
assert.equal(spaceWrap.lines[0], spaceTest, "catch for multiple spaces");
assert.equal(textWrap()("A\nB").lines[0], "A", "catch for literal line break (\\n)");
import {test} from "zora";
import {default as stringify} from "../src/stringify.js";
test("stringify", assert => {
assert.equal(stringify(true), "true");
assert.equal(stringify(false), "false");
assert.equal(stringify(undefined), "undefined");
assert.equal(stringify(42), "42", "integer");
assert.equal(stringify(3.14159265), "3.14159265", "float");
assert.equal(stringify("string"), "string");
});
export default test;