(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestSort(t *testing.T) { |
| 12 | // from join test |
| 13 | customers, orders := sampleForJoin() |
| 14 | |
| 15 | dt, err := customers.LeftJoin(orders, datatable.On("[Customers].[id]", "[Orders].[user_id]")) |
| 16 | assert.NoError(t, err) |
| 17 | assert.NotNil(t, dt) |
| 18 | checkTable(t, dt, |
| 19 | "id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total", |
| 20 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14, |
| 21 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00, |
| 22 | 2, "Esmée", "Lefort", "esmee.lefort@example.com", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45, |
| 23 | 3, "Marine", "Prevost", "m.prevost@example.com", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35, |
| 24 | 4, "Luc", "Rolland", "lucrolland@example.com", "Marseille", nil, nil, nil, |
| 25 | ) |
| 26 | |
| 27 | sorted := dt.Sort(datatable.SortBy{Column: "num_facture", Desc: true}) |
| 28 | |
| 29 | checkTable(t, sorted, |
| 30 | "id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total", |
| 31 | 3, "Marine", "Prevost", "m.prevost@example.com", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35, |
| 32 | 2, "Esmée", "Lefort", "esmee.lefort@example.com", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45, |
| 33 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00, |
| 34 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14, |
| 35 | 4, "Luc", "Rolland", "lucrolland@example.com", "Marseille", nil, nil, nil, |
| 36 | ) |
| 37 | |
| 38 | // dt must not be modified |
| 39 | sorted = dt.Sort(datatable.SortBy{Column: "ville"}, datatable.SortBy{Column: "id", Desc: true}) |
| 40 | checkTable(t, sorted, |
| 41 | "id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total", |
| 42 | 3, "Marine", "Prevost", "m.prevost@example.com", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35, |
| 43 | 2, "Esmée", "Lefort", "esmee.lefort@example.com", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45, |
| 44 | 4, "Luc", "Rolland", "lucrolland@example.com", "Marseille", nil, nil, nil, |
| 45 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14, |
| 46 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00, |
| 47 | ) |
| 48 | |
| 49 | sorted = dt.Sort(datatable.SortBy{Column: "ville"}, datatable.SortBy{Column: "prix_total", Desc: true}) |
| 50 | checkTable(t, sorted, |
| 51 | "id", "prenom", "nom", "email", "ville", "date_achat", "num_facture", "prix_total", |
| 52 | 3, "Marine", "Prevost", "m.prevost@example.com", "Lille", time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC), "A00106", 235.35, |
| 53 | 2, "Esmée", "Lefort", "esmee.lefort@example.com", "Lyon", time.Date(2013, time.February, 17, 0, 0, 0, 0, time.UTC), "A00105", 149.45, |
| 54 | 4, "Luc", "Rolland", "lucrolland@example.com", "Marseille", nil, nil, nil, |
| 55 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.January, 23, 0, 0, 0, 0, time.UTC), "A00103", 203.14, |
| 56 | 1, "Aimée", "Marechal", "aime.marechal@example.com", "Paris", time.Date(2013, time.February, 14, 0, 0, 0, 0, time.UTC), "A00104", 124.00, |
| 57 | ) |
| 58 | } |
nothing calls this directly
no test coverage detected