Example #1
0
func TestJvFromJSONString(t *testing.T) {
	is := is.New(t)

	jv, err := jq.JvFromJSONString("[]")
	is.NoErr(err)
	is.OK(jv)
	is.Equal(jv.Kind(), jq.JV_KIND_ARRAY)

	jv, err = jq.JvFromJSONString("not valid")
	is.Err(err)
	is.Nil(jv)
}
Example #2
0
func TestJqSimpleProgram(t *testing.T) {
	state, err := jq.New()

	if err != nil {
		t.Errorf("Error initializing state_state: %v", err)
	}
	defer state.Close()

	input, err := jq.JvFromJSONString("{\"a\": 123}")
	if err != nil {
		t.Error(err)
	}

	cIn, cOut, cErrs := state.Start(".a", jq.JvArray())
	outputs, errs := feedJq(input, cIn, cOut, cErrs)

	if len(errs) > 0 {
		t.Errorf("Expected no errors, but got %#v", errs)
	}

	if l := len(outputs); l != 1 {
		t.Errorf("Got %d outputs (%#v), expected %d", l, outputs, 1)
	} else if val := outputs[0].ToGoVal(); val != 123 {
		t.Errorf("Got %#v, expected %#v", val, 123)
	}
}
Example #3
0
func TestJqRuntimeError(t *testing.T) {
	state, err := jq.New()

	if err != nil {
		t.Errorf("Error initializing state_state: %v", err)
	}
	defer state.Close()

	input, err := jq.JvFromJSONString(`{"a": 123}`)
	if err != nil {
		t.Error(err)
	}

	cIn, cOut, cErrs := state.Start(".[0]", jq.JvArray())
	_, errors := feedJq(input, cIn, cOut, cErrs)

	if l := len(errors); l != 1 {
		t.Errorf("Got %d errors (%#v), expected %d", l, errors, 1)
	}
}