@@ -17,8 +17,11 @@ func TestRunStdoutJqQuery(t *testing.T) {
1717 wantError bool
1818 }{
1919 {
20- name : "queries json with interpolated query" ,
21- stdout : `{"users":[{"name":"Lane"},{"name":"Theo"}]}` ,
20+ name : "queries json with interpolated query" ,
21+ stdout : `{
22+ // Users to query
23+ "users": [/* users */ {"name":"Lane"},{"name":"Theo",},],
24+ }` ,
2225 test : api.StdoutJqTest {
2326 InputMode : "json" ,
2427 Query : `.users[] | select(.name == "${name}") | .name` ,
@@ -29,6 +32,24 @@ func TestRunStdoutJqQuery(t *testing.T) {
2932 Results : []string {`"Theo"` },
3033 },
3134 },
35+ {
36+ name : "default mode accepts comments and trailing commas" ,
37+ stdout : `{"name": /* user */ "Boots",} // final comment without newline` ,
38+ test : api.StdoutJqTest {Query : `.name` },
39+ want : api.CLICommandJqOutput {
40+ Query : `.name` ,
41+ Results : []string {`"Boots"` },
42+ },
43+ },
44+ {
45+ name : "preserves large integers" ,
46+ stdout : `{"id":9007199254740993,}` ,
47+ test : api.StdoutJqTest {InputMode : "json" , Query : `.id` },
48+ want : api.CLICommandJqOutput {
49+ Query : `.id` ,
50+ Results : []string {`9007199254740993` },
51+ },
52+ },
3253 {
3354 name : "queries jsonl as array" ,
3455 stdout : "{\" id\" :1}\n {\" id\" :2}\n " ,
@@ -43,7 +64,7 @@ func TestRunStdoutJqQuery(t *testing.T) {
4364 },
4465 {
4566 name : "returns parse error" ,
46- stdout : `{not json} ` ,
67+ stdout : `{"name":"Boots"} /* unterminated ` ,
4768 test : api.StdoutJqTest {
4869 InputMode : "json" ,
4970 Query : `.name` ,
@@ -77,6 +98,9 @@ func TestRunStdoutJqQuery(t *testing.T) {
7798 if got .Error == "" {
7899 t .Fatal ("expected an error" )
79100 }
101+ if len (got .Results ) != 0 {
102+ t .Fatalf ("expected no results on error, got %v" , got .Results )
103+ }
80104 return
81105 }
82106 if ! reflect .DeepEqual (got , tt .want ) {
@@ -91,9 +115,6 @@ func TestParseJqInputRejectsMultipleJSONValuesInJSONMode(t *testing.T) {
91115 if err == nil {
92116 t .Fatal ("expected error for multiple JSON values in json mode" )
93117 }
94- if err .Error () != "expected a single JSON value" {
95- t .Fatalf ("expected single-value error, got %q" , err .Error ())
96- }
97118}
98119
99120func TestValFromJqPath (t * testing.T ) {
0 commit comments