-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
json_encode_test.go
55 lines (48 loc) · 1.43 KB
/
json_encode_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
// Copyright 2018 Fedir RYKHTIK. All rights reserved.
// Use of this source code is governed by the GNU GPL 3.0
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"testing"
)
func TestSeqToJSON(t *testing.T) {
inputRawData := []byte{0x31, 0xa, 0x32, 0xa, 0x33, 0xa, 0x34, 0xa, 0x35, 0xa, 0x36, 0xa, 0x37, 0xa, 0x38, 0xa, 0x39, 0xa, 0x31, 0x30, 0xa}
JSON := string(ConvertToJSON(ConvertInputToLines(string(inputRawData))))
expectedOutput := "[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\"]"
if expectedOutput != JSON {
t.Fail()
}
}
func TestStringsToJson(t *testing.T) {
inputData := "1 2 3\n4 5 6"
JSON := string(ConvertToJSON(ConvertInputToLines(inputData)))
expectedOutput := "[\"1 2 3\",\"4 5 6\"]"
if expectedOutput != JSON {
t.Fail()
}
}
func TestStringsToTable(t *testing.T) {
inputData := "A B C\nD E F"
JSON := string(ConvertToJSON(ConvertLinesToTable(ConvertInputToLines(inputData))))
expectedOutput := "[[\"A\",\"B\",\"C\"],[\"D\",\"E\",\"F\"]]"
if expectedOutput != JSON {
t.Fail()
}
}
func TestConvertInputToLines(t *testing.T) {
inputData := "1\n2\n3"
convertedData := fmt.Sprintf("%v", ConvertInputToLines(inputData))
expectedOutput := fmt.Sprintf("%v", []string{"1", "2", "3"})
if expectedOutput != convertedData {
t.Fail()
}
}
func TestMainProgram(t *testing.T) {
main()
}
func TestMainProgramWithSimpleColumns(t *testing.T) {
os.Args = []string{"-sc"}
main()
}