Add tests for strict unit errors

This commit is contained in:
Luke Page
2013-01-31 07:06:59 +00:00
parent 3ef22f16f9
commit c27922890d
9 changed files with 24 additions and 4 deletions

View File

@@ -18,7 +18,7 @@ tree.Dimension.prototype = {
},
toCSS: function (env) {
if ((!env || env.strictUnits !== false) && !this.unit.isSingular()) {
throw new Error("multiple units in dimension: "+this.unit.toString());
throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: "+this.unit.toString());
}
var value = this.value,
@@ -55,9 +55,9 @@ tree.Dimension.prototype = {
} else {
other = other.convertTo(this.unit.usedUnits());
if(env.strictUnits !== false && other.unit.toCSS() !== unit.toCSS()) {
throw new Error("Incompatible units: '" + unit.toCSS() +
"' and '" + other.unit.toCSS() + "'.");
if(env.strictUnits !== false && other.unit.toString() !== unit.toString()) {
throw new Error("Incompatible units. Change the units or use the unit function. Bad units: '" + unit.toString() +
"' and '" + other.unit.toString() + "'.");
}
value = tree.operate(env, op, this.value, other.value);