Debian Codegraph @

token/swift_lexer_test.go

raw
1 package token
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 const githubIssue13TestData = "\r\n" +
9 ":20:MT940-1803060458\r\n" +
10 ":21:NONREF\r\n" +
11 ":25:20040000/12345678EUR\r\n" +
12 ":28C:0/13\r\n" +
13 ":60M:C170201EUR1234,56\r\n" +
14 ":61:1702010201DR86,40NMSCNONREF//POS 8888888888\r\n" +
15 ":86:005?20LASTSCHRIFT/BELAST.?888888888888 8888888884REFERE?22NZ HVV \r\n" +
16 "A?23BO?24END-TO-END-REF.:?888888888888 8888888884?26CORE / MANDAT\r\n" +
17 "SREF.:?27VMH008888880001?28GL\xc4UBIGER-ID:?29DE88888888888888888?32H\r\n" +
18 "AMBURGER HOCHBAHN AG?60Ref. IL888888G8888888/6716\r\n" +
19 ":61:1702010201DR24,00NMSCNONREF//POS 3409790600\r\n" +
20 ":86:005?20LASTSCHRIFT/BELAST.?21110865 BEITRAG MITGLIED 888?228888?23\r\n" +
21 "END-TO-END-REF.:?8888888888888ZV888888Z?25CORE / MANDATSREF.:?26EV\r\n" +
22 "-000008888?27GL\xc4UBIGER-ID:?88DE88ZZZ8888888888?29Ref. IL888888G2\r\n" +
23 "145077/1543?32SOME TEST-VEREIN E.V.\r\n" +
24 ":62M:C170203EUR5378,36\r\n-" +
25 "\r\n" +
26 ":20:MT940-1803060458\r\n" +
27 ":21:NONREF\r\n" +
28 ":25:20040000/12345678EUR\r\n" +
29 ":28C:0/13\r\n" +
30 ":60M:C170201EUR1234,56\r\n" +
31 ":61:1702010201DR86,40NMSCNONREF//POS 8888888888\r\n" +
32 ":86:005?20LASTSCHRIFT/BELAST.?888888888888 8888888884REFERE?22NZ HVV \r\n" +
33 "A?23BO?24END-TO-END-REF.:?888888888888 8888888884?26CORE / MANDAT\r\n" +
34 "SREF.:?27VMH008888880001?28GL\xc4UBIGER-ID:?29DE88888888888888888?32H\r\n" +
35 "AMBURGER HOCHBAHN AG?60Ref. IL888888G8888888/6716\r\n" +
36 ":61:1702010201DR24,00NMSCNONREF//POS 3409790600\r\n" +
37 ":86:005?20LASTSCHRIFT/BELAST.?21110865 BEITRAG MITGLIED 888?228888?23\r\n" +
38 "END-TO-END-REF.:?8888888888888ZV888888Z?25CORE / MANDATSREF.:?26EV\r\n" +
39 "-000008888?27GL\xc4UBIGER-ID:?88DE88ZZZ8888888888?29Ref. IL888888G2\r\n" +
40 "145077/1543?32SOME TEST-VEREIN E.V.\r\n" +
41 ":62M:C170203EUR5378,36\r\n-" +
42 "\r\n" +
43 ":20:MT940-1804300355\r\n" +
44 ":21:NONREF\r\n" +
45 ":25:20012345/112233445EUR\r\n" +
46 ":28C:0/2\r\n" +
47 ":60M:C170203EUR1234,56\r\n" +
48 ":61:1702030203DR1,00NMSCNONREF//POS 3416383187\r\n" +
49 ":86:005?20LASTSCHRIFT/BELAST.?21SEPADDDD00009999999-01 DRI?22VENOW 9\r\n" +
50 "3?2350790427 IHRE BILLPAYZAHLUN?24G 0055 3?555 555 555 555 WWW.BI\r\n" +
51 "LLPAY.D?26E?27END-TO-END-REF.:?28SEPADDDD00009999999-01?29CORE /\r\n" +
52 " MANDATSREF.:?32BILLPAY GMBH?12345556667-1-12345678?61GLÄUBIGER-ID\r\n" +
53 ":?62DE19ZZZ00000999999?63Ref. I9999099B999999/280\r\n" +
54 ":61:9909999203DR1000,00NMSCNONREF//POS 9999999999\r\n" +
55 ":86:820?20ÜBERTRAG/ÜBERWEISUNG?21CBAEURXABCDEFG?22END-TO-END-REF.:?23\r\n" +
56 "NICHT ANGEGEBEN?24Ref. H09999999999999/2?30ABCDEF22XXX?31EE99999\r\n" +
57 "0999009999999?32COINBASE UK, LTD.\r\n" +
58 ":62M:C170206EUR1234,56\r\n-"
59
60 func Test_SwiftLexer(t *testing.T) {
61 t.Run("github issue 13", func(t *testing.T) {
62 lexer := NewSwiftLexer("testlexer", []byte(githubIssue13TestData))
63
64 var tokens []Token
65
66 for lexer.HasNext() {
67 tokens = append(tokens, lexer.Next())
68 }
69
70 var messageSeparatorCount int
71 var tags []string
72 for _, tk := range tokens {
73 if tk.Type() == SWIFT_MESSAGE_SEPARATOR {
74 messageSeparatorCount++
75 }
76 if tk.Type() == SWIFT_TAG {
77 tags = append(tags, string(tk.Value()))
78 }
79 }
80
81 if messageSeparatorCount != 3 {
82 t.Logf("Expected %d message separator, got %d", 3, messageSeparatorCount)
83 t.Fail()
84 }
85
86 expectedTagCount := 30
87 if len(tags) != expectedTagCount {
88 t.Logf("Expected %d tags, got %d", expectedTagCount, len(tags))
89 t.Fail()
90 }
91 expectedTags := []string{
92 ":20:",
93 ":21:",
94 ":25:",
95 ":28C:",
96 ":60M:",
97 ":61:",
98 ":86:",
99 ":61:",
100 ":86:",
101 ":62M:",
102 ":20:",
103 ":21:",
104 ":25:",
105 ":28C:",
106 ":60M:",
107 ":61:",
108 ":86:",
109 ":61:",
110 ":86:",
111 ":62M:",
112 ":20:",
113 ":21:",
114 ":25:",
115 ":28C:",
116 ":60M:",
117 ":61:",
118 ":86:",
119 ":61:",
120 ":86:",
121 ":62M:",
122 }
123
124 if !reflect.DeepEqual(tags, expectedTags) {
125 t.Logf("Expected tags to equal\n%v\n\tgot\n%v\n", expectedTags, tags)
126 t.Fail()
127 }
128 })
129 }