-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package teq | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
func field(v reflect.Value, idx int) reflect.Value { | ||
f1 := v.Field(idx) | ||
if f1.CanAddr() { | ||
return f1 | ||
} | ||
vc := reflect.New(v.Type()).Elem() | ||
vc.Set(v) | ||
rf := vc.Field(idx) | ||
return reflect.NewAt(rf.Type(), rf.Addr().UnsafePointer()).Elem() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package teq_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/seiyab/teq" | ||
) | ||
|
||
func TestEqual_Customized(t *testing.T) { | ||
t.Run("time.Time", func(t *testing.T) { | ||
defaultTeq := teq.New() | ||
customizedTeq := teq.New() | ||
customizedTeq.AddTransform(utc) | ||
|
||
secondsEastOfUTC := int((8 * time.Hour).Seconds()) | ||
beijing := time.FixedZone("Beijing Time", secondsEastOfUTC) | ||
d1 := time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC) | ||
d2 := time.Date(2000, 2, 1, 20, 30, 0, 0, beijing) | ||
|
||
defaultTeq.NotEqual(t, d1, d2) | ||
customizedTeq.Equal(t, d1, d2) | ||
if reflect.DeepEqual(d1, d2) { | ||
t.Error("expected d1 != d2, got d1 == d2 with reflect.DeepEqual") | ||
} | ||
|
||
type twoDates struct { | ||
d1 time.Time | ||
d2 time.Time | ||
} | ||
dt1 := twoDates{d1, d2} | ||
dt2 := twoDates{d2, d1} | ||
|
||
defaultTeq.NotEqual(t, dt1, dt2) | ||
customizedTeq.Equal(t, dt1, dt2) | ||
|
||
if reflect.DeepEqual(dt1, dt2) { | ||
t.Error("expected dt1 != dt2, got dt1 == dt2 with reflect.DeepEqual") | ||
} | ||
|
||
t.Skip("slice is not supported yet") | ||
ds1 := []time.Time{d1, d1, d2} | ||
ds2 := []time.Time{d2, d1, d1} | ||
defaultTeq.NotEqual(t, ds1, ds2) | ||
customizedTeq.Equal(t, ds1, ds2) | ||
if reflect.DeepEqual(ds1, ds2) { | ||
t.Error("expected ds1 != ds2, got ds1 == ds2 with reflect.DeepEqual") | ||
} | ||
}) | ||
} | ||
|
||
func utc(d time.Time) time.Time { | ||
return d.UTC() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters