@@ -769,6 +769,24 @@ func TestJSONQ_Only_with_distinct(t *testing.T) {
769769 assertJSON (t , out , expected )
770770}
771771
772+ func TestJSONQ_OnlyR (t * testing.T ) {
773+ jq := New ().JSONString (jsonStr ).
774+ From ("vendor.items" )
775+ result , err := jq .OnlyR ("name" , "price" )
776+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
777+ t .Error ("failed to match Result type" )
778+ }
779+ }
780+
781+ func TestJSONQ_OnlyR_error (t * testing.T ) {
782+ jq := New ().JSONString (jsonStr ).
783+ From ("invalid_path" )
784+ result , err := jq .OnlyR ("name" , "price" )
785+ if result != nil && err == nil {
786+ t .Error ("failed to catch error" )
787+ }
788+ }
789+
772790func TestJSONQ_First_expecting_result (t * testing.T ) {
773791 jq := New ().JSONString (jsonStr ).
774792 From ("vendor.items" )
@@ -794,6 +812,24 @@ func TestJSONQ_First_distinct_expecting_result(t *testing.T) {
794812 assertJSON (t , out , expected , "First with distinct & where expecting result result" )
795813}
796814
815+ func TestJSONQ_FirstR (t * testing.T ) {
816+ jq := New ().JSONString (jsonStr ).
817+ From ("vendor.items" ).Distinct ("price" ).Where ("price" , "=" , 850 )
818+ result , err := jq .FirstR ()
819+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
820+ t .Error ("failed to match Result type" )
821+ }
822+ }
823+
824+ func TestJSONQ_FirstR_error (t * testing.T ) {
825+ jq := New ().JSONString (jsonStr ).
826+ From ("invalid" ).Distinct ("price" ).Where ("price" , "=" , 850 )
827+ result , err := jq .FirstR ()
828+ if result != nil && err == nil {
829+ t .Error ("failed to catch error" )
830+ }
831+ }
832+
797833func TestJSONQ_Last_expecting_result (t * testing.T ) {
798834 jq := New ().JSONString (jsonStr ).
799835 From ("vendor.items" )
@@ -819,6 +855,24 @@ func TestJSONQ_Last_distinct_expecting_result(t *testing.T) {
819855 assertJSON (t , out , expected , "Last with distinct & where expecting result result" )
820856}
821857
858+ func TestJSONQ_LastR (t * testing.T ) {
859+ jq := New ().JSONString (jsonStr ).
860+ From ("vendor.items" ).Distinct ("price" ).Where ("price" , "=" , 850 )
861+ result , err := jq .LastR ()
862+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
863+ t .Error ("failed to match Result type" )
864+ }
865+ }
866+
867+ func TestJSONQ_LastR_error (t * testing.T ) {
868+ jq := New ().JSONString (jsonStr ).
869+ From ("invalid_path" ).Distinct ("price" ).Where ("price" , "=" , 850 )
870+ result , err := jq .LastR ()
871+ if result != nil && err == nil {
872+ t .Error ("failed to catch error" )
873+ }
874+ }
875+
822876func TestJSONQ_Nth_expecting_result (t * testing.T ) {
823877 jq := New ().JSONString (jsonStr ).
824878 From ("vendor.items" )
@@ -894,6 +948,24 @@ func TestJSONQ_Nth_distinct_expecting_result(t *testing.T) {
894948 assertJSON (t , out , expected , "Last with distinct & where expecting result result" )
895949}
896950
951+ func TestJSONQ_NthR (t * testing.T ) {
952+ jq := New ().JSONString (jsonStr ).
953+ From ("vendor.items" ).Distinct ("price" ).Where ("price" , "=" , 850 )
954+ result , err := jq .NthR (1 )
955+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
956+ t .Error ("failed to match Result type" )
957+ }
958+ }
959+
960+ func TestJSONQ_NthR_error (t * testing.T ) {
961+ jq := New ().JSONString (jsonStr ).
962+ From ("invalid_path" ).Distinct ("price" ).Where ("price" , "=" , 850 )
963+ result , err := jq .NthR (1 )
964+ if result != nil && err == nil {
965+ t .Error ("failed to catch error" )
966+ }
967+ }
968+
897969func TestJSONQ_Find_simple_property (t * testing.T ) {
898970 jq := New ().JSONString (jsonStr )
899971 out := jq .Find ("name" )
@@ -908,6 +980,22 @@ func TestJSONQ_Find_nested_property(t *testing.T) {
908980 assertJSON (t , out , expected , "Find expecting a nested object" )
909981}
910982
983+ func TestJSONQ_FindR (t * testing.T ) {
984+ jq := New ().JSONString (jsonStr )
985+ result , err := jq .FindR ("vendor.items.[0]" )
986+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
987+ t .Error ("failed to match Result type" )
988+ }
989+ }
990+
991+ func TestJSONQ_FindR_error (t * testing.T ) {
992+ jq := New ().JSONString (jsonStr )
993+ result , err := jq .FindR ("invalid_path" )
994+ if result != nil && err == nil {
995+ t .Error ("failed to catch error" )
996+ }
997+ }
998+
911999func TestJSONQ_Pluck_expecting_list_of_float64 (t * testing.T ) {
9121000 jq := New ().JSONString (jsonStr ).
9131001 From ("vendor.items" )
@@ -932,6 +1020,22 @@ func TestJSONQ_Pluck_expecting_with_distinct(t *testing.T) {
9321020 assertJSON (t , out , expected , "Expecting distinct price with limit 3" )
9331021}
9341022
1023+ func TestJSONQ_PluckR (t * testing.T ) {
1024+ jq := New ().JSONString (jsonStr ).From ("vendor.items" )
1025+ result , err := jq .PluckR ("price" )
1026+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
1027+ t .Error ("failed to match Result type" )
1028+ }
1029+ }
1030+
1031+ func TestJSONQ_PluckR_error (t * testing.T ) {
1032+ jq := New ().JSONString (jsonStr ).From ("invalid_path" )
1033+ result , err := jq .PluckR ("price" )
1034+ if result != nil && err == nil {
1035+ t .Error ("failed to catch error" )
1036+ }
1037+ }
1038+
9351039func TestJSONQ_Count_expecting_int_from_list (t * testing.T ) {
9361040 jq := New ().JSONString (jsonStr ).
9371041 From ("vendor.items" )
@@ -1226,6 +1330,24 @@ func TestJSONQ_Get_with_nested_invalid_property_in_Select_method_expecting_error
12261330 assertJSON (t , out , expected , "nested Select method using alias" )
12271331}
12281332
1333+ func TestJSONQ_GetR (t * testing.T ) {
1334+ jq := New ().JSONString (jsonStr ).
1335+ From ("vendor.items" ).Select ("name" )
1336+ result , err := jq .GetR ()
1337+ if reflect .ValueOf (result ).Type ().String () != "*gojsonq.Result" && err != nil {
1338+ t .Error ("failed to match Result type" )
1339+ }
1340+ }
1341+
1342+ func TestJSONQ_GetR_error (t * testing.T ) {
1343+ jq := New ().JSONString (jsonStr ).
1344+ From ("invalid_path" )
1345+ result , err := jq .GetR ()
1346+ if result != nil && err == nil {
1347+ t .Error ("failed to catch error" )
1348+ }
1349+ }
1350+
12291351func TestJSONQ_Offset_method (t * testing.T ) {
12301352 jq := New ().JSONString (jsonStr ).
12311353 From ("vendor.items" ).
0 commit comments