-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjoin_test.go
More file actions
48 lines (41 loc) · 775 Bytes
/
Copy pathjoin_test.go
File metadata and controls
48 lines (41 loc) · 775 Bytes
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
// Copyright © 2023 Hedzr Yeh.
package errors_test
import (
"errors"
"fmt"
"testing"
v3 "gopkg.in/hedzr/errors.v3"
)
func TestJoinErrors(t *testing.T) {
err1 := errors.New("err1")
err2 := errors.New("err2")
err := v3.Join(err1, err2)
fmt.Printf("%T, %v\n", err, err)
if v3.Is(err, err1) {
t.Log("err is err1")
} else {
t.Fatal("expecting err is err1")
}
if v3.Is(err, err2) {
t.Log("err is err2")
} else {
t.Fatal("expecting err is err2")
}
}
type DivisionError struct {
IntA int
IntB int
Msg string
}
func (e *DivisionError) Error() string {
return e.Msg
}
func Divide(a, b int) (int, error) {
if b == 0 {
return 0, &DivisionError{
Msg: fmt.Sprintf("cannot divide '%d' by zero", a),
IntA: a, IntB: b,
}
}
return a / b, nil
}