blob: b136824a7c7f49450f4f6ab8074bbddda1fe6b25 [file] [log] [blame]
Scott Bakera00418a2019-06-03 16:15:28 -07001/*
2 * Copyright 2019-present Ciena Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package order
17
18import (
19 "fmt"
20 "testing"
21)
22
23type SortTestStruct struct {
24 One string
25 Two string
26 Three uint64
27}
28
29var testList = []SortTestStruct{
30 {
31 One: "a",
32 Two: "x",
33 Three: 10,
34 },
35 {
36 One: "a",
37 Two: "c",
38 Three: 1,
39 },
40 {
41 One: "a",
42 Two: "b",
43 Three: 2,
44 },
45 {
46 One: "a",
47 Two: "a",
48 Three: 3,
49 },
50 {
51 One: "b",
52 Two: "a",
53 Three: 3,
54 },
55}
56
57func TestSort(t *testing.T) {
58 s, err := Parse("+One,-Two")
59 if err != nil {
60 t.Errorf("Unable to parse sort specification")
61 }
62 //fmt.Printf("%#v\n", s)
63 o, err := s.Process(testList)
64 if err != nil {
65 t.Errorf("Sort failed: %s", err.Error())
66 }
67
68 fmt.Printf("END: %#v\n", o)
69}
70
71func TestSortInt(t *testing.T) {
72 s, err := Parse("Three,One")
73 if err != nil {
74 t.Errorf("Unable to parse sort specification")
75 }
76 //fmt.Printf("%#v\n", s)
77 o, err := s.Process(testList)
78 if err != nil {
79 t.Errorf("Sort failed: %s", err.Error())
80 }
81
82 fmt.Printf("END: %#v\n", o)
83}