wolsey
Version:
Output numbers as numerals and ordinals
165 lines (147 loc) • 6.43 kB
JavaScript
var Log = require("log");
var log = new Log(process.env.loglevel || "error");
var Wolsey = require("../wolsey");
describe("Wolsey.numeral", function() {
function expectNumerals (cardinal, vals, options) {
vals.forEach(function (val) {
expect(cardinal.numeral(val[0], options)).toBe(val[1]);
});
}
it("can convert numbers", function () {
var vals = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
expectNumerals(new Wolsey(), vals);
});
xit("can handle different langs and default langs", function () {
var gbvals = [
[],
[]
];
var usvals = [
[],
[]
];
var foovals = [
[],
[]
];
var foo = {
numeral: function (num) {
if (num == 27) { return "foobar"; }
if (num == 206) { return "foobaztic"; }
},
ordinal: function (num) {
return "Not implemented";
},
ordinalAsNumber: function (num) {
return "Not implemented";
}
};
var cardinal = new Wolsey("foo", foo);
expectNumerals(cardinal, foovals);
expectNumerals(cardinal, gbvals, {lang: "en-gb"});
cardinal.setDefault("en-us");
expectNumerals(cardinal, usvals);
cardinal.resetDefault();
expectNumerals(cardinal, foovals);
});
xit("can handle strings and invalid cases", function () {
var vals = [
["98", "ninety eight"],
["99 red balloons", "99 red balloons"]
];
expectNumerals(new Wolsey(), vals);
});
xit("can create custom en langs", function () {
var vals = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
var enCustom = Wolsey.EN({separator: "", hyphenatecompound: true});
var cardinal = new Wolsey("en-custom", enCustom);
expectNumerals(cardinal, vals);
});
});
log.info("Tests described");