forked from ixmilia/dxf-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables_test.go
128 lines (120 loc) · 3.4 KB
/
tables_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package dxf
import (
"testing"
)
func TestReadLayer(t *testing.T) {
drawing := parseTableItem(t, "LAYER",
NewStringCodePair(2, "layer-name"),
)
assertEqInt(t, 1, len(drawing.Layers))
layer := drawing.Layers[0]
assertEqString(t, "layer-name", layer.Name)
}
func TestWriteLayer(t *testing.T) {
l := *NewLayer()
l.Name = "layer-name"
d := NewDrawing()
d.Layers = append(d.Layers, l)
actual, err := d.CodePairs()
if err != nil {
t.Error(err)
}
assertContainsCodePairs(t, []CodePair{
NewStringCodePair(100, "AcDbSymbolTableRecord"),
NewStringCodePair(100, "AcDbLayerTableRecord"),
NewStringCodePair(2, "layer-name"),
NewShortCodePair(70, 0),
NewShortCodePair(62, 7),
NewStringCodePair(6, "CONTINUOUS"),
}, actual)
}
func TestRoundTripLayer(t *testing.T) {
l := *NewLayer()
l.Name = "layer-name"
d := NewDrawing()
d.Layers = append(d.Layers, l)
r := roundTripDrawing(t, d)
assertEqInt(t, 1, len(r.Layers))
l2 := r.Layers[0]
assertEqString(t, l.Name, l2.Name)
}
func TestReadLayers(t *testing.T) {
drawing := parseFromCodePairs(t,
// section decl
NewStringCodePair(0, "SECTION"),
NewStringCodePair(2, "TABLES"),
// table decl
NewStringCodePair(0, "TABLE"),
NewStringCodePair(2, "LAYER"),
// item
NewStringCodePair(0, "LAYER"),
NewStringCodePair(2, "layer-1"),
// item
NewStringCodePair(0, "LAYER"),
NewStringCodePair(2, "layer-2"),
// end
NewStringCodePair(0, "ENDTAB"),
NewStringCodePair(0, "ENDSEC"),
NewStringCodePair(0, "EOF"),
)
assertEqInt(t, 2, len(drawing.Layers))
assertEqString(t, "layer-1", drawing.Layers[0].Name)
assertEqString(t, "layer-2", drawing.Layers[1].Name)
}
func TestReadTableWithHandle(t *testing.T) {
drawing := parseFromCodePairs(t,
// section decl
NewStringCodePair(0, "SECTION"),
NewStringCodePair(2, "TABLES"),
// table decl
NewStringCodePair(0, "TABLE"),
NewStringCodePair(2, "VPORT"),
NewStringCodePair(5, "ABCD"), // n.b., handle is on the table, not the table item
// item
NewStringCodePair(0, "VPORT"),
NewStringCodePair(2, "vport-name"),
// end
NewStringCodePair(0, "ENDTAB"),
NewStringCodePair(0, "ENDSEC"),
NewStringCodePair(0, "EOF"),
)
assertEqInt(t, 1, len(drawing.ViewPorts))
assertEqString(t, "vport-name", drawing.ViewPorts[0].Name)
}
func TestUnsupportedTable(t *testing.T) {
drawing := parseFromCodePairs(t,
NewStringCodePair(0, "SECTION"),
NewStringCodePair(2, "TABLES"),
NewStringCodePair(0, "TABLE"),
NewStringCodePair(2, "UNSUPPORTED"),
NewStringCodePair(0, "UNSUPPORTED"),
NewStringCodePair(2, "unsupported-name"),
NewStringCodePair(0, "ENDTAB"),
NewStringCodePair(0, "TABLE"),
NewStringCodePair(2, "LAYER"),
NewStringCodePair(0, "LAYER"),
NewStringCodePair(2, "layer-name"),
NewStringCodePair(0, "ENDTAB"),
NewStringCodePair(0, "ENDSEC"),
NewStringCodePair(0, "EOF"),
)
assertEqInt(t, 1, len(drawing.Layers))
assertEqString(t, "layer-name", drawing.Layers[0].Name)
}
func parseTableItem(t *testing.T, tableType string, codePairs ...CodePair) (drawing Drawing) {
allPairs := []CodePair{
NewStringCodePair(0, "SECTION"),
NewStringCodePair(2, "TABLES"),
NewStringCodePair(0, "TABLE"),
NewStringCodePair(2, tableType),
NewStringCodePair(0, tableType),
}
allPairs = append(allPairs, codePairs...)
allPairs = append(allPairs,
NewStringCodePair(0, "ENDTAB"),
NewStringCodePair(0, "ENDSEC"),
NewStringCodePair(0, "EOF"),
)
drawing = parseFromCodePairs(t, allPairs...)
return
}