Skip to content

Commit 33cf701

Browse files
committed
feat: isOrderable support the alias of the primitive orderable types.
1 parent d6d675d commit 33cf701

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

order.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ func isOrderable(v any) bool {
287287
string: // string
288288
return true
289289
default:
290-
return false
290+
kind := reflect.TypeOf(v).Kind()
291+
return (kind >= reflect.Int && kind <= reflect.Int64) ||
292+
(kind >= reflect.Uint && kind <= reflect.Uintptr) ||
293+
(kind >= reflect.Float32 && kind <= reflect.Float64) ||
294+
kind == reflect.String
291295
}
292296
}

order_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package assert
33
import (
44
"reflect"
55
"testing"
6+
"time"
67
)
78

89
func TestGt(t *testing.T) {
@@ -25,6 +26,9 @@ func TestGt(t *testing.T) {
2526
testGt(a, mockA, float32(2.0), 1.0, true)
2627
testGt(a, mockA, "ABC", "BCD", false)
2728
testGt(a, mockA, "ABC", "AAA", true)
29+
testGt(a, mockA, time.Second, time.Millisecond, true)
30+
testGt(a, mockA, time.Second, time.Second, false)
31+
testGt(a, mockA, time.Second, time.Minute, false)
2832
}
2933

3034
func testGt(a, mockA *Assertion, v1, v2 any, isGt bool) {
@@ -68,6 +72,9 @@ func TestGte(t *testing.T) {
6872
testGte(a, mockA, "ABC", "BCD", false)
6973
testGte(a, mockA, "ABC", "AAA", true)
7074
testGte(a, mockA, "ABC", "ABC", true)
75+
testGte(a, mockA, time.Second, time.Millisecond, true)
76+
testGte(a, mockA, time.Second, time.Second, true)
77+
testGte(a, mockA, time.Second, time.Minute, false)
7178
}
7279

7380
func testGte(a, mockA *Assertion, v1, v2 any, isGte bool) {
@@ -108,6 +115,9 @@ func TestLt(t *testing.T) {
108115
testLt(a, mockA, float32(1.0), 2.0, true)
109116
testLt(a, mockA, "BCD", "ABC", false)
110117
testLt(a, mockA, "AAA", "ABC", true)
118+
testLt(a, mockA, time.Millisecond, time.Second, true)
119+
testLt(a, mockA, time.Second, time.Second, false)
120+
testLt(a, mockA, time.Minute, time.Second, false)
111121
}
112122

113123
func testLt(a, mockA *Assertion, v1, v2 any, isLt bool) {
@@ -151,6 +161,9 @@ func TestLte(t *testing.T) {
151161
testLte(a, mockA, "BCD", "ABC", false)
152162
testLte(a, mockA, "AAA", "ABC", true)
153163
testLte(a, mockA, "ABC", "ABC", true)
164+
testLte(a, mockA, time.Millisecond, time.Second, true)
165+
testLte(a, mockA, time.Second, time.Second, true)
166+
testLte(a, mockA, time.Minute, time.Second, false)
154167
}
155168

156169
func testLte(a, mockA *Assertion, v1, v2 any, isLte bool) {

0 commit comments

Comments
 (0)