cleanup: move packages to top level, change vanity URL

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-05-25 16:53:26 -07:00
parent e13153a284
commit af776b8abe
45 changed files with 74 additions and 74 deletions

35
compiler/compiler_test.go Normal file
View File

@@ -0,0 +1,35 @@
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()))
}