@@ -7,6 +7,7 @@ void main() {
77      input.length >  3  ?  null  :  errorMsg;
88  String ?  isEven (int  input) =>  input %  2  ==  0  ?  null  :  errorMsg;
99  String ?  greaterThan9 (num  input) =>  input >  9  ?  null  :  errorMsg;
10+   String ?  isT (bool  input) =>  input ?  null  :  errorMsg;
1011
1112  group ('Validator: isString' , () {
1213    test ('Should only check if the input is a String' , () {
@@ -115,4 +116,59 @@ void main() {
115116      expect (v (- 23.34 ), isNull);
116117    });
117118  });
119+ 
120+   group ('Validator: isBool' , () {
121+     test ('Should only check if the input is a bool/parsable to bool' , () {
122+       // defaults to case insensitive and trim 
123+       final  Validator <Object > v =  isBool ();
124+ 
125+       expect (v ('not a bool' ), equals (tmpIsBoolMsg));
126+       expect (v ('T' ), equals (tmpIsBoolMsg));
127+       expect (v ('isTrue' ), equals (tmpIsBoolMsg));
128+       expect (v ('true.' ), equals (tmpIsBoolMsg));
129+       expect (v ('true true' ), equals (tmpIsBoolMsg));
130+       expect (v (true ), isNull);
131+       expect (v (1  >  2 ), isNull);
132+       expect (v (false ), isNull);
133+       expect (v ('True' ), isNull);
134+       expect (v ('TrUe' ), isNull);
135+       expect (v (' true' ), isNull);
136+       expect (v ('true\n ' ), isNull);
137+     });
138+     test (
139+         'Should only check if the input is a bool/parsable to bool without trim and with case sensitiveness' ,
140+         () {
141+       final  Validator <Object > v =  isBool (null , null , true , false );
142+ 
143+       expect (v ('not a bool' ), equals (tmpIsBoolMsg));
144+       expect (v ('T' ), equals (tmpIsBoolMsg));
145+       expect (v ('isTrue' ), equals (tmpIsBoolMsg));
146+       expect (v ('true.' ), equals (tmpIsBoolMsg));
147+       expect (v (true ), isNull);
148+       expect (v (1  >  2 ), isNull);
149+       expect (v (false ), isNull);
150+       expect (v ('True' ), equals (tmpIsBoolMsg));
151+       expect (v ('TrUe' ), equals (tmpIsBoolMsg));
152+       expect (v (' true' ), equals (tmpIsBoolMsg));
153+       expect (v ('true\n ' ), equals (tmpIsBoolMsg));
154+     });
155+     test ('Should check if the input is true' , () {
156+       final  Validator <Object > v =  isBool (isT);
157+ 
158+       expect (v ('not a bool' ), equals (tmpIsBoolMsg));
159+       expect (v (true ), isNull);
160+       expect (v (1  >  2 ), equals (errorMsg));
161+       expect (v (false ), equals (errorMsg));
162+       expect (v ('False' ), equals (errorMsg));
163+       expect (v ('fAlSE   \n  ' ), equals (errorMsg));
164+     });
165+     test ('Should check if the input is a bool using custom error' , () {
166+       const  String  customError =  'custom error' ;
167+       final  Validator <Object > v =  isBool (null , customError);
168+ 
169+       expect (v ('not num' ), equals (customError));
170+       expect (v (true ), isNull);
171+       expect (v (false ), isNull);
172+     });
173+   });
118174}
0 commit comments