|
|
@ -10,21 +10,36 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestNaturalSortLess(t *testing.T) { |
|
|
|
func TestNaturalSortLess(t *testing.T) { |
|
|
|
test := func(s1, s2 string, less bool) { |
|
|
|
testLess := func(s1, s2 string) { |
|
|
|
assert.Equal(t, less, NaturalSortLess(s1, s2), "s1=%q, s2=%q", s1, s2) |
|
|
|
assert.True(t, NaturalSortLess(s1, s2), "s1<s2 should be true: s1=%q, s2=%q", s1, s2) |
|
|
|
|
|
|
|
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2) |
|
|
|
} |
|
|
|
} |
|
|
|
test("v1.20.0", "v1.2.0", false) |
|
|
|
testEqual := func(s1, s2 string) { |
|
|
|
test("v1.20.0", "v1.29.0", true) |
|
|
|
assert.False(t, NaturalSortLess(s1, s2), "s1<s2 should be false: s1=%q, s2=%q", s1, s2) |
|
|
|
test("v1.20.0", "v1.20.0", false) |
|
|
|
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2) |
|
|
|
test("abc", "bcd", true) |
|
|
|
} |
|
|
|
test("a-1-a", "a-1-b", true) |
|
|
|
|
|
|
|
test("2", "12", true) |
|
|
|
testEqual("", "") |
|
|
|
test("a", "ab", true) |
|
|
|
testLess("", "a") |
|
|
|
|
|
|
|
testLess("", "1") |
|
|
|
test("A", "b", true) |
|
|
|
|
|
|
|
test("a", "B", true) |
|
|
|
testLess("v1.2", "v1.2.0") |
|
|
|
|
|
|
|
testLess("v1.2.0", "v1.10.0") |
|
|
|
test("cafe", "café", true) |
|
|
|
testLess("v1.20.0", "v1.29.0") |
|
|
|
test("café", "cafe", false) |
|
|
|
testEqual("v1.20.0", "v1.20.0") |
|
|
|
test("caff", "café", false) |
|
|
|
|
|
|
|
|
|
|
|
testLess("a", "A") |
|
|
|
|
|
|
|
testLess("a", "B") |
|
|
|
|
|
|
|
testLess("A", "b") |
|
|
|
|
|
|
|
testLess("A", "ab") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testLess("abc", "bcd") |
|
|
|
|
|
|
|
testLess("a-1-a", "a-1-b") |
|
|
|
|
|
|
|
testLess("2", "12") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testLess("cafe", "café") |
|
|
|
|
|
|
|
testLess("café", "caff") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testLess("A-2", "A-11") |
|
|
|
|
|
|
|
testLess("0.txt", "1.txt") |
|
|
|
} |
|
|
|
} |
|
|
|