Skip to content

Commit 5df7fe4

Browse files
committed
fix newRel
1 parent 6298404 commit 5df7fe4

File tree

8 files changed

+1801
-1795
lines changed

8 files changed

+1801
-1795
lines changed

errors_test.go

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
package opc
2-
3-
import (
4-
"testing"
5-
)
6-
7-
func TestError_Code(t *testing.T) {
8-
tests := []struct {
9-
name string
10-
e *Error
11-
want int
12-
}{
13-
{"empty", new(Error), 0},
14-
{"base", newError(1, "base"), 1},
15-
}
16-
for _, tt := range tests {
17-
t.Run(tt.name, func(t *testing.T) {
18-
if got := tt.e.Code(); got != tt.want {
19-
t.Errorf("Error.Code() = %v, want %v", got, tt.want)
20-
}
21-
})
22-
}
23-
}
24-
25-
func TestError_PartName(t *testing.T) {
26-
tests := []struct {
27-
name string
28-
e *Error
29-
want string
30-
}{
31-
{"empty", new(Error), ""},
32-
{"base", &Error{partName: "base"}, "base"},
33-
}
34-
for _, tt := range tests {
35-
t.Run(tt.name, func(t *testing.T) {
36-
if got := tt.e.PartName(); got != tt.want {
37-
t.Errorf("Error.PartName() = %v, want %v", got, tt.want)
38-
}
39-
})
40-
}
41-
}
42-
43-
func TestError_Error(t *testing.T) {
44-
tests := []struct {
45-
name string
46-
e *Error
47-
want string
48-
wantPanic bool
49-
}{
50-
{"base", &Error{101, "/doc.xml", ""}, "opc: /doc.xml: a part name shall not be empty", false},
51-
{"panic", &Error{0, "/doc.xml", ""}, "", true},
52-
}
53-
for _, tt := range tests {
54-
t.Run(tt.name, func(t *testing.T) {
55-
defer func() {
56-
if r := recover(); r != nil {
57-
if !tt.wantPanic {
58-
t.Errorf("Error.Error() want panic")
59-
}
60-
}
61-
}()
62-
if got := tt.e.Error(); got != tt.want {
63-
t.Errorf("Error.Error() = %v, want %v", got, tt.want)
64-
return
65-
}
66-
if tt.wantPanic {
67-
t.Error("Error.Error() want error")
68-
}
69-
})
70-
}
71-
}
72-
73-
func TestError_RelationshipID(t *testing.T) {
74-
tests := []struct {
75-
name string
76-
e *Error
77-
want string
78-
}{
79-
{"empty", new(Error), ""},
80-
{"base", newErrorRelationship(101, "/doc.xml", "21211"), "21211"},
81-
}
82-
for _, tt := range tests {
83-
t.Run(tt.name, func(t *testing.T) {
84-
if got := tt.e.RelationshipID(); got != tt.want {
85-
t.Errorf("Error.RelationshipID() = %v, want %v", got, tt.want)
86-
}
87-
})
88-
}
89-
}
1+
package opc
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestError_Code(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
e *Error
11+
want int
12+
}{
13+
{"empty", new(Error), 0},
14+
{"base", newError(1, "base"), 1},
15+
}
16+
for _, tt := range tests {
17+
t.Run(tt.name, func(t *testing.T) {
18+
if got := tt.e.Code(); got != tt.want {
19+
t.Errorf("Error.Code() = %v, want %v", got, tt.want)
20+
}
21+
})
22+
}
23+
}
24+
25+
func TestError_PartName(t *testing.T) {
26+
tests := []struct {
27+
name string
28+
e *Error
29+
want string
30+
}{
31+
{"empty", new(Error), ""},
32+
{"base", &Error{partName: "base"}, "base"},
33+
}
34+
for _, tt := range tests {
35+
t.Run(tt.name, func(t *testing.T) {
36+
if got := tt.e.PartName(); got != tt.want {
37+
t.Errorf("Error.PartName() = %v, want %v", got, tt.want)
38+
}
39+
})
40+
}
41+
}
42+
43+
func TestError_Error(t *testing.T) {
44+
tests := []struct {
45+
name string
46+
e *Error
47+
want string
48+
wantPanic bool
49+
}{
50+
{"base", &Error{101, "/doc.xml", ""}, "opc: /doc.xml: a part name shall not be empty", false},
51+
{"panic", &Error{0, "/doc.xml", ""}, "", true},
52+
}
53+
for _, tt := range tests {
54+
t.Run(tt.name, func(t *testing.T) {
55+
defer func() {
56+
if r := recover(); r != nil {
57+
if !tt.wantPanic {
58+
t.Errorf("Error.Error() want panic")
59+
}
60+
}
61+
}()
62+
if got := tt.e.Error(); got != tt.want {
63+
t.Errorf("Error.Error() = %v, want %v", got, tt.want)
64+
return
65+
}
66+
if tt.wantPanic {
67+
t.Error("Error.Error() want error")
68+
}
69+
})
70+
}
71+
}
72+
73+
func TestError_RelationshipID(t *testing.T) {
74+
tests := []struct {
75+
name string
76+
e *Error
77+
want string
78+
}{
79+
{"empty", new(Error), ""},
80+
{"base", newErrorRelationship(101, "/doc.xml", "21211"), "21211"},
81+
}
82+
for _, tt := range tests {
83+
t.Run(tt.name, func(t *testing.T) {
84+
if got := tt.e.RelationshipID(); got != tt.want {
85+
t.Errorf("Error.RelationshipID() = %v, want %v", got, tt.want)
86+
}
87+
})
88+
}
89+
}

example_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,3 @@ func ExampleNewWriterFromReader() {
8989
log.Fatal(err)
9090
}
9191
}
92-

0 commit comments

Comments
 (0)