fix null key

This commit is contained in:
Alexander Wang 2022-12-22 19:29:13 -08:00
parent 5cd28e14ad
commit 949df0342d
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 113 additions and 5 deletions

View file

@ -1650,6 +1650,16 @@ choo: {
}
},
},
{
name: "null",
text: `null
`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "null", g.Objects[0].ID)
tassert.Equal(t, "null", g.Objects[0].IDVal)
},
},
}
for _, tc := range testCases {

View file

@ -47,10 +47,6 @@ func escapeUnquotedValue(s string, inKey bool) string {
return `""`
}
if strings.EqualFold(s, "null") {
return "\\null"
}
var b strings.Builder
for i, r := range s {
switch r {

2
go.mod generated
View file

@ -6,6 +6,7 @@ require (
cdr.dev/slog v1.4.2-0.20221206192828-e4803b10ae17
github.com/PuerkitoBio/goquery v1.8.0
github.com/alecthomas/chroma v0.10.0
github.com/davecgh/go-spew v1.1.1
github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86
github.com/fsnotify/fsnotify v1.6.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
@ -28,7 +29,6 @@ require (
cloud.google.com/go/compute v1.7.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gin-gonic/gin v1.7.7 // indirect

102
testdata/d2compiler/TestCompile/null.exp.json generated vendored Normal file
View file

@ -0,0 +1,102 @@
{
"graph": {
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-1:0:5",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-0:4:4",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-0:4:4",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-0:4:4",
"value": [
{
"string": "null",
"raw_string": "null"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "null",
"id_val": "null",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-0:4:4",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/null.d2,0:0:0-0:4:4",
"value": [
{
"string": "null",
"raw_string": "null"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "null"
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": null
}