-
Notifications
You must be signed in to change notification settings - Fork 528
/
Copy pathd2lib_test.go
89 lines (82 loc) · 1.35 KB
/
d2lib_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package d2lib_test
import (
"context"
"testing"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
"oss.terrastruct.com/d2/d2lib"
"oss.terrastruct.com/d2/lib/textmeasure"
"oss.terrastruct.com/util-go/assert"
)
func TestValidateTopLeft(t *testing.T) {
assertCompile(t, `
container: {
a: {
top: 100
left: 100
}
b: {
top: 100
left: 100
}
}
`,
`4:3: invalid top/left overlapping with "b"
8:3: invalid top/left overlapping with "a"`,
)
assertCompile(t, `
container: {
a: {
top: 100
left: 100
}
b: {
top: 100
left: 200
}
}
`,
``,
)
assertCompile(t, `
a: {
top: 100
left: 100
}
b: {
top: 101
left: 101
}
`,
`3:2: invalid top/left overlapping with "b"
7:2: invalid top/left overlapping with "a"`,
)
assertCompile(t, `
a: {
top: 100
left: 100
}
b: {
top: 99
left: 99
}
`,
`3:2: invalid top/left overlapping with "b"
7:2: invalid top/left overlapping with "a"`,
)
}
func assertCompile(t *testing.T, text string, expErr string) {
ruler, _ := textmeasure.NewRuler()
defaultLayout := func(ctx context.Context, g *d2graph.Graph) error {
return d2dagrelayout.Layout(ctx, g, nil)
}
_, _, err := d2lib.Compile(context.Background(), text, &d2lib.CompileOptions{
Layout: defaultLayout,
Ruler: ruler,
})
if expErr != "" {
assert.ErrorString(t, err, expErr)
} else {
assert.Success(t, err)
}
}