Ejemplo n.º 1
0
func init() {
	// Pre-create thre jv_string objects that we will use over and over again.
	jvStringName = jq.JvFromString("name")
	jvStringValue = jq.JvFromString("value")
	jvStringOut = jq.JvFromString("out")
	jvStringUnderscore = jq.JvFromString("_")
	jvStringDunderscore = jq.JvFromString("__")
}
Ejemplo n.º 2
0
func TestJvDump(t *testing.T) {
	is := is.New(t)

	jv := jq.JvFromString("test")
	defer jv.Free()

	dump := jv.Copy().Dump(jq.JvPrintNone)

	is.Equal(`"test"`, dump)
	dump = jv.Copy().Dump(jq.JvPrintColour)

	is.Equal([]byte("\x1b[0;32m"+`"test"`+"\x1b[0m"), []byte(dump))
}
Ejemplo n.º 3
0
func TestJvInvalidWithMessage_string(t *testing.T) {
	is := is.New(t)

	jv := jq.JvInvalidWithMessage(jq.JvFromString("Error message 1"))

	is.False(jv.IsValid())

	msg := jv.Copy().GetInvalidMessage()
	is.Equal(msg.Kind(), jq.JV_KIND_STRING)
	msg.Free()

	str, ok := jv.GetInvalidMessageAsString()
	is.True(ok)
	is.Equal("Error message 1", str)
}
Ejemplo n.º 4
0
func TestJvString(t *testing.T) {
	is := is.New(t)

	jv := jq.JvFromString("test")
	defer jv.Free()

	str, err := jv.String()

	is.Equal(str, "test")
	is.NoErr(err)

	i := jv.ToGoVal()

	is.Equal(i, "test")
}
Ejemplo n.º 5
0
func TestJvKind(t *testing.T) {
	is := is.New(t)

	cases := []struct {
		*jq.Jv
		jq.JvKind
		string
	}{
		{jq.JvNull(), jq.JV_KIND_NULL, "null"},
		{jq.JvFromString("a"), jq.JV_KIND_STRING, "string"},
	}

	for _, c := range cases {
		defer c.Free()
		is.Equal(c.Kind(), c.JvKind)
		is.Equal(c.Kind().String(), c.string)
	}
}