diff options
| author | Shulhan <ms@kilabit.info> | 2018-09-17 01:21:27 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-09-18 01:50:21 +0700 |
| commit | 44b26edf7f390db383fe025454be0c4e30cfbd9b (patch) | |
| tree | 84d02953bc9095312182534936c1b60667957f07 /lib/tabula/tabula_test.go | |
| parent | 4a820ec157501c957d2e30f1670656cceec5c044 (diff) | |
| download | pakakeh.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.go | 81 |
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 +} |
