2022-11-03 13:54:49 +00:00
|
|
|
package d2graph_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2022-12-01 19:32:57 +00:00
|
|
|
"oss.terrastruct.com/util-go/assert"
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
"oss.terrastruct.com/d2/d2graph"
|
|
|
|
|
"oss.terrastruct.com/d2/d2parser"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestKey(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
key string
|
|
|
|
|
exp string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "simple",
|
|
|
|
|
key: "meow.foo.bar",
|
|
|
|
|
exp: "meow.foo.bar",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "specials_1",
|
|
|
|
|
key: `'null.$$$.---'''.",,,.{}{}-\\-><"`,
|
|
|
|
|
exp: `"null.$$$.---'".",,,.{}{}-\\-><"`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "specials_2",
|
|
|
|
|
key: `"&&####;;".| ;;::** |`,
|
|
|
|
|
exp: `"&&####;;".";;::**"`,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
tc := tc
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
k, err := d2parser.ParseKey(tc.key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2022-12-01 19:32:57 +00:00
|
|
|
assert.String(t, tc.exp, strings.Join(d2graph.Key(k), "."))
|
2022-11-03 13:54:49 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|