Skip to content

Commit

Permalink
Reformat (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Nov 4, 2020
1 parent 28a582f commit f798aae
Showing 2 changed files with 19 additions and 18 deletions.
13 changes: 6 additions & 7 deletions lib/src/value/color.dart
Original file line number Diff line number Diff line change
@@ -98,8 +98,10 @@ class SassColor extends Value implements ext.SassColor {
factory SassColor.hwb(num hue, num whiteness, num blackness, [num alpha]) {
// From https://www.w3.org/TR/css-color-4/#hwb-to-rgb
var scaledHue = hue % 360 / 360;
var scaledWhiteness = fuzzyAssertRange(whiteness, 0, 100, "whiteness") / 100;
var scaledBlackness = fuzzyAssertRange(blackness, 0, 100, "blackness") / 100;
var scaledWhiteness =
fuzzyAssertRange(whiteness, 0, 100, "whiteness") / 100;
var scaledBlackness =
fuzzyAssertRange(blackness, 0, 100, "blackness") / 100;

var sum = scaledWhiteness + scaledBlackness;
if (sum > 1) {
@@ -117,11 +119,8 @@ class SassColor extends Value implements ext.SassColor {
// don't cache its values because we expect the memory overhead of doing so
// to outweigh the cost of recalculating it on access. Instead, we eagerly
// convert it to RGB and then convert back if necessary.
return SassColor.rgb(
toRgb(scaledHue + 1/3),
toRgb(scaledHue),
toRgb(scaledHue - 1/3),
alpha);
return SassColor.rgb(toRgb(scaledHue + 1 / 3), toRgb(scaledHue),
toRgb(scaledHue - 1 / 3), alpha);
}

SassColor._(this._red, this._green, this._blue, this._hue, this._saturation,
24 changes: 13 additions & 11 deletions test/dart_api/value/color_test.dart
Original file line number Diff line number Diff line change
@@ -130,22 +130,21 @@ void main() {
equals(SassColor.hwb(210, 7.0588235294117645, 42)));
expect(
value.changeHwb(alpha: 0.5),
equals(
SassColor.hwb(210, 7.0588235294117645, 66.27450980392157, 0.5)));
equals(SassColor.hwb(
210, 7.0588235294117645, 66.27450980392157, 0.5)));
expect(
value.changeHwb(
hue: 120, whiteness: 42, blackness: 42, alpha: 0.5),
value.changeHwb(hue: 120, whiteness: 42, blackness: 42, alpha: 0.5),
equals(SassColor.hwb(120, 42, 42, 0.5)));
expect(
value.changeHwb(whiteness: 50),
equals(SassColor.hwb(210, 43, 57)));
value.changeHwb(whiteness: 50), equals(SassColor.hwb(210, 43, 57)));
});

test("allows valid values", () {
expect(value.changeHwb(whiteness: 0).whiteness, equals(0));
expect(value.changeHwb(whiteness: 100).whiteness, equals(60.0));
expect(value.changeHwb(blackness: 0).blackness, equals(0));
expect(value.changeHwb(blackness: 100).blackness, equals(93.33333333333333));
expect(value.changeHwb(blackness: 100).blackness,
equals(93.33333333333333));
expect(value.changeHwb(alpha: 0).alpha, equals(0));
expect(value.changeHwb(alpha: 1).alpha, equals(1));
});
@@ -219,7 +218,10 @@ void main() {
test("equals the same color", () {
expect(value, equalsWithHash(SassColor.rgb(0x3E, 0x98, 0x3E)));
expect(value, equalsWithHash(SassColor.hsl(120, 42, 42)));
expect(value, equalsWithHash(SassColor.hwb(120, 24.313725490196077, 40.3921568627451)));
expect(
value,
equalsWithHash(
SassColor.hwb(120, 24.313725490196077, 40.3921568627451)));
});
});

@@ -295,9 +297,9 @@ void main() {
});

test("allows valid values", () {
expect(SassColor.hwb(0, 0, 0, 0), equals(parseValue("rgba(255, 0, 0, 0)")));
expect(SassColor.hwb(4320, 100, 100, 1),
equals(parseValue("grey")));
expect(
SassColor.hwb(0, 0, 0, 0), equals(parseValue("rgba(255, 0, 0, 0)")));
expect(SassColor.hwb(4320, 100, 100, 1), equals(parseValue("grey")));
});

test("disallows invalid values", () {

0 comments on commit f798aae

Please sign in to comment.