-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmtparser_test.go
114 lines (90 loc) · 2.36 KB
/
mtparser_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main_test
import (
"bufio"
"fmt"
"os"
"testing"
"github.com/amay0048/mtparser/mtparser"
"github.com/amay0048/mtparser/mtserializer"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func readerTest(nm string) mtparser.Parser {
file, err := os.Open(nm)
check(err)
defer file.Close()
r := bufio.NewReader(file)
psr := mtparser.New(r)
if err = psr.Parse(); err != nil {
fmt.Println(err)
}
return psr
}
func serializerTest(m []mtparser.Block) string {
sl := mtserializer.New(m)
return string(sl.Serialize())
}
func benchmarkReader(b *testing.B) {
s := "./test/mt-103-0001.txt"
for i := 0; i < b.N; i++ {
_ = readerTest(s)
}
}
func benchmarkSerialiser(b *testing.B) {
f := "./test/mt-103-0001.txt"
psr := readerTest(f)
for i := 0; i < b.N; i++ {
_ = serializerTest(psr.Blocks)
}
}
func TestE2E(t *testing.T) {
var psr mtparser.Parser
var msg string
var sts []string
mtparser.TextRegexCompilation()
fmt.Println("Regex compilation success")
psr = readerTest("./test/mt-103-0001.txt")
msg = serializerTest(psr.Blocks)
sts = psr.BodyValueStructured("23E")
fmt.Println(sts)
sts = psr.BodyValueStructured("32A")
// fmt.Println(sts)
sts = psr.BodyValueStructured("33B")
// fmt.Println(sts)
sts = psr.BodyValueStructured("71F")
// fmt.Println(sts)
psr = readerTest("./test/mt-103-0002.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0002.txt", msg)
psr = readerTest("./test/mt-103-0003.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0003.txt", msg)
psr = readerTest("./test/mt-103-0004.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0004.txt", msg)
psr = readerTest("./test/mt-103-0005.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0005.txt", msg)
psr = readerTest("./test/mt-103-0006.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0006.txt", msg)
psr = readerTest("./test/mt-103-0007.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0007.txt", msg)
psr = readerTest("./test/mt-103-0008.txt")
msg = serializerTest(psr.Blocks)
fmt.Println("./test/mt-103-0008.txt", msg)
reader := testing.Benchmark(benchmarkReader)
serial := testing.Benchmark(benchmarkSerialiser)
fmt.Println()
fmt.Println("Reader")
fmt.Println(reader)
fmt.Println()
fmt.Println("Serializer")
fmt.Println(serial)
fmt.Println()
return
}