This commit is contained in:
Anmol Sethi 2023-06-04 23:32:14 -07:00
parent 2fcc9ed140
commit 9f0c24f5d7
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
3 changed files with 43 additions and 47 deletions

View file

@ -10,50 +10,50 @@ func testCompileImports(t *testing.T) {
t.Parallel() t.Parallel()
tca := []testCase{ tca := []testCase{
{ {
name: "value", name: "value",
run: func(t testing.TB) { run: func(t testing.TB) {
m, err := compileFS(t, "index.d2", map[string]string{ m, err := compileFS(t, "index.d2", map[string]string{
"index.d2": "x: @x.d2", "index.d2": "x: @x.d2",
"x.d2": `shape: circle "x.d2": `shape: circle
label: meow`, label: meow`,
}) })
assert.Success(t, err) assert.Success(t, err)
assertQuery(t, m, 3, 0, nil, "") assertQuery(t, m, 3, 0, nil, "")
assertQuery(t, m, 2, 0, nil, "x") assertQuery(t, m, 2, 0, nil, "x")
assertQuery(t, m, 0, 0, "circle", "x.shape") assertQuery(t, m, 0, 0, "circle", "x.shape")
assertQuery(t, m, 0, 0, "meow", "x.label") assertQuery(t, m, 0, 0, "meow", "x.label")
}, },
}, },
{ {
name: "nested", name: "nested",
run: func(t testing.TB) { run: func(t testing.TB) {
m, err := compileFS(t, "index.d2", map[string]string{ m, err := compileFS(t, "index.d2", map[string]string{
"index.d2": "x: @x.y", "index.d2": "x: @x.y",
"x.d2": `y: { "x.d2": `y: {
shape: circle shape: circle
label: meow label: meow
}`, }`,
}) })
assert.Success(t, err) assert.Success(t, err)
assertQuery(t, m, 3, 0, nil, "") assertQuery(t, m, 3, 0, nil, "")
assertQuery(t, m, 2, 0, nil, "x") assertQuery(t, m, 2, 0, nil, "x")
assertQuery(t, m, 0, 0, "circle", "x.shape") assertQuery(t, m, 0, 0, "circle", "x.shape")
assertQuery(t, m, 0, 0, "meow", "x.label") assertQuery(t, m, 0, 0, "meow", "x.label")
}, },
}, },
{ {
name: "spread", name: "spread",
run: func(t testing.TB) { run: func(t testing.TB) {
m, err := compileFS(t, "index.d2", map[string]string{ m, err := compileFS(t, "index.d2", map[string]string{
"index.d2": "...@x.d2", "index.d2": "...@x.d2",
"x.d2": "x: wowa", "x.d2": "x: wowa",
}) })
assert.Success(t, err) assert.Success(t, err)
assertQuery(t, m, 1, 0, nil, "") assertQuery(t, m, 1, 0, nil, "")
assertQuery(t, m, 0, 0, "wowa", "x") assertQuery(t, m, 0, 0, "wowa", "x")
}, },
}, },
} }
runa(t, tca) runa(t, tca)

View file

@ -59,7 +59,7 @@ func Parse(path string, r io.RuneReader, opts *ParseOptions) (*d2ast.Map, error)
func ParseKey(key string) (*d2ast.KeyPath, error) { func ParseKey(key string) (*d2ast.KeyPath, error) {
p := &parser{ p := &parser{
reader: strings.NewReader(key), reader: strings.NewReader(key),
err: &ParseError{}, err: &ParseError{},
} }
k := p.parseKey() k := p.parseKey()
@ -75,7 +75,7 @@ func ParseKey(key string) (*d2ast.KeyPath, error) {
func ParseMapKey(mapKey string) (*d2ast.Key, error) { func ParseMapKey(mapKey string) (*d2ast.Key, error) {
p := &parser{ p := &parser{
reader: strings.NewReader(mapKey), reader: strings.NewReader(mapKey),
err: &ParseError{}, err: &ParseError{},
} }
mk := p.parseMapKey() mk := p.parseMapKey()
@ -91,7 +91,7 @@ func ParseMapKey(mapKey string) (*d2ast.Key, error) {
func ParseValue(value string) (d2ast.Value, error) { func ParseValue(value string) (d2ast.Value, error) {
p := &parser{ p := &parser{
reader: strings.NewReader(value), reader: strings.NewReader(value),
err: &ParseError{}, err: &ParseError{},
} }
v := p.parseValue() v := p.parseValue()

4
go.sum generated
View file

@ -329,10 +329,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
oss.terrastruct.com/util-go v0.0.0-20230320053557-dcb5aac7d972 h1:HS7fg2GzGsqRLApsoh7ztaLMvXzxSln/Hfz4wy4tIDA=
oss.terrastruct.com/util-go v0.0.0-20230320053557-dcb5aac7d972/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4=
oss.terrastruct.com/util-go v0.0.0-20230604220107-5ffc52e2e534 h1:6RWrCAg2bzrmGCXd063nkqaHYJHd3KiN3lVfchm4o5I=
oss.terrastruct.com/util-go v0.0.0-20230604220107-5ffc52e2e534/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4=
oss.terrastruct.com/util-go v0.0.0-20230604222829-11c3c60fec14 h1:oy5vtt6O2qYxeSpqWhyevrdUenFfuhphixozUlpL6qY= oss.terrastruct.com/util-go v0.0.0-20230604222829-11c3c60fec14 h1:oy5vtt6O2qYxeSpqWhyevrdUenFfuhphixozUlpL6qY=
oss.terrastruct.com/util-go v0.0.0-20230604222829-11c3c60fec14/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4= oss.terrastruct.com/util-go v0.0.0-20230604222829-11c3c60fec14/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4=
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4= rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=