|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:yaru/src/colors.dart'; |
| 4 | + |
| 5 | +final Matcher throwsAssertionError = throwsA(isA<AssertionError>()); |
| 6 | +final Color midColor = const HSLColor.fromAHSL(.5, 180, .5, .5).toColor(); |
| 7 | + |
| 8 | +void main() { |
| 9 | + group('Color.scale() test -', () { |
| 10 | + test('With out of range amount', () { |
| 11 | + expect(() => midColor.scale(alpha: -1.1), throwsAssertionError); |
| 12 | + expect(() => midColor.scale(alpha: 1.1), throwsAssertionError); |
| 13 | + expect(() => midColor.scale(hue: -1.1), throwsAssertionError); |
| 14 | + expect(() => midColor.scale(hue: 1.1), throwsAssertionError); |
| 15 | + expect(() => midColor.scale(saturation: -1.1), throwsAssertionError); |
| 16 | + expect(() => midColor.scale(saturation: 1.1), throwsAssertionError); |
| 17 | + expect(() => midColor.scale(lightness: -1.1), throwsAssertionError); |
| 18 | + expect(() => midColor.scale(lightness: 1.1), throwsAssertionError); |
| 19 | + }); |
| 20 | + test('With clamped amount', () { |
| 21 | + expect( |
| 22 | + midColor.scale(alpha: -1.0), |
| 23 | + const Color(0x0040bfbf), |
| 24 | + ); |
| 25 | + expect( |
| 26 | + midColor.scale(alpha: 1.0), |
| 27 | + const Color(0xff40bfbf), |
| 28 | + ); |
| 29 | + expect( |
| 30 | + midColor.scale(hue: -1.0), |
| 31 | + const Color(0x80bf4040), |
| 32 | + ); |
| 33 | + expect( |
| 34 | + midColor.scale(hue: 1.0), |
| 35 | + const Color(0x80bf4040), |
| 36 | + ); |
| 37 | + expect( |
| 38 | + midColor.scale(saturation: -1.0), |
| 39 | + const Color(0x80808080), |
| 40 | + ); |
| 41 | + expect( |
| 42 | + midColor.scale(saturation: 1.0), |
| 43 | + const Color(0x8000ffff), |
| 44 | + ); |
| 45 | + expect( |
| 46 | + midColor.scale(lightness: -1.0), |
| 47 | + const Color(0x80000000), |
| 48 | + ); |
| 49 | + expect( |
| 50 | + midColor.scale(lightness: 1.0), |
| 51 | + const Color(0x80ffffff), |
| 52 | + ); |
| 53 | + }); |
| 54 | + test('With medium amount', () { |
| 55 | + expect( |
| 56 | + midColor.scale(alpha: -0.5), |
| 57 | + const Color(0x4040bfbf), |
| 58 | + ); |
| 59 | + expect( |
| 60 | + midColor.scale(alpha: 0.5), |
| 61 | + const Color(0xc040bfbf), |
| 62 | + ); |
| 63 | + expect( |
| 64 | + midColor.scale(hue: -0.5), |
| 65 | + const Color(0x8080bf40), |
| 66 | + ); |
| 67 | + expect( |
| 68 | + midColor.scale(hue: 0.5), |
| 69 | + const Color(0x808040bf), |
| 70 | + ); |
| 71 | + expect( |
| 72 | + midColor.scale(saturation: -0.5), |
| 73 | + const Color(0x80609f9f), |
| 74 | + ); |
| 75 | + expect( |
| 76 | + midColor.scale(saturation: 0.5), |
| 77 | + const Color(0x8020dfdf), |
| 78 | + ); |
| 79 | + expect( |
| 80 | + midColor.scale(lightness: -0.5), |
| 81 | + const Color(0x80206060), |
| 82 | + ); |
| 83 | + expect( |
| 84 | + midColor.scale(lightness: 0.5), |
| 85 | + const Color(0x80a0dfdf), |
| 86 | + ); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + group('Color.adjust() test -', () { |
| 91 | + test('With out of range amount', () { |
| 92 | + expect(() => midColor.adjust(alpha: -1.1), throwsAssertionError); |
| 93 | + expect(() => midColor.adjust(alpha: 1.1), throwsAssertionError); |
| 94 | + expect(() => midColor.adjust(hue: -360.1), throwsAssertionError); |
| 95 | + expect(() => midColor.adjust(hue: 360.1), throwsAssertionError); |
| 96 | + expect(() => midColor.adjust(saturation: -1.1), throwsAssertionError); |
| 97 | + expect(() => midColor.adjust(saturation: 1.1), throwsAssertionError); |
| 98 | + expect(() => midColor.adjust(lightness: -1.1), throwsAssertionError); |
| 99 | + expect(() => midColor.adjust(lightness: 1.1), throwsAssertionError); |
| 100 | + }); |
| 101 | + test('With clamped amount', () { |
| 102 | + expect( |
| 103 | + midColor.adjust(alpha: -1.0), |
| 104 | + const Color(0x0040bfbf), |
| 105 | + ); |
| 106 | + expect( |
| 107 | + midColor.adjust(alpha: 1.0), |
| 108 | + const Color(0xff40bfbf), |
| 109 | + ); |
| 110 | + expect( |
| 111 | + midColor.adjust(hue: -180), |
| 112 | + const Color(0x80bf4040), |
| 113 | + ); |
| 114 | + expect( |
| 115 | + midColor.adjust(hue: 180), |
| 116 | + const Color(0x80bf4040), |
| 117 | + ); |
| 118 | + expect( |
| 119 | + midColor.adjust(saturation: -1.0), |
| 120 | + const Color(0x80808080), |
| 121 | + ); |
| 122 | + expect( |
| 123 | + midColor.adjust(saturation: 1.0), |
| 124 | + const Color(0x8000ffff), |
| 125 | + ); |
| 126 | + expect( |
| 127 | + midColor.adjust(lightness: -1.0), |
| 128 | + const Color(0x80000000), |
| 129 | + ); |
| 130 | + expect( |
| 131 | + midColor.adjust(lightness: 1.0), |
| 132 | + const Color(0x80ffffff), |
| 133 | + ); |
| 134 | + }); |
| 135 | + test('With medium amount', () { |
| 136 | + expect( |
| 137 | + midColor.adjust(alpha: -0.25), |
| 138 | + const Color(0x4040bfbf), |
| 139 | + ); |
| 140 | + expect( |
| 141 | + midColor.adjust(alpha: 0.25), |
| 142 | + const Color(0xc040bfbf), |
| 143 | + ); |
| 144 | + expect( |
| 145 | + midColor.adjust(hue: -90), |
| 146 | + const Color(0x8080bf40), |
| 147 | + ); |
| 148 | + expect( |
| 149 | + midColor.adjust(hue: 90), |
| 150 | + const Color(0x808040bf), |
| 151 | + ); |
| 152 | + expect( |
| 153 | + midColor.adjust(saturation: -0.25), |
| 154 | + const Color(0x80609f9f), |
| 155 | + ); |
| 156 | + expect( |
| 157 | + midColor.adjust(saturation: 0.25), |
| 158 | + const Color(0x8020dfdf), |
| 159 | + ); |
| 160 | + expect( |
| 161 | + midColor.adjust(lightness: -0.25), |
| 162 | + const Color(0x80206060), |
| 163 | + ); |
| 164 | + expect( |
| 165 | + midColor.adjust(lightness: 0.25), |
| 166 | + const Color(0x80a0dfdf), |
| 167 | + ); |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + group('Color.copyWith() test -', () { |
| 172 | + test('With out of range amount', () { |
| 173 | + expect(() => midColor.copyWith(alpha: -1.1), throwsAssertionError); |
| 174 | + expect(() => midColor.copyWith(alpha: 1.1), throwsAssertionError); |
| 175 | + expect(() => midColor.copyWith(hue: -360.1), throwsAssertionError); |
| 176 | + expect(() => midColor.copyWith(hue: 360.1), throwsAssertionError); |
| 177 | + expect(() => midColor.copyWith(saturation: -1.1), throwsAssertionError); |
| 178 | + expect(() => midColor.copyWith(saturation: 1.1), throwsAssertionError); |
| 179 | + expect(() => midColor.copyWith(lightness: -1.1), throwsAssertionError); |
| 180 | + expect(() => midColor.copyWith(lightness: 1.1), throwsAssertionError); |
| 181 | + }); |
| 182 | + test('With various amount', () { |
| 183 | + expect( |
| 184 | + midColor.copyWith(alpha: 0.25), |
| 185 | + const Color(0x4040bfbf), |
| 186 | + ); |
| 187 | + expect( |
| 188 | + midColor.copyWith(hue: 90), |
| 189 | + const Color(0x8080bf40), |
| 190 | + ); |
| 191 | + expect( |
| 192 | + midColor.copyWith(saturation: 0.75), |
| 193 | + const Color(0x8020dfdf), |
| 194 | + ); |
| 195 | + expect( |
| 196 | + midColor.copyWith(lightness: 0.75), |
| 197 | + const Color(0x80a0dfdf), |
| 198 | + ); |
| 199 | + }); |
| 200 | + }); |
| 201 | +} |
0 commit comments