Add tests for SassNumber.valueInRange() (#212)

This commit is contained in:
Natalie Weizenbaum 2018-01-14 15:18:16 -08:00 committed by GitHub
parent 9d207b13ec
commit b1b9eca66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,6 +48,19 @@ main() {
expect(value.valueInUnits(["abc"], ["def"]), equals(123)); expect(value.valueInUnits(["abc"], ["def"]), equals(123));
}); });
group("valueInRange()", () {
test("returns its value within a given range", () {
expect(value.valueInRange(0, 123), equals(123));
expect(value.valueInRange(123, 123), equals(123));
expect(value.valueInRange(123, 1000), equals(123));
});
test("rejects a value outside the range", () {
expect(() => value.valueInRange(0, 122), throwsSassScriptException);
expect(() => value.valueInRange(124, 1000), throwsSassScriptException);
});
});
test("equals the same number", () { test("equals the same number", () {
expect(value, equalsWithHash(new SassNumber(123))); expect(value, equalsWithHash(new SassNumber(123)));
}); });
@ -136,6 +149,19 @@ main() {
equalsWithHash( equalsWithHash(
new SassNumber(123 - math.pow(10, -SassNumber.precision - 1)))); new SassNumber(123 - math.pow(10, -SassNumber.precision - 1))));
}); });
group("valueInRange()", () {
test("clamps within the given range", () {
expect(value.valueInRange(0, 123), equals(123));
expect(value.valueInRange(123, 123), equals(123));
expect(value.valueInRange(123, 1000), equals(123));
});
test("rejects a value outside the range", () {
expect(() => value.valueInRange(0, 122), throwsSassScriptException);
expect(() => value.valueInRange(124, 1000), throwsSassScriptException);
});
});
}); });
group("an integer with a single numerator unit", () { group("an integer with a single numerator unit", () {