Skip to content

Commit

Permalink
updates d3plus-dev to v0.6.0 (closes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Feb 26, 2018
1 parent 141a938 commit 89e5231
Show file tree
Hide file tree
Showing 10 changed files with 2,366 additions and 1,018 deletions.
3,110 changes: 2,225 additions & 885 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"test": "d3plus-test"
},
"devDependencies": {
"d3plus-dev": "^0.5.3"
"d3plus-dev": "^0.6.0"
},
"module": "es/index",
"files": [
Expand Down
103 changes: 52 additions & 51 deletions test/TextBox.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
import zora from "zora";
import test from "zora";
import {default as TextBox} from "../src/TextBox.js";

export default zora()
.test("TextBox", function *(assert) {
test("TextBox", function *(assert) {

assert.end();
assert.end();

const data = {text: "Hello D3plus, please wrap this sentence for me."},
height = 200,
width = 200,
x = 100,
y = 100;
const data = {text: "Hello D3plus, please wrap this sentence for me."},
height = 200,
width = 200,
x = 100,
y = 100;

let testBox;
let testBox;

yield cb => {
testBox = new TextBox()
.data([data])
.fontSize(14)
.height(height)
.width(width)
.x(x)
.y(y)
.render(cb);
};
yield cb => {
testBox = new TextBox()
.data([data])
.fontSize(14)
.height(height)
.width(width)
.x(x)
.y(y)
.render(cb);
};

assert.equal(document.getElementsByTagName("svg").length, 1, "automatically added <svg> element to page");
assert.equal(document.getElementsByTagName("text").length, 1, "created <text> container element");
assert.equal(document.getElementsByTagName("tspan").length, 2, "created 2 <tspan> elements");
assert.equal(document.getElementsByTagName("svg").length, 1, "automatically added <svg> element to page");
assert.equal(document.getElementsByTagName("text").length, 1, "created <text> container element");
assert.equal(document.getElementsByTagName("tspan").length, 2, "created 2 <tspan> elements");

let tspans = document.getElementsByTagName("tspan");
assert.ok(tspans[0].textContent === "Hello D3plus, please wrap" &&
tspans[1].textContent === "this sentence for me.", "wrapped text");
let tspans = document.getElementsByTagName("tspan");
assert.ok(tspans[0].textContent === "Hello D3plus, please wrap" &&
tspans[1].textContent === "this sentence for me.", "wrapped text");

const elem = document.getElementById("d3plus-textBox-0");
let bbox = elem.getBBox();
assert.ok(bbox.width <= width, "fit within width");
assert.ok(bbox.height <= height, "fit within height");
assert.equal(Math.round(bbox.x), x, "x positioned correctly");
const elem = document.getElementById("d3plus-textBox-0");
let bbox = elem.getBBox();
assert.ok(bbox.width <= width, "fit within width");
assert.ok(bbox.height <= height, "fit within height");
assert.equal(Math.round(bbox.x), x, "x positioned correctly");

const yP = 1;
let y2 = y;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (top)");
const yP = 1;
let y2 = y;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (top)");

yield cb => testBox.verticalAlign("middle").render(cb);
yield cb => testBox.verticalAlign("middle").render(cb);

bbox = elem.getBBox();
y2 = y + height / 2 - bbox.height / 2;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (middle)");
bbox = elem.getBBox();
y2 = y + height / 2 - bbox.height / 2;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (middle)");

yield cb => testBox.verticalAlign("bottom").render(cb);
yield cb => testBox.verticalAlign("bottom").render(cb);

bbox = elem.getBBox();
y2 = y + height - bbox.height;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (bottom)");
bbox = elem.getBBox();
y2 = y + height - bbox.height;
assert.ok(y2 - yP <= bbox.y <= y + yP, "y positioned correctly (bottom)");

yield cb => testBox.fontResize(true).verticalAlign("top").render(cb);
yield cb => testBox.fontResize(true).verticalAlign("top").render(cb);

tspans = document.getElementsByTagName("tspan");
assert.ok(tspans[0].textContent === "Hello" &&
tspans[1].textContent === "D3plus," &&
tspans[2].textContent === "please" &&
tspans[3].textContent === "wrap this" &&
tspans[4].textContent === "sentence" &&
tspans[5].textContent === "for me.", "font resizing");
tspans = document.getElementsByTagName("tspan");
assert.ok(tspans[0].textContent === "Hello" &&
tspans[1].textContent === "D3plus," &&
tspans[2].textContent === "please" &&
tspans[3].textContent === "wrap this" &&
tspans[4].textContent === "sentence" &&
tspans[5].textContent === "for me.", "font resizing");

});
});

export default test;
27 changes: 14 additions & 13 deletions test/fontExists.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import zora from "zora";
import test from "zora";
import {default as fontExists} from "../src/fontExists.js";

export default zora()
.test("fontExists", assert => {
test("fontExists", assert => {

const missing = "Missing", valid = "DejaVuSans";
const missing = "Missing", valid = "DejaVuSans";

assert.equal(valid, fontExists(valid), "single - exists");
assert.equal(false, fontExists(missing), "single - missing");
assert.equal(valid, fontExists(`${valid}, ${missing}`), "string - first");
assert.equal(valid, fontExists(`${missing}, ${valid}`), "string - second");
assert.equal(false, fontExists(`${missing}, ${missing}2`), "string - none");
assert.equal(valid, fontExists([valid, missing]), "array - first");
assert.equal(valid, fontExists([missing, valid]), "array - second");
assert.equal(false, fontExists([missing, `${missing}2`]), "array - none");
assert.equal(valid, fontExists(valid), "single - exists");
assert.equal(false, fontExists(missing), "single - missing");
assert.equal(valid, fontExists(`${valid}, ${missing}`), "string - first");
assert.equal(valid, fontExists(`${missing}, ${valid}`), "string - second");
assert.equal(false, fontExists(`${missing}, ${missing}2`), "string - none");
assert.equal(valid, fontExists([valid, missing]), "array - first");
assert.equal(valid, fontExists([missing, valid]), "array - second");
assert.equal(false, fontExists([missing, `${missing}2`]), "array - none");

});
});

export default test;
21 changes: 11 additions & 10 deletions test/stringify.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import zora from "zora";
import test from "zora";
import {default as stringify} from "../src/stringify.js";

export default zora()
.test("stringify", assert => {
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");
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;
15 changes: 8 additions & 7 deletions test/strip.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import zora from "zora";
import test from "zora";
import {default as strip} from "../src/strip.js";

export default zora()
.test("strip", assert => {
test("strip", assert => {

assert.equal(strip("one two"), "one-two", "Space");
assert.equal(strip("one@two"), "onetwo", "Removed");
assert.equal(strip("á"), "a", "Diacritic");
assert.equal(strip("one two"), "one-two", "Space");
assert.equal(strip("one@two"), "onetwo", "Removed");
assert.equal(strip("á"), "a", "Diacritic");

});
});

export default test;
41 changes: 21 additions & 20 deletions test/textSplit.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import zora from "zora";
import test from "zora";
import {default as textSplit, splitChars} from "../src/textSplit.js";

export default zora()
.test("textSplit", assert => {
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}"`);
}
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");
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");
const chinese = textSplit("里句。");
assert.ok(chinese[0] === "里" && chinese[1] === "句。", "simplified chinese");

const burmese = textSplit("ကြောယ်။");
assert.ok(burmese[0] === "ကြော" && burmese[1] === "ယ်။", "burmese");
const burmese = textSplit("ကြောယ်။");
assert.ok(burmese[0] === "ကြော" && burmese[1] === "ယ်။", "burmese");

const lao = textSplit("ຕໍ່ດ້.");
assert.ok(lao[0] === "ຕໍ່" && lao[1] === "ດ້.", "lao");
const lao = textSplit("ຕໍ່ດ້.");
assert.ok(lao[0] === "ຕໍ່" && lao[1] === "ດ້.", "lao");

});
});

