@@ -563,7 +563,7 @@ test("query callback", function() {
563
563
u . query ( function ( data ) {
564
564
return {
565
565
bla : 'blubb'
566
- }
566
+ } ;
567
567
} ) ;
568
568
equal ( u . query ( ) , 'bla=blubb' , "overwrite returned value" ) ;
569
569
} ) ;
@@ -689,6 +689,65 @@ test("duplicateQueryParameters", function() {
689
689
u . addQuery ( 'bar' , 1 ) ;
690
690
equal ( u . toString ( ) , '?bar=1&bar=1&bar=1&bar=1' , "parameters NOT de-duplicated after addQuery()" ) ;
691
691
} ) ;
692
+ test ( "hasQuery" , function ( ) {
693
+ var u = URI ( '?string=bar&list=one&list=two&number=123&null&empty=' ) ;
694
+
695
+ // exists
696
+ equal ( u . hasQuery ( 'string' ) , true , "simple exists check - passing" ) ;
697
+ equal ( u . hasQuery ( 'nono' ) , false , "simple exists check - failing" ) ;
698
+
699
+ // truthy value
700
+ equal ( u . hasQuery ( 'string' , true ) , true , "has truthy value check - passing string" ) ;
701
+ equal ( u . hasQuery ( 'number' , true ) , true , "has truthy value check - passing number" ) ;
702
+ equal ( u . hasQuery ( 'list' , true ) , true , "has truthy value check - passing list" ) ;
703
+ equal ( u . hasQuery ( 'empty' , true ) , false , "has truthy value check - failing empty" ) ;
704
+ equal ( u . hasQuery ( 'null' , true ) , false , "has truthy value check - failing null" ) ;
705
+
706
+ // falsy value
707
+ equal ( u . hasQuery ( 'string' , false ) , false , "has falsy value check - failing string" ) ;
708
+ equal ( u . hasQuery ( 'number' , false ) , false , "has falsy value check - failing number" ) ;
709
+ equal ( u . hasQuery ( 'list' , false ) , false , "has falsy value check - failing list" ) ;
710
+ equal ( u . hasQuery ( 'empty' , false ) , true , "has falsy value check - passing empty" ) ;
711
+ equal ( u . hasQuery ( 'null' , false ) , true , "has falsy value check - passing null" ) ;
712
+
713
+ // match value
714
+ equal ( u . hasQuery ( 'string' , "bar" ) , true , "value check - passing string" ) ;
715
+ equal ( u . hasQuery ( 'number' , 123 ) , true , "value check - passing number" ) ;
716
+ equal ( u . hasQuery ( 'number' , "123" ) , true , "value check - passing number as string" ) ;
717
+ equal ( u . hasQuery ( 'list' , "one" ) , false , "value check - failing list" ) ;
718
+ equal ( u . hasQuery ( 'empty' , "" ) , true , "value check - passing empty" ) ;
719
+ equal ( u . hasQuery ( 'null' , "" ) , false , "value check - failing null" ) ;
720
+
721
+ // matching RegExp
722
+ equal ( u . hasQuery ( 'string' , / a r $ / ) , true , "RegExp check - passing string" ) ;
723
+ equal ( u . hasQuery ( 'number' , / 2 / ) , true , "RegExp check - passing number" ) ;
724
+ equal ( u . hasQuery ( 'string' , / n o n o / ) , false , "RegExp check - failing string" ) ;
725
+ equal ( u . hasQuery ( 'number' , / 9 9 9 / ) , false , "RegExp check - failing number" ) ;
726
+
727
+ // matching array
728
+ equal ( u . hasQuery ( 'string' , [ 'one' ] ) , false , "array check - failing string" ) ;
729
+ equal ( u . hasQuery ( 'list' , [ 'one' ] ) , false , "array check - failing incomplete list" ) ;
730
+ equal ( u . hasQuery ( 'list' , [ 'one' , 'two' ] ) , true , "array check - passing list" ) ;
731
+ equal ( u . hasQuery ( 'list' , [ 'two' , 'one' ] ) , true , "array check - passing unsorted list" ) ;
732
+
733
+ // matching part of array
734
+ equal ( u . hasQuery ( 'string' , [ 'one' ] , true ) , false , "in array check - failing string" ) ;
735
+ equal ( u . hasQuery ( 'list' , [ 'one' ] , true ) , true , "in array check - passing incomplete list" ) ;
736
+ equal ( u . hasQuery ( 'list' , [ 'one' , 'two' ] , true ) , true , "in array check - passing list" ) ;
737
+ equal ( u . hasQuery ( 'list' , [ 'two' , 'one' ] , true ) , true , "in array check - passing unsorted list" ) ;
738
+ equal ( u . hasQuery ( 'list' , [ / n e $ / ] , true ) , true , "in array check - passing RegExp" ) ;
739
+
740
+ // comparison function
741
+ equal ( u . hasQuery ( 'string' , function ( value , name , data ) {
742
+ equal ( value , "bar" , "Function check - param value" ) ;
743
+ equal ( name , "string" , "Function check - param name" ) ;
744
+ equal ( typeof data , "object" , "Function check - param data" ) ;
745
+ return true ;
746
+ } ) , true , "Function check - passing true" ) ;
747
+ equal ( u . hasQuery ( 'string' , function ( value , name , data ) {
748
+ return false ;
749
+ } ) , false , "Function check - passing false" ) ;
750
+ } ) ;
692
751
693
752
module ( "normalizing" ) ;
694
753
test ( "normalize" , function ( ) {
0 commit comments