22// Use of this source code is governed by a MIT style
33// license that can be found in the LICENSE file.
44
5- package x
5+ package errors
66
77import (
8+ "io"
89 "os"
910 "testing"
1011)
@@ -24,18 +25,22 @@ func (te *testError) Error() string {
2425// go test -v -cover -count=1 -test.cpu=1 -run=^TestIs$
2526func TestIs (t * testing.T ) {
2627 testErr := & testError {reason : "test error" }
27- wrapErr := Wrap (testErr , - 1000 , "wrap test error" )
28+ wrapErr := Wrap (- 1000 , "wrap test error" ). With ( testErr )
2829
2930 testCases := []struct {
3031 err error
3132 cause error
3233 }{
3334 {
34- err : Wrap (testErr , 1000 , "wow" ),
35+ err : io .EOF ,
36+ cause : io .EOF ,
37+ },
38+ {
39+ err : Wrap (1000 , "wow" ).With (testErr ),
3540 cause : testErr ,
3641 },
3742 {
38- err : Wrap (wrapErr , 1000 , "wow too" ),
43+ err : Wrap (1000 , "wow too" ). With ( wrapErr ),
3944 cause : testErr ,
4045 },
4146 }
@@ -50,7 +55,7 @@ func TestIs(t *testing.T) {
5055// go test -v -cover -count=1 -test.cpu=1 -run=^TestAs$
5156func TestAs (t * testing.T ) {
5257 testErr := & testError {reason : "test error" }
53- wrapErr := Wrap (testErr , - 1000 , "wrap test error" )
58+ wrapErr := Wrap (- 1000 , "wrap test error" ). With ( testErr )
5459
5560 targetTestErr := & testError {}
5661 targetTestErr2 := & testError {}
@@ -63,19 +68,19 @@ func TestAs(t *testing.T) {
6368 want any
6469 }{
6570 {
66- err : Wrap (testErr , 1000 , "wow" ),
71+ err : Wrap (1000 , "wow" ). With ( testErr ),
6772 target : & targetTestErr ,
6873 ok : true ,
6974 want : & testErr ,
7075 },
7176 {
72- err : Wrap (wrapErr , 1000 , "wow too" ),
77+ err : Wrap (1000 , "wow too" ). With ( wrapErr ),
7378 target : & targetTestErr2 ,
7479 ok : true ,
7580 want : & testErr ,
7681 },
7782 {
78- err : New (1000 , "no" ),
83+ err : Wrap (1000 , "no" ),
7984 target : & targetPathErr ,
8085 ok : false ,
8186 want : nil ,
@@ -93,7 +98,7 @@ func TestAs(t *testing.T) {
9398// go test -v -cover -count=1 -test.cpu=1 -run=^TestUnwrap$
9499func TestUnwrap (t * testing.T ) {
95100 testErr := & testError {reason : "test error" }
96- wrapErr := Wrap (testErr , - 1000 , "wrap test error" )
101+ wrapErr := Wrap (- 1000 , "wrap test error" ). With ( testErr )
97102
98103 testCases := []struct {
99104 err error
@@ -104,11 +109,11 @@ func TestUnwrap(t *testing.T) {
104109 cause : nil ,
105110 },
106111 {
107- err : Wrap (testErr , 1000 , "wow" ),
112+ err : Wrap (1000 , "wow" ). With ( testErr ),
108113 cause : testErr ,
109114 },
110115 {
111- err : Wrap (wrapErr , 1000 , "wow too" ),
116+ err : Wrap (1000 , "wow too" ). With ( wrapErr ),
112117 cause : wrapErr ,
113118 },
114119 }
0 commit comments