-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
138 lines (107 loc) · 4.12 KB
/
Copy pathparser_test.go
File metadata and controls
138 lines (107 loc) · 4.12 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package optionfmt
import "testing"
func TestOSIParser(t *testing.T) {
osiString := "AAPL 261120C00150000"
var contract OptionContract
ok := contract.ParseOSI(osiString)
if !ok {
t.Errorf("Failed to parse OSI string: %s", osiString)
}
if contract.Symbol() != "AAPL" {
t.Errorf("Expected symbol 'AAPL', got '%s'", contract.Symbol())
}
if contract.Type() != Call {
t.Errorf("Expected option type 'C', got '%s'", contract.Type())
}
if contract.StrikePrice() != 150.0 {
t.Errorf("Expected strike price 150.0, got %f", contract.StrikePrice())
}
if contract.Expiration().Year() != 2026 || contract.Expiration().Month() != 11 || contract.Expiration().Day() != 20 {
t.Errorf("Expected expiration date 2026-11-20, got %s", contract.Expiration().Format("2006-01-02"))
}
wrongOSIString := "AAPL 261120C0015000" // Missing one digit in strike price
ok = contract.ParseOSI(wrongOSIString)
if ok {
t.Errorf("Expected failure to parse invalid OSI string: %s", wrongOSIString)
}
}
func TestDASParser(t *testing.T) {
dasString := "+MSFT^G7D300"
var contract OptionContract
ok := contract.ParseDAS(dasString)
if !ok {
t.Errorf("Failed to parse DAS string: %s", dasString)
}
if contract.Symbol() != "MSFT" {
t.Errorf("Expected symbol 'MSFT', got '%s'", contract.Symbol())
}
if contract.Type() != Call {
t.Errorf("Expected option type 'C', got '%s'", contract.Type())
}
if contract.StrikePrice() != 300.0 {
t.Errorf("Expected strike price 300.0, got %f", contract.StrikePrice())
}
if contract.Expiration().Year() != 2026 || contract.Expiration().Month() != 7 || contract.Expiration().Day() != 13 {
t.Errorf("Expected expiration date 2026-07-13, got %s", contract.Expiration().Format("2006-01-02"))
}
}
func TestEUREXInfrontParser(t *testing.T) {
eurexString := "DBK XEUR C 28 12/21 2"
var contract OptionContract
ok := contract.ParseEUREXInfront(eurexString)
if !ok {
t.Errorf("Failed to parse EUREX Infront string: %s", eurexString)
}
if contract.Symbol() != "DBK" {
t.Errorf("Expected symbol 'DBK', got '%s'", contract.Symbol())
}
if contract.Type() != Call {
t.Errorf("Expected option type 'C', got '%s'", contract.Type())
}
if contract.StrikePrice() != 28.0 {
t.Errorf("Expected strike price 28.0, got %f", contract.StrikePrice())
}
if contract.Expiration().Year() != 2021 || contract.Expiration().Month() != 12 || contract.Expiration().Day() != 17 {
t.Errorf("Expected expiration date 2021-12-17, got %s", contract.Expiration().Format("2006-01-02"))
}
}
func TestEUREXT7Parser(t *testing.T) {
eurexString := "PROD FI 20260917 SM ES C 28.00 CNG"
var contract OptionContract
ok := contract.ParseEUREXT7(eurexString)
if !ok {
t.Errorf("Failed to parse EUREX T7 string: %s", eurexString)
}
if contract.Symbol() != "PROD" {
t.Errorf("Expected symbol 'PROD', got '%s'", contract.Symbol())
}
if contract.Type() != Call {
t.Errorf("Expected option type 'C', got '%s'", contract.Type())
}
if contract.StrikePrice() != 28.00 {
t.Errorf("Expected strike price 28.00, got %f", contract.StrikePrice())
}
if contract.Expiration().Year() != 2026 || contract.Expiration().Month() != 9 || contract.Expiration().Day() != 17 {
t.Errorf("Expected expiration date 2026-09-17, got %s", contract.Expiration().Format("2006-01-02"))
}
}
func TestBovespaParser(t *testing.T) {
bovespaString := "BBDCF26"
var contract OptionContract
ok := contract.ParseBovespa(bovespaString)
if !ok {
t.Errorf("Failed to parse Bovespa string: %s", bovespaString)
}
if contract.Symbol() != "BBDC" {
t.Errorf("Expected symbol 'BBDC', got '%s'", contract.Symbol())
}
if contract.Type() != Call {
t.Errorf("Expected option type 'C', got '%s'", contract.Type())
}
if contract.StrikePrice() != 26.0 {
t.Errorf("Expected strike price 26.0, got %f", contract.StrikePrice())
}
if contract.Expiration().Year() != 2026 || contract.Expiration().Month() != 6 || contract.Expiration().Day() != 15 {
t.Errorf("Expected expiration date 2026-06-15, got %s", contract.Expiration().Format("2006-01-02"))
}
}