-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsort_test.go
58 lines (50 loc) · 3.55 KB
/
sort_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package datatable_test
import (
"testing"
"time"
"github.com/datasweet/datatable"
"github.com/stretchr/testify/assert"
)
func TestSort(t *testing.T) {
// from join test
customers, orders := sampleForJoin()
dt, err := customers.LeftJoin(orders, datatable.On("[Customers].[id]", "[Orders].[user_id]"))
assert.NoError(t, err)
assert.NotNil(t, dt)
checkTable(t, dt,
"id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total",
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00,
2, "Esmée", "Lefort", "[email protected]", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45,
3, "Marine", "Prevost", "[email protected]", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35,
4, "Luc", "Rolland", "[email protected]", "Marseille", nil, nil, nil,
)
sorted := dt.Sort(datatable.SortBy{Column: "num_facture", Desc: true})
checkTable(t, sorted,
"id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total",
3, "Marine", "Prevost", "[email protected]", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35,
2, "Esmée", "Lefort", "[email protected]", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14,
4, "Luc", "Rolland", "[email protected]", "Marseille", nil, nil, nil,
)
// dt must not be modified
sorted = dt.Sort(datatable.SortBy{Column: "ville"}, datatable.SortBy{Column: "id", Desc: true})
checkTable(t, sorted,
"id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total",
3, "Marine", "Prevost", "[email protected]", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35,
2, "Esmée", "Lefort", "[email protected]", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45,
4, "Luc", "Rolland", "[email protected]", "Marseille", nil, nil, nil,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00,
)
sorted = dt.Sort(datatable.SortBy{Column: "ville"}, datatable.SortBy{Column: "prix_total", Desc: true})
checkTable(t, sorted,
"id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total",
3, "Marine", "Prevost", "[email protected]", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35,
2, "Esmée", "Lefort", "[email protected]", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45,
4, "Luc", "Rolland", "[email protected]", "Marseille", nil, nil, nil,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14,
1, "Aimée", "Marechal", "[email protected]", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00,
)
}