This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/compiler/compiler_test.go
Andrea Luzzardi af776b8abe cleanup: move packages to top level, change vanity URL
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
2021-05-25 16:54:00 -07:00

36 lines
976 B
Go

package compiler
import (
"testing"
"github.com/stretchr/testify/require"
)
// Test that a non-existing field is detected correctly
func TestFieldNotExist(t *testing.T) {
c := New()
root, err := c.Compile("test.cue", `foo: "bar"`)
require.NoError(t, err)
require.True(t, root.Lookup("foo").Exists())
require.False(t, root.Lookup("bar").Exists())
}
// Test that a non-existing definition is detected correctly
func TestDefNotExist(t *testing.T) {
c := New()
root, err := c.Compile("test.cue", `foo: #bla: "bar"`)
require.NoError(t, err)
require.True(t, root.Lookup("foo.#bla").Exists())
require.False(t, root.Lookup("foo.#nope").Exists())
}
func TestJSON(t *testing.T) {
c := New()
v, err := c.Compile("", `foo: hello: "world"`)
require.NoError(t, err)
require.Equal(t, `{"foo":{"hello":"world"}}`, string(v.JSON()))
// Reproduce a bug where Value.Lookup().JSON() ignores Lookup()
require.Equal(t, `{"hello":"world"}`, string(v.Lookup("foo").JSON()))
}