@@ -588,6 +588,44 @@ describe('Test lib.js:', function() {
588
588
589
589
590
590
} ) ;
591
+
592
+ describe ( 'enumerated types' , function ( ) {
593
+ var attrs = {
594
+ a : { valType : 'enumerated' , dflt : 8 , coerceNumber : true , values : [ 2 , 'e' , true , 8 ] } ,
595
+ b : { valType : 'enumerated' , dflt : 8 , values : [ 2 , 'e' , true , 8 ] }
596
+ } ;
597
+
598
+ it ( 'should allow only the enum values' , function ( ) {
599
+ out = coerce ( undefined , { } , attrs , 'a' ) ;
600
+ expect ( out ) . toBe ( 8 ) ;
601
+ } ) ;
602
+
603
+ it ( 'should be strict about numbers when coerceNumber isn\'t set' , function ( ) {
604
+ out = coerce ( { b : '2' } , { } , attrs , 'b' ) ;
605
+ expect ( out ) . toBe ( 8 ) ;
606
+ } ) ;
607
+
608
+ it ( 'should coerce when coerceNumber is set' , function ( ) {
609
+ out = coerce ( { a : '2' } , { } , attrs , 'a' ) ;
610
+ expect ( out ) . toBe ( 2 ) ;
611
+ } ) ;
612
+
613
+ it ( 'should use the default when given an invalid value' , function ( ) {
614
+ out = coerce ( { a : 'invalid' } , { } , attrs , 'a' ) ;
615
+ expect ( out ) . toBe ( 8 ) ;
616
+ } ) ;
617
+
618
+ it ( 'should work with mixed types' , function ( ) {
619
+ out = coerce ( { a : true } , { } , attrs , 'a' ) ;
620
+ expect ( out ) . toBe ( true ) ;
621
+
622
+ out = coerce ( { a : 'e' } , { } , attrs , 'a' ) ;
623
+ expect ( out ) . toBe ( 'e' ) ;
624
+
625
+ out = coerce ( { a : 2 } , { } , attrs , 'a' ) ;
626
+ expect ( out ) . toBe ( 2 ) ;
627
+ } ) ;
628
+ } ) ;
591
629
} ) ;
592
630
593
631
describe ( 'coerceFont' , function ( ) {
0 commit comments