-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomprehensive_test.mbt
More file actions
980 lines (908 loc) · 24.6 KB
/
comprehensive_test.mbt
File metadata and controls
980 lines (908 loc) · 24.6 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
///|
/// Comprehensive test demonstrating the TOML parser capabilities
test "complex TOML document" {
// For now, let's test a simpler version since we haven't implemented [section] syntax yet
// let simple_toml = "title = \"TOML Example\"\nversion = 1.0\nenabled = true\nports = [8000, 8001, 8002]"
let simple_toml =
#|title = "TOML Example"
#|version = 1.0
#|enabled = true
#|ports = [8000, 8001, 8002]
#|
debug_inspect(
@toml.parse(simple_toml),
content=(
#|TomlTable(
#| {
#| "title": TomlString("TOML Example"),
#| "version": TomlFloat(1),
#| "enabled": TomlBoolean(true),
#| "ports": TomlArray([TomlInteger(8000), TomlInteger(8001), TomlInteger(8002)]),
#| },
#|)
),
)
}
///|
/// Test nested arrays and mixed data types
test "nested arrays and mixed types" {
let complex_toml =
#|mixed_array = [1, "hello", true, 3.14]
#|nested_array = [[1, 2], ["a", "b"], [true, false]]
#|numbers = [1, 2, 3, 4, 5]
#|strings = ["red", "yellow", "green"]
#|booleans = [true, false, true]
#|floats = [1.1, 2.2, 3.3]
#|
debug_inspect(
@toml.parse(complex_toml),
content=(
#|TomlTable(
#| {
#| "mixed_array": TomlArray(
#| [
#| TomlInteger(1),
#| TomlString("hello"),
#| TomlBoolean(true),
#| TomlFloat(3.14),
#| ],
#| ),
#| "nested_array": TomlArray(
#| [
#| TomlArray([TomlInteger(1), TomlInteger(2)]),
#| TomlArray([TomlString("a"), TomlString("b")]),
#| TomlArray([TomlBoolean(true), TomlBoolean(false)]),
#| ],
#| ),
#| "numbers": TomlArray(
#| [
#| TomlInteger(1),
#| TomlInteger(2),
#| TomlInteger(3),
#| TomlInteger(4),
#| TomlInteger(5),
#| ],
#| ),
#| "strings": TomlArray([TomlString("red"), TomlString("yellow"), TomlString("green")]),
#| "booleans": TomlArray([TomlBoolean(true), TomlBoolean(false), TomlBoolean(true)]),
#| "floats": TomlArray([TomlFloat(1.1), TomlFloat(2.2), TomlFloat(3.3)]),
#| },
#|)
),
)
}
///|
/// Test inline tables and nesting
test "inline tables and nesting" {
let inline_toml =
#|server = {host = "localhost", port = 8080, enabled = true}
#|database = {name = "mydb", user = "admin", settings = {timeout = 30, pool_size = 10}}
#|endpoints = ["/api/v1", "/api/v2", "/health"]
#|
debug_inspect(
@toml.parse(inline_toml),
content=(
#|TomlTable(
#| {
#| "server": TomlTable(
#| {
#| "host": TomlString("localhost"),
#| "port": TomlInteger(8080),
#| "enabled": TomlBoolean(true),
#| },
#| ),
#| "database": TomlTable(
#| {
#| "name": TomlString("mydb"),
#| "user": TomlString("admin"),
#| "settings": TomlTable({ "timeout": TomlInteger(30), "pool_size": TomlInteger(10) }),
#| },
#| ),
#| "endpoints": TomlArray([TomlString("/api/v1"), TomlString("/api/v2"), TomlString("/health")]),
#| },
#|)
),
)
}
///|
/// Test realistic application configuration
test "application configuration" {
let app_config =
#|app_name = "WebServer"
#|version = "1.2.3"
#|debug = false
#|max_connections = 1000
#|timeout = 30.5
#|allowed_hosts = ["127.0.0.1", "localhost", "example.com"]
#|features = {logging = true, metrics = false, caching = {enabled = true, ttl = 300}}
#|
debug_inspect(
@toml.parse(app_config),
content=(
#|TomlTable(
#| {
#| "app_name": TomlString("WebServer"),
#| "version": TomlString("1.2.3"),
#| "debug": TomlBoolean(false),
#| "max_connections": TomlInteger(1000),
#| "timeout": TomlFloat(30.5),
#| "allowed_hosts": TomlArray(
#| [
#| TomlString("127.0.0.1"),
#| TomlString("localhost"),
#| TomlString("example.com"),
#| ],
#| ),
#| "features": TomlTable(
#| {
#| "logging": TomlBoolean(true),
#| "metrics": TomlBoolean(false),
#| "caching": TomlTable({ "enabled": TomlBoolean(true), "ttl": TomlInteger(300) }),
#| },
#| ),
#| },
#|)
),
)
}
///|
/// Test string escaping and special characters
test "advanced string handling" {
let string_tests =
#|basic = "simple string"
#|with_quotes = "I said \"Hello World\""
#|with_escapes = "Line 1\nLine 2\tTabbed"
#|with_backslash = "C:\\Users\\Name"
#|unicode_like = "café"
#|empty = ""
#|single_quotes = 'Single quoted string'
#|mixed = ["double", 'single', "escaped\"quote"]
#|
debug_inspect(
@toml.parse(string_tests),
content=(
#|TomlTable(
#| {
#| "basic": TomlString("simple string"),
#| "with_quotes": TomlString("I said \"Hello World\""),
#| "with_escapes": TomlString("Line 1\nLine 2\tTabbed"),
#| "with_backslash": TomlString("C:\\Users\\Name"),
#| "unicode_like": TomlString("café"),
#| "empty": TomlString(""),
#| "single_quotes": TomlString("Single quoted string"),
#| "mixed": TomlArray(
#| [
#| TomlString("double"),
#| TomlString("single"),
#| TomlString("escaped\"quote"),
#| ],
#| ),
#| },
#|)
),
)
}
///|
/// Test numerical edge cases
test "numerical edge cases" {
// Test various number formats and edge cases
let number_tests =
#|zero = 0
#|positive = 42
#|small_float = 0.1
#|large_float = 1000000.999999
#|mixed_numbers = [0, 1, 42, 3.14, 2.5, 0.0]
#|
debug_inspect(
@toml.parse(number_tests),
content=(
#|TomlTable(
#| {
#| "zero": TomlInteger(0),
#| "positive": TomlInteger(42),
#| "small_float": TomlFloat(0.1),
#| "large_float": TomlFloat(1000000.999999),
#| "mixed_numbers": TomlArray(
#| [
#| TomlInteger(0),
#| TomlInteger(1),
#| TomlInteger(42),
#| TomlFloat(3.14),
#| TomlFloat(2.5),
#| TomlFloat(0),
#| ],
#| ),
#| },
#|)
),
)
}
///|
test "empty array" {
debug_inspect(
@toml.parse(
(
#|empty_array = []
),
),
content=(
#|TomlTable({ "empty_array": TomlArray([]) })
),
)
}
///|
/// Test negative numbers (now supported!)
test "negative numbers" {
let negative_toml =
#|negative_int = -42
#|negative_float = -3.14
#|zero = 0
#|positive = 123
#|mixed_array = [-1, 2, -3.5, 4.0]
#|extreme_negative = -9223372036854775807
#|small_negative = -0.001
#|
debug_inspect(
@toml.parse(negative_toml),
content=(
#|TomlTable(
#| {
#| "negative_int": TomlInteger(-42),
#| "negative_float": TomlFloat(-3.14),
#| "zero": TomlInteger(0),
#| "positive": TomlInteger(123),
#| "mixed_array": TomlArray([TomlInteger(-1), TomlInteger(2), TomlFloat(-3.5), TomlFloat(4)]),
#| "extreme_negative": TomlInteger(-9223372036854775807),
#| "small_negative": TomlFloat(-0.001),
#| },
#|)
),
)
}
///|
/// Test negative numbers in various contexts
test "negative numbers in context" {
// Single negative integer
debug_inspect(
@toml.parse(
(
#|count = -5
),
),
content=(
#|TomlTable({ "count": TomlInteger(-5) })
),
)
// Single negative float
debug_inspect(
@toml.parse(
(
#|temperature = -15.5
),
),
content=(
#|TomlTable({ "temperature": TomlFloat(-15.5) })
),
)
// Array with mixed positive and negative numbers
debug_inspect(
@toml.parse(
(
#|values = [1, -2, 3.0, -4.5]
),
),
content=(
#|TomlTable({ "values": TomlArray([TomlInteger(1), TomlInteger(-2), TomlFloat(3), TomlFloat(-4.5)]) })
),
)
// Inline table with negative values
let coords_toml =
#|coords = {x = -10, y = 20, z = -5.5}
#|
debug_inspect(
@toml.parse(coords_toml),
content=(
#|TomlTable({ "coords": TomlTable({ "x": TomlInteger(-10), "y": TomlInteger(20), "z": TomlFloat(-5.5) }) })
),
)
// Multiple negative values
let multi_negative =
#|min_temp = -40
#|max_debt = -1000.50
#|adjustment = -0.1
#|
debug_inspect(
@toml.parse(multi_negative),
content=(
#|TomlTable(
#| {
#| "min_temp": TomlInteger(-40),
#| "max_debt": TomlFloat(-1000.5),
#| "adjustment": TomlFloat(-0.1),
#| },
#|)
),
)
}
///|
/// Test complex data structure (simulating a microservice config)
test "microservice configuration" {
let microservice_config =
#|service_name = "user-service"
#|version = "2.1.0"
#|environment = "production"
#|http = {port = 8080, host = "0.0.0.0", timeout = 30.0}
#|database = {url = "postgresql://localhost:5432/users", max_connections = 20, retry_attempts = 3}
#|redis = {enabled = true, host = "redis-cluster", port = 6379, db = 0}
#|logging = {level = "INFO", format = "json", outputs = ["stdout", "file"]}
#|metrics = {enabled = true, port = 9090, path = "/metrics"}
#|health_check = {endpoint = "/health", interval = 10, timeout = 5.0}
#|rate_limiting = {enabled = true, requests_per_minute = 1000, burst = 50}
#|
debug_inspect(
@toml.parse(microservice_config),
content=(
#|TomlTable(
#| {
#| "service_name": TomlString("user-service"),
#| "version": TomlString("2.1.0"),
#| "environment": TomlString("production"),
#| "http": TomlTable(
#| {
#| "port": TomlInteger(8080),
#| "host": TomlString("0.0.0.0"),
#| "timeout": TomlFloat(30),
#| },
#| ),
#| "database": TomlTable(
#| {
#| "url": TomlString("postgresql://localhost:5432/users"),
#| "max_connections": TomlInteger(20),
#| "retry_attempts": TomlInteger(3),
#| },
#| ),
#| "redis": TomlTable(
#| {
#| "enabled": TomlBoolean(true),
#| "host": TomlString("redis-cluster"),
#| "port": TomlInteger(6379),
#| "db": TomlInteger(0),
#| },
#| ),
#| "logging": TomlTable(
#| {
#| "level": TomlString("INFO"),
#| "format": TomlString("json"),
#| "outputs": TomlArray([TomlString("stdout"), TomlString("file")]),
#| },
#| ),
#| "metrics": TomlTable(
#| {
#| "enabled": TomlBoolean(true),
#| "port": TomlInteger(9090),
#| "path": TomlString("/metrics"),
#| },
#| ),
#| "health_check": TomlTable(
#| {
#| "endpoint": TomlString("/health"),
#| "interval": TomlInteger(10),
#| "timeout": TomlFloat(5),
#| },
#| ),
#| "rate_limiting": TomlTable(
#| {
#| "enabled": TomlBoolean(true),
#| "requests_per_minute": TomlInteger(1000),
#| "burst": TomlInteger(50),
#| },
#| ),
#| },
#|)
),
)
}
///|
/// Test error handling with expect tests
test "error handling" {
// Missing value
inspect(
parse_expect_to_fail("key ="),
content=(
#|Expected value at { start: { line: 1, column: 6 }, end: { line: 1, column: 6 } })
),
)
// Missing key
inspect(
parse_expect_to_fail("= \"value\""),
content=(
#|Expected key at { start: { line: 1, column: 1 }, end: { line: 1, column: 2 } })
),
)
// Unterminated string
inspect(
parse_expect_to_fail("key = \"unterminated"),
content=(
#|Unterminated string at line 1, column 8)
),
)
// Invalid syntax - incomplete array
inspect(
parse_expect_to_fail("key = [1, 2"),
content=(
#|Expected ',' or ']' in array at { start: { line: 1, column: 12 }, end: { line: 1, column: 12 } })
),
)
// Empty key
inspect(
parse_expect_to_fail(" = \"value\""),
content=(
#|Expected key at { start: { line: 1, column: 2 }, end: { line: 1, column: 3 } })
),
)
}
///|
/// Test location tracking for various error scenarios
test "error location tracking" {
// Test 1: Error at beginning of line
inspect(
parse_expect_to_fail("=missing_key"),
content=(
#|Expected key at { start: { line: 1, column: 1 }, end: { line: 1, column: 2 } })
),
)
// Test 2: Error in the middle of a line
inspect(
parse_expect_to_fail("valid_key = "),
content=(
#|Expected value at { start: { line: 1, column: 13 }, end: { line: 1, column: 13 } })
),
)
// Test 3: Error with spaces before it
inspect(
parse_expect_to_fail(" key = "),
content=(
#|Expected value at { start: { line: 1, column: 10 }, end: { line: 1, column: 10 } })
),
)
// Test 4: Missing equals sign
inspect(
parse_expect_to_fail("key \"value\""),
content=(
#|Expected '=' at { start: { line: 1, column: 5 }, end: { line: 1, column: 12 } })
),
)
// Test 5: Invalid value type
inspect(
parse_expect_to_fail("key = invalid_unquoted"),
content=(
#|Expected value at { start: { line: 1, column: 7 }, end: { line: 1, column: 23 } })
),
)
}
///|
/// Test multiline error location tracking
test "multiline error locations" {
// Test 1: Error on second line
let multiline_test1 =
#|key1 = "valid"
#|key2 =
#|
inspect(
parse_expect_to_fail(multiline_test1),
content=(
#|Expected value at { start: { line: 2, column: 7 }, end: { line: 3, column: 1 } })
),
)
// Test 2: Error on third line
let multiline_test2 =
#|key1 = "valid"
#|key2 = "also_valid"
#|= missing_key
#|
inspect(
parse_expect_to_fail(multiline_test2),
content=(
#|Expected key at { start: { line: 3, column: 1 }, end: { line: 3, column: 2 } })
),
)
// Test 3: Array error on second line
let multiline_test3 =
#|key1 = "valid"
#|key2 = [1, 2,
#|
inspect(
parse_expect_to_fail(multiline_test3),
content=(
#|Expected value at { start: { line: 2, column: 14 }, end: { line: 3, column: 1 } })
),
)
// Test 4: Error after newlines and comments
let multiline_test4 =
#|# Comment line
#|
#|key1 = "valid"
#|
#|= error_here
#|
inspect(
parse_expect_to_fail(multiline_test4),
content=(
#|Expected key at { start: { line: 5, column: 1 }, end: { line: 5, column: 2 } })
),
)
}
///|
/// Test array parsing error locations
test "array error locations" {
// Test 1: Missing closing bracket at specific position
inspect(
parse_expect_to_fail("arr = [1, 2, 3"),
content=(
#|Expected ',' or ']' in array at { start: { line: 1, column: 15 }, end: { line: 1, column: 15 } })
),
)
// Test 2: Missing comma between elements
inspect(
parse_expect_to_fail("arr = [1 2]"),
content=(
#|Expected ',' or ']' in array at { start: { line: 1, column: 10 }, end: { line: 1, column: 11 } })
),
)
// Test 3: Invalid value in array
inspect(
parse_expect_to_fail("arr = [1, invalid, 3]"),
content=(
#|Expected value at { start: { line: 1, column: 11 }, end: { line: 1, column: 18 } })
),
)
// Test 4: Nested array error
inspect(
parse_expect_to_fail("arr = [[1, 2], [3, ]"),
content=(
#|Expected ',' or ']' in array at { start: { line: 1, column: 21 }, end: { line: 1, column: 21 } })
),
)
// Test 5: Array with newlines
let array_multiline =
#|arr = [
#| 1,
#| 2,
#| invalid_value
#|]
#|
inspect(
parse_expect_to_fail(array_multiline),
content=(
#|Expected value at { start: { line: 3, column: 5 }, end: { line: 4, column: 1 } })
),
)
}
///|
/// Test inline table error locations
test "inline table error locations" {
// Test 1: Missing closing brace
inspect(
parse_expect_to_fail("table = {key = \"value\""),
content=(
#|Expected ',' or '}' in inline table at { start: { line: 1, column: 23 }, end: { line: 1, column: 23 } })
),
)
// Test 2: Missing key in inline table
inspect(
parse_expect_to_fail("table = {= \"value\"}"),
content=(
#|Expected key at { start: { line: 1, column: 10 }, end: { line: 1, column: 11 } })
),
)
// Test 3: Missing value in inline table
inspect(
parse_expect_to_fail("table = {key = }"),
content=(
#|Expected value at { start: { line: 1, column: 16 }, end: { line: 1, column: 17 } })
),
)
// Test 4: Missing equals in inline table
inspect(
parse_expect_to_fail("table = {key \"value\"}"),
content=(
#|Expected '=' at { start: { line: 1, column: 14 }, end: { line: 1, column: 21 } })
),
)
// Test 5: Invalid syntax after comma
debug_inspect(
try? @toml.parse("table = {key1 = \"val1\", }"),
content=(
#|Ok(TomlTable({ "table": TomlTable({ "key1": TomlString("val1") }) }))
),
)
}
///|
/// Test table header error locations
test "table header error locations" {
// Test 1: Missing closing bracket in table header
inspect(
parse_expect_to_fail("[table_name"),
content=(
#|Expected ']' at { start: { line: 1, column: 12 }, end: { line: 1, column: 12 } })
),
)
// Test 2: Missing table name
inspect(
parse_expect_to_fail("[]"),
content=(
#|Expected key at { start: { line: 1, column: 2 }, end: { line: 1, column: 3 } })
),
)
// Test 3: Array of tables missing second bracket
inspect(
parse_expect_to_fail("[[table_name]"),
content=(
#|Expected ']]' at { start: { line: 1, column: 13 }, end: { line: 1, column: 14 } })
),
)
// Test 4: Array of tables missing table name
inspect(
parse_expect_to_fail("[[]]"),
content=(
#|Expected key at { start: { line: 1, column: 3 }, end: { line: 1, column: 4 } })
),
)
// Test 5: Invalid character in table name position
inspect(
parse_expect_to_fail("[#invalid]"),
content=(
#|Expected key at { start: { line: 1, column: 11 }, end: { line: 1, column: 11 } })
),
)
}
///|
/// Test precise column tracking with various spacing
test "precise column tracking" {
// Test 1: Error at specific column with tabs (assuming tab = 1 column)
inspect(
parse_expect_to_fail("\tkey ="),
content=(
#|Expected value at { start: { line: 1, column: 7 }, end: { line: 1, column: 7 } })
),
)
// Test 2: Error with mixed spaces and content (should fail due to missing newline)
inspect(
parse_expect_to_fail(" key1 = \"val\" key2 = "),
content=(
#|Expected newline or end of file after key-value pair at { start: { line: 1, column: 17 }, end: { line: 1, column: 21 } })
),
)
// Test 3: Long key name error position
inspect(
parse_expect_to_fail("very_long_key_name_here = "),
content=(
#|Expected value at { start: { line: 1, column: 27 }, end: { line: 1, column: 27 } })
),
)
// Test 4: Error position after unicode characters
inspect(
parse_expect_to_fail("café = "),
content=(
#|Unexpected character: 'é')
),
)
// Test 5: Multiple equals signs - error on second one
inspect(
parse_expect_to_fail("key = = \"value\""),
content=(
#|Expected value at { start: { line: 1, column: 7 }, end: { line: 1, column: 8 } })
),
)
}
///|
/// Test complex error scenarios with precise location tracking
test "complex error location scenarios" {
// Test 1: Deep nesting error location
let deep_nested =
#|outer = {
#| middle = {
#| inner = {
#| key =
#| }
#| }
#|}
#|
inspect(
parse_expect_to_fail(deep_nested),
content=(
#|Expected value at { start: { line: 4, column: 12 }, end: { line: 5, column: 1 } })
),
)
// Test 2: Error at end of file
inspect(
parse_expect_to_fail("key = [1, 2, 3"),
content=(
#|Expected ',' or ']' in array at { start: { line: 1, column: 15 }, end: { line: 1, column: 15 } })
),
)
// Test 3: Error with different quote types
inspect(
parse_expect_to_fail("key = 'unterminated"),
content=(
#|Unterminated string at line 1, column 8)
),
)
// Test 4: Error in array of tables with location
let aot_error =
#|[[servers]]
#|name = "server1"
#|
#|[[servers]]
#|name =
#|
inspect(
parse_expect_to_fail(aot_error),
content=(
#|Expected value at { start: { line: 5, column: 7 }, end: { line: 6, column: 1 } })
),
)
// Test 5: Error with trailing whitespace and newlines
let trailing_ws =
#|key1 = "value"
#|key2 =
#|
#|
inspect(
parse_expect_to_fail(trailing_ws),
content=(
#|Expected value at { start: { line: 2, column: 7 }, end: { line: 3, column: 1 } })
),
)
}
///|
/// Test location tracking with comments and special characters
test "location tracking with special cases" {
// Test 1: Error after comment on same line (should fail since comments aren't implemented)
inspect(
parse_expect_to_fail("key = # comment"),
content=(
#|Expected value at { start: { line: 1, column: 16 }, end: { line: 1, column: 16 } })
),
)
// Test 2: Error with windows-style line endings (if supported)
inspect(
parse_expect_to_fail("key1 = \"value\"\r\nkey2 = "),
content=(
#|Expected value at { start: { line: 2, column: 8 }, end: { line: 2, column: 8 } })
),
)
// Test 3: Error with just spaces as a key
inspect(
parse_expect_to_fail(" = \"value\""),
content=(
#|Expected key at { start: { line: 1, column: 4 }, end: { line: 1, column: 5 } })
),
)
// Test 4: Complex array with error at specific nested position
let complex_array =
#|data = [
#| [1, 2, 3],
#| ["a", "b", ],
#| [true, false, invalid_token]
#|]
#|
inspect(
parse_expect_to_fail(complex_array),
content=(
#|Expected value at { start: { line: 4, column: 17 }, end: { line: 4, column: 30 } })
),
)
// Test 5: Very long line with error at the end
let long_line = "very_long_key_name_that_goes_on_and_on_and_on_and_on_and_on = "
inspect(
parse_expect_to_fail(long_line),
content=(
#|Expected value at { start: { line: 1, column: 63 }, end: { line: 1, column: 63 } })
),
)
}
///|
/// Test edge cases with expect tests
test "edge cases" {
// Empty input should result in empty table
debug_inspect(
@toml.parse(
(
#|
),
),
content=(
#|TomlTable({})
),
)
// Only comments and whitespace should result in empty table
let comments_only_toml =
#|# Just a comment
#|
#|# Another comment
#|
debug_inspect(
@toml.parse(comments_only_toml),
content=(
#|TomlTable({})
),
)
// Mixed single and double quotes should parse correctly
let mixed_quotes_toml =
#|single = 'value'
#|double = "value"
#|
debug_inspect(
@toml.parse(mixed_quotes_toml),
content=(
#|TomlTable({ "single": TomlString("value"), "double": TomlString("value") })
),
)
// Whitespace around equals sign
debug_inspect(
@toml.parse(
(
#|spaced = "value"
),
),
content=(
#|TomlTable({ "spaced": TomlString("value") })
),
)
// Multiple newlines and comments
let complex_whitespace =
#|# Top comment
#|
#|key1 = "value1"
#|
#|# Middle comment
#|
#|key2 = "value2"
#|# End comment
#|
debug_inspect(
@toml.parse(complex_whitespace),
content=(
#|TomlTable({ "key1": TomlString("value1"), "key2": TomlString("value2") })
),
)
}
///|
test "newline significate" {
// this should fail
let data =
#|key1 =
#| 3
inspect(
parse_expect_to_fail(data),
content=(
#|Expected value at { start: { line: 1, column: 7 }, end: { line: 2, column: 1 } })
),
)
// This should fail, inline table does not cross newline according to the spec
let data2 =
#| server = {host =
#| "localhost"
#| }
inspect(
parse_expect_to_fail(data2),
content=(
#|Expected value at { start: { line: 1, column: 18 }, end: { line: 2, column: 1 } })
),
)
// This should pass, array can cross newline according to the spec
let data3 =
#| x = [1,
#|2
#|
#|
#|]
#|
debug_inspect(
try? @toml.parse(data3),
content=(
#|Ok(TomlTable({ "x": TomlArray([TomlInteger(1), TomlInteger(2)]) }))
),
)
}