export default test;
23 changes: 12 additions & 11 deletions test/textWidth.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import zora from "zora";
import test from "zora";
import {default as textWidth} from "../src/textWidth.js";

export default zora()
.test("textWidth", assert => {
test("textWidth", assert => {

const base = textWidth("Test", {"font-family": "Verdana", "font-size": 14}),
bigger = textWidth("Test", {"font-family": "Verdana", "font-size": 28}),
bolder = textWidth("Test", {"font-family": "Verdana", "font-size": 14, "font-weight": "bold"}),
longer = textWidth("TestTest", {"font-family": "Verdana", "font-size": 14});
const base = textWidth("Test", {"font-family": "Verdana", "font-size": 14}),
bigger = textWidth("Test", {"font-family": "Verdana", "font-size": 28}),
bolder = textWidth("Test", {"font-family": "Verdana", "font-size": 14, "font-weight": "bold"}),
longer = textWidth("TestTest", {"font-family": "Verdana", "font-size": 14});

assert.ok(base * 2 === longer, "string length");
assert.ok(base < bigger, "font-size");
assert.ok(base < bolder, "font-weight");
assert.ok(base * 2 === longer, "string length");
assert.ok(base < bigger, "font-size");
assert.ok(base < bolder, "font-weight");

});
});

export default test;
29 changes: 15 additions & 14 deletions test/textWrap.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import zora from "zora";
import test from "zora";
import {default as textWrap} from "../src/textWrap.js";

export default zora()
.test("textWrap", assert => {
test("textWrap", assert => {

const sentence = "Hello D3plus, please wrap this sentence for me.",
testWrap = textWrap().fontFamily("Verdana").fontSize(14)(sentence);
const sentence = "Hello D3plus, please wrap this sentence for me.",
testWrap = textWrap().fontFamily("Verdana").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");
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("Verdana").fontSize(14)(spaceTest);
assert.equal(spaceWrap.lines[0], spaceTest, "catch for multiple spaces");
const spaceTest = "Two Space Test",
spaceWrap = textWrap().fontFamily("Verdana").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)");
assert.equal(textWrap()("A\nB").lines[0], "A", "catch for literal line break (\\n)");

});
});

export default test;
13 changes: 7 additions & 6 deletions test/titleCase.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import zora from "zora";
import test from "zora";
import {default as titleCase} from "../src/titleCase.js";

export default zora()
.test("titleCase", assert => {
test("titleCase", assert => {

assert.equal(titleCase("this/that"), "This/That", "Non-space Break");
assert.equal(titleCase("this and that"), "This and That", "Lowercase Word");
assert.equal(titleCase("this/that"), "This/That", "Non-space Break");
assert.equal(titleCase("this and that"), "This and That", "Lowercase Word");

});
});

export default test;

0 comments on commit 89e5231

Please sign in to comment.