github.com/karsthammer/dnscontrol@v0.2.8/pkg/natsort/sort_test.go (about) 1 package natsort 2 3 import "testing" 4 5 func TestLess(t *testing.T) { 6 7 tests := []struct { 8 d1, d2 string 9 }{ 10 11 {``, `x`}, 12 {`foo3`, `foo10`}, 13 {`foo2`, `foo40`}, 14 {`ny-dc01.ds`, `ny-dc-vpn`}, 15 {`20161108174726pm._domainkey`, `*`}, 16 {`co-dc01.ds.stackexchange.com`, `co-dc-vpn.stackexchange.com`}, 17 18 // Bug#4: [a1 a#1 a_1 aa] 19 //{`a1`, `a#1`}, 20 {`a#1`, `a_1`}, 21 {`a_1`, `aa`}, 22 23 // Bug#4: [1 #1 _1 a] 24 //{`1`, `#1`}, // Not implemented 25 {`#1`, `_1`}, 26 {`_1`, `a`}, 27 28 // Bug#4: [1 01 2 02 3] 29 {`1`, `01`}, 30 {`2`, `02`}, 31 //{`02`, `3`}, // Not implemented 32 33 // Bug#4: [111111111111111111112 111111111111111111113 1111111111111111111120] 34 {`111111111111111111112`, `111111111111111111113`}, 35 {`111111111111111111113`, `1111111111111111111120`}, 36 } 37 for i, test := range tests { 38 r1 := Less(test.d1, test.d2) 39 if r1 != true { 40 t.Errorf("%va: expected (%v) got (%v): (%v) < (%v)", i, true, r1, test.d1, test.d2) 41 } else { 42 r2 := Less(test.d2, test.d1) 43 if r2 == true { 44 t.Errorf("%vb: expected (%v) got (%v): (%v) < (%v)", i, false, r2, test.d1, test.d2) 45 } 46 } 47 } 48 } 49 50 func TestEqual(t *testing.T) { 51 52 tests := []struct { 53 d1, d2 string 54 }{ 55 {``, ``}, 56 } 57 for i, test := range tests { 58 r1 := Less(test.d1, test.d2) 59 if r1 != false { 60 t.Errorf("%va: expected (%v) got (%v): (%v) < (%v)", i, false, r1, test.d1, test.d2) 61 } else { 62 r2 := Less(test.d2, test.d1) 63 if r2 != false { 64 t.Errorf("%vb: expected (%v) got (%v): (%v) < (%v)", i, false, r2, test.d1, test.d2) 65 } 66 } 67 } 68 }