@@ -51,40 +51,66 @@ main() {
5151 expect (toRem (new CssValue .parse ('15px' )), new CssValue (0.75 , 'rem' ));
5252 });
5353
54- test ('converts an int value (treated as px) to rem' , () {
54+ test ('converts nums (treated as px) to rem' , () {
5555 expect (toRem (15 ), new CssValue (0.75 , 'rem' ));
56+ expect (toRem (20.2 ), new CssValue (1.01 , 'rem' ));
5657 });
5758
58- test ('converts a double (treated as px) to rem' , () {
59- expect (toRem (20.2 ), new CssValue (1.01 , 'rem' ));
59+ test ('does not convert nums when `treatNumAsRem` is true' , () {
60+ expect (toRem (15 , treatNumAsRem: true ), new CssValue (15 , 'rem' ));
61+ expect (toRem (20.2 , treatNumAsRem: true ), new CssValue (20.2 , 'rem' ));
62+ });
63+
64+ test ('gracefully handles a rem String, not doing any conversion' , () {
65+ expect (toRem ('1334rem' ), new CssValue (1334 , 'rem' ));
66+ });
67+
68+ test ('gracefully handles a rem CssValue, not doing any conversion' , () {
69+ expect (toRem (new CssValue (1334 , 'rem' )), new CssValue (1334 , 'rem' ));
70+ });
71+
72+ test ('gracefully passes through `null`' , () {
73+ expect (toRem (null ), null );
6074 });
6175
6276 test ('throws when passed an invalid value' , () {
6377 expect (() => toRem (new Object ()), allOf (
6478 throwsArgumentError,
65- throwsA (hasToStringValue (contains ('must be a num or a String px value' ))))
79+ throwsA (hasToStringValue (contains ('must be a px num or a String px/rem value' ))))
6680 );
6781 });
6882
6983 test ('throws when passed a malformed CSS value string' , () {
7084 expect (() => toRem ('' ), allOf (
7185 throwsArgumentError,
72- throwsA (hasToStringValue (contains ('must be a num or a String px value' ))))
86+ throwsA (hasToStringValue (contains ('must be a px num or a String px/rem value' ))))
7387 );
7488 });
7589
76- test ('throws when passed a CSS value string with a unit other than px' , () {
77- expect (() => toRem ('1em' ), allOf (
78- throwsArgumentError,
79- throwsA (hasToStringValue (contains ('must be a num or a String px value' ))))
80- );
90+ group ('throws when passed a CSS value string with a unit other than px/rem' , () {
91+ test ('' , () {
92+ expect (() => toRem ('1em' ), allOf (
93+ throwsArgumentError,
94+ throwsA (hasToStringValue (contains ('must be a px num or a String px/rem value' ))))
95+ );
96+ });
97+
98+ test ('unless `passThroughUnsupportedUnits` is true' , () {
99+ expect (toRem ('1em' , passThroughUnsupportedUnits: true ), new CssValue .parse ('1em' ));
100+ });
81101 });
82102
83- test ('throws when passed a CssValue instance with a unit other than px' , () {
84- expect (() => toRem (new CssValue .parse ('1em' )), allOf (
85- throwsArgumentError,
86- throwsA (hasToStringValue (contains ('must be a num or a String px value' ))))
87- );
103+ group ('throws when passed a CssValue instance with a unit other than px/rem' , () {
104+ test ('' , () {
105+ expect (() => toRem (new CssValue .parse ('1em' )), allOf (
106+ throwsArgumentError,
107+ throwsA (hasToStringValue (contains ('must be a px num or a String px/rem value' ))))
108+ );
109+ });
110+
111+ test ('unless `passThroughUnsupportedUnits` is true' , () {
112+ expect (toRem (new CssValue .parse ('1em' ), passThroughUnsupportedUnits: true ), new CssValue .parse ('1em' ));
113+ });
88114 });
89115 });
90116
@@ -105,40 +131,66 @@ main() {
105131 expect (toPx (new CssValue .parse ('0.75rem' )), new CssValue (15 , 'px' ));
106132 });
107133
108- test ('converts an int value (treated as rem) to px' , () {
134+ test ('converts nums (treated as rem) to px' , () {
109135 expect (toPx (3 ), new CssValue (60 , 'px' ));
136+ expect (toPx (1.01 ), new CssValue (20.2 , 'px' ));
110137 });
111138
112- test ('converts a double (treated as rem) to px' , () {
113- expect (toPx (1.01 ), new CssValue (20.2 , 'px' ));
139+ test ('does not convert nums when `treatNumAsPx` is true' , () {
140+ expect (toPx (3 , treatNumAsPx: true ), new CssValue (3 , 'px' ));
141+ expect (toPx (1.01 , treatNumAsPx: true ), new CssValue (1.01 , 'px' ));
142+ });
143+
144+ test ('gracefully handles a px String, not doing any conversion' , () {
145+ expect (toPx ('1334px' ), new CssValue (1334 , 'px' ));
146+ });
147+
148+ test ('gracefully handles a px CssValue, not doing any conversion' , () {
149+ expect (toPx (new CssValue (1334 , 'px' )), new CssValue (1334 , 'px' ));
150+ });
151+
152+ test ('gracefully passes through `null`' , () {
153+ expect (toPx (null ), null );
114154 });
115155
116156 test ('throws when passed an invalid value' , () {
117157 expect (() => toPx (new Object ()), allOf (
118158 throwsArgumentError,
119- throwsA (hasToStringValue (contains ('must be a num or a String rem value' ))))
159+ throwsA (hasToStringValue (contains ('must be a rem num or a String px/ rem value' ))))
120160 );
121161 });
122162
123163 test ('throws when passed a malformed CSS value string' , () {
124164 expect (() => toPx ('' ), allOf (
125165 throwsArgumentError,
126- throwsA (hasToStringValue (contains ('must be a num or a String rem value' ))))
166+ throwsA (hasToStringValue (contains ('must be a rem num or a String px/ rem value' ))))
127167 );
128168 });
129169
130- test ('throws when passed a CSS value string with a unit other than px' , () {
131- expect (() => toPx ('1em' ), allOf (
132- throwsArgumentError,
133- throwsA (hasToStringValue (contains ('must be a num or a String rem value' ))))
134- );
170+ group ('throws when passed a CSS value string with a unit other than px/rem' , () {
171+ test ('' , () {
172+ expect (() => toPx ('1em' ), allOf (
173+ throwsArgumentError,
174+ throwsA (hasToStringValue (contains ('must be a rem num or a String px/rem value' ))))
175+ );
176+ });
177+
178+ test ('unless `passThroughUnsupportedUnits` is true' , () {
179+ expect (toPx ('1em' , passThroughUnsupportedUnits: true ), new CssValue .parse ('1em' ));
180+ });
135181 });
136182
137- test ('throws when passed a CssValue instance with a unit other than px' , () {
138- expect (() => toPx (new CssValue .parse ('1em' )), allOf (
139- throwsArgumentError,
140- throwsA (hasToStringValue (contains ('must be a num or a String rem value' ))))
141- );
183+ group ('throws when passed a CssValue instance with a unit other than px/rem' , () {
184+ test ('' , () {
185+ expect (() => toPx (new CssValue .parse ('1em' )), allOf (
186+ throwsArgumentError,
187+ throwsA (hasToStringValue (contains ('must be a rem num or a String px/rem value' ))))
188+ );
189+ });
190+
191+ test ('unless `passThroughUnsupportedUnits` is true' , () {
192+ expect (toPx (new CssValue .parse ('1em' ), passThroughUnsupportedUnits: true ), new CssValue .parse ('1em' ));
193+ });
142194 });
143195 });
144196
0 commit comments