webpack/test/Template.unittest.js

30 lines
766 B
JavaScript
Raw Normal View History

2017-01-18 23:17:10 +08:00
"use strict";
2017-11-15 21:08:11 +08:00
require("should");
const Template = require("../lib/Template");
2017-01-18 23:17:10 +08:00
describe("Template", () => {
it("should generate valid identifiers", () =>
Template.toIdentifier("0abc-def9").should.equal("_0abc_def9"));
2017-01-18 23:17:10 +08:00
it("should generate valid number identifiers", () => {
const items = [];
let item;
2018-02-25 09:00:20 +08:00
for (let i = 0; i < 80; i += 1) {
item = Template.numberToIdentifer(i);
2018-02-25 09:00:20 +08:00
if (item === "") {
2017-01-18 23:17:10 +08:00
throw new Error("empty number identifier");
2018-02-25 09:00:20 +08:00
} else if (items.indexOf(item) > -1) {
2017-01-18 23:17:10 +08:00
throw new Error("duplicate number identifier");
} else {
items.push(item);
}
}
});
it("should generate sanitized path identifiers", () => {
2018-02-25 09:00:20 +08:00
Template.toPath("path/to-sdfas/sadfome$$.js").should.equal(
"path-to-sdfas-sadfome$$-js"
);
});
});