-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcoverage_improvement_test.mbt
More file actions
201 lines (194 loc) · 5.39 KB
/
coverage_improvement_test.mbt
File metadata and controls
201 lines (194 loc) · 5.39 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
///|
/// Tests specifically designed to improve coverage of uncovered lines
test "test complex TOML with all token types" {
let complex_toml =
#|string_key = "value with \"quotes\""
#|integer_key = 42
#|float_key = 3.14159
#|bool_key = true
#|int_array = [1, 2, 3, 4, 5]
#|inline_table = { name = "John", age = 30 }
#|[database]
#|server = "192.168.1.1"
#|ports = [ 8001, 8001, 8002 ]
#|connection_max = 5000
#|enabled = true
#|[servers.alpha]
#|ip = "10.0.0.1"
#|dc = "eqdc10"
#|[servers.beta]
#|ip = "10.0.0.2"
#|dc = "eqdc10"
#|
// This now successfully parses with nested tables support
debug_inspect(
try? @toml.parse(complex_toml),
content=(
#|Ok(
#| TomlTable(
#| {
#| "string_key": TomlString("value with \"quotes\""),
#| "integer_key": TomlInteger(42),
#| "float_key": TomlFloat(3.14159),
#| "bool_key": TomlBoolean(true),
#| "int_array": TomlArray(
#| [
#| TomlInteger(1),
#| TomlInteger(2),
#| TomlInteger(3),
#| TomlInteger(4),
#| TomlInteger(5),
#| ],
#| ),
#| "inline_table": TomlTable({ "name": TomlString("John"), "age": TomlInteger(30) }),
#| "database": TomlTable(
#| {
#| "server": TomlString("192.168.1.1"),
#| "ports": TomlArray([TomlInteger(8001), TomlInteger(8001), TomlInteger(8002)]),
#| "connection_max": TomlInteger(5000),
#| "enabled": TomlBoolean(true),
#| },
#| ),
#| "servers": TomlTable(
#| {
#| "alpha": TomlTable({ "ip": TomlString("10.0.0.1"), "dc": TomlString("eqdc10") }),
#| "beta": TomlTable({ "ip": TomlString("10.0.0.2"), "dc": TomlString("eqdc10") }),
#| },
#| ),
#| },
#| ),
#|)
),
)
}
///|
test "test tokenizer unreachable path coverage" {
// This is trying to hit the unreachable else branch in tokenize function
let tokens = @tokenize.tokenize(
(
#|simple = true
),
)
debug_inspect(
tokens,
content=(
#|[
#| Identifier(
#| "simple",
#| loc={ start: { line: 1, column: 1 }, end: { line: 1, column: 7 } },
#| ),
#| Equals(loc={ start: { line: 1, column: 8 }, end: { line: 1, column: 9 } }),
#| BooleanToken(
#| true,
#| loc={ start: { line: 1, column: 10 }, end: { line: 1, column: 14 } },
#| ),
#| EOF(loc={ start: { line: 1, column: 14 }, end: { line: 1, column: 14 } }),
#|]
),
)
}
///|
test "test edge case number formats for error paths" {
// Try to trigger integer parsing errors
let tokens = try? @tokenize.tokenize(
"huge = 999999999999999999999999999999999999999",
)
debug_inspect(
tokens,
content=(
#|Err(Failure("internal/tokenize/tokenize.mbt:969:12-969:41@bobzhang/toml FAILED: Invalid integer: 999999999999999999999999999999999999999"))
),
)
}
///|
test "test literal string handling" {
let tokens = @tokenize.tokenize(
(
#|literal = 'this is a literal string'
),
)
debug_inspect(
tokens,
content=(
#|[
#| Identifier(
#| "literal",
#| loc={ start: { line: 1, column: 1 }, end: { line: 1, column: 8 } },
#| ),
#| Equals(loc={ start: { line: 1, column: 9 }, end: { line: 1, column: 10 } }),
#| StringToken(
#| "this is a literal string",
#| loc={ start: { line: 1, column: 11 }, end: { line: 1, column: 37 } },
#| multiline=false,
#| ),
#| EOF(loc={ start: { line: 1, column: 37 }, end: { line: 1, column: 37 } }),
#|]
),
)
}
///|
test "test various escape sequences coverage" {
let toml_with_escapes =
#|newline = "line1\nline2"
#|tab = "col1\tcol2"
#|carriage = "line1\rline2"
#|backslash = "path\\to\\file"
#|quote = "say \"hello\""
#|
debug_inspect(
try? @toml.parse(toml_with_escapes),
content=(
#|Ok(
#| TomlTable(
#| {
#| "newline": TomlString("line1\nline2"),
#| "tab": TomlString("col1\tcol2"),
#| "carriage": TomlString("line1\rline2"),
#| "backslash": TomlString("path\\to\\file"),
#| "quote": TomlString("say \"hello\""),
#| },
#| ),
#|)
),
)
}
///|
test "test whitespace and comment skipping" {
let toml_with_whitespace =
#|key1 = "value1"
#|
#|
#|key2 = "value2"
#|
debug_inspect(
try? @toml.parse(toml_with_whitespace),
content=(
#|Ok(TomlTable({ "key1": TomlString("value1"), "key2": TomlString("value2") }))
),
)
}
///|
test "test mixed case hex digits" {
let tokens = @tokenize.tokenize(
(
#|mixed_hex = 0xaBcDeF
),
)
debug_inspect(
tokens,
content=(
#|[
#| Identifier(
#| "mixed_hex",
#| loc={ start: { line: 1, column: 1 }, end: { line: 1, column: 10 } },
#| ),
#| Equals(loc={ start: { line: 1, column: 11 }, end: { line: 1, column: 12 } }),
#| IntegerToken(
#| 11259375,
#| loc={ start: { line: 1, column: 13 }, end: { line: 1, column: 21 } },
#| ),
#| EOF(loc={ start: { line: 1, column: 21 }, end: { line: 1, column: 21 } }),
#|]
),
)
}