aboutsummaryrefslogtreecommitdiff
path: root/lib/tabula/tabula_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-17 01:21:27 +0700
committerShulhan <ms@kilabit.info>2018-09-18 01:50:21 +0700
commit44b26edf7f390db383fe025454be0c4e30cfbd9b (patch)
tree84d02953bc9095312182534936c1b60667957f07 /lib/tabula/tabula_test.go
parent4a820ec157501c957d2e30f1670656cceec5c044 (diff)
downloadpakakeh.go-44b26edf7f390db383fe025454be0c4e30cfbd9b.tar.xz
Merge package "github.com/shuLhan/tabula"
Diffstat (limited to 'lib/tabula/tabula_test.go')
-rw-r--r--lib/tabula/tabula_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/tabula/tabula_test.go b/lib/tabula/tabula_test.go
new file mode 100644
index 00000000..6b13d60c
--- /dev/null
+++ b/lib/tabula/tabula_test.go
@@ -0,0 +1,81 @@
+// Copyright 2017, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be found
+// in the LICENSE file.
+
+package tabula
+
+import (
+ "os"
+)
+
+var (
+ traces = make([]byte, 1024)
+)
+
+func printStackTrace() {
+ var lines, start, end int
+
+ for x, b := range traces {
+ if b != '\n' {
+ continue
+ }
+ lines++
+ if lines == 3 {
+ start = x
+ } else if lines == 5 {
+ end = x + 1
+ break
+ }
+ }
+
+ os.Stderr.Write(traces[start:end])
+}
+
+var testColTypes = []int{
+ TInteger,
+ TInteger,
+ TInteger,
+ TString,
+}
+
+var testColNames = []string{"int01", "int02", "int03", "class"}
+
+// Testing data and function for Rows and MapRows
+var rowsData = [][]string{
+ {"1", "5", "9", "+"},
+ {"2", "6", "0", "-"},
+ {"3", "7", "1", "-"},
+ {"4", "8", "2", "+"},
+}
+
+var testClassIdx = 3
+
+var rowsExpect = []string{
+ "&[1 5 9 +]",
+ "&[2 6 0 -]",
+ "&[3 7 1 -]",
+ "&[4 8 2 +]",
+}
+
+var groupByExpect = "[{+ &[1 5 9 +]&[4 8 2 +]} {- &[2 6 0 -]&[3 7 1 -]}]"
+
+func initRows() (rows Rows, e error) {
+ for i := range rowsData {
+ l := len(rowsData[i])
+ row := make(Row, 0)
+
+ for j := 0; j < l; j++ {
+ rec, e := NewRecordBy(rowsData[i][j],
+ testColTypes[j])
+
+ if nil != e {
+ return nil, e
+ }
+
+ row = append(row, rec)
+ }
+
+ rows.PushBack(&row)
+ }
+ return rows, nil
+}