ruchy 4.2.1

A systems scripting language that transpiles to idiomatic Rust with extreme quality engineering
Documentation
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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

    use crate::frontend::parser::Parser;

    #[test]
    fn test_basic_class() {
        let code = "class MyClass { }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Basic class should parse");
    }

    #[test]
    fn test_class_with_fields() {
        let code = "class Point { x: f64 y: f64 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with fields should parse");
    }

    #[test]
    fn test_class_with_inheritance() {
        let code = "class Child : Parent { }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with inheritance should parse");
    }

    #[test]
    fn test_class_with_traits() {
        let code = "class MyClass : ParentClass + Trait1 + Trait2 { }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with traits should parse");
    }

    #[test]
    fn test_class_with_constructor() {
        let code = "class Point { new(x: f64, y: f64) { self.x = x; self.y = y } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with constructor should parse");
    }

    #[test]
    fn test_class_with_method() {
        let code = "class Point { fun distance(&self) -> f64 { 0.0 } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with method should parse");
    }

    #[test]
    fn test_generic_class() {
        let code = "class Container<T> { value: T }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Generic class should parse");
    }

    // Additional tests for comprehensive coverage
    #[test]
    fn test_class_with_init_constructor() {
        let code = "class Point { init(x: f64) { self.x = x } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with init constructor should parse");
    }

    #[test]
    fn test_class_with_multiple_constructors() {
        let code = "class Point { new() { } new(x: f64) { self.x = x } }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with multiple constructors should parse"
        );
    }

    #[test]
    fn test_class_with_static_method() {
        let code = "class Math { static fun add(a: i32, b: i32) -> i32 { a + b } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with static method should parse");
    }

    #[test]
    fn test_class_with_pub_field() {
        let code = "class Point { pub x: f64 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with pub field should parse");
    }

    #[test]
    fn test_class_with_mut_field() {
        let code = "class Counter { mut count: i32 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with mut field should parse");
    }

    #[test]
    fn test_class_with_pub_mut_field() {
        let code = "class Counter { pub mut count: i32 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with pub mut field should parse");
    }

    #[test]
    fn test_class_with_const() {
        // Const in class might require different syntax
        let code = "class Math { const PI: f64 = 3.14159 }";
        let result = Parser::new(code).parse();
        // Some grammars require typed const
        assert!(result.is_ok() || result.is_err());
    }

    #[test]
    fn test_class_with_typed_const() {
        let code = "class Math { const MAX: i32 = 100 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with typed const should parse");
    }

    #[test]
    fn test_class_with_self_method() {
        let code = "class Point { fun get_x(&self) -> f64 { self.x } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with &self method should parse");
    }

    #[test]
    fn test_class_with_mut_self_method() {
        let code = "class Counter { fun increment(&mut self) { self.count = self.count + 1 } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with &mut self method should parse");
    }

    #[test]
    fn test_class_with_owned_self_method() {
        let code = "class Point { fun into_tuple(self) -> (f64, f64) { (self.x, self.y) } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with owned self method should parse");
    }

    #[test]
    fn test_class_with_override_method() {
        let code = "class Child : Parent { override fun method(&self) { } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with override method should parse");
    }

    #[test]
    fn test_class_with_final_method() {
        let code = "class Base { final fun method(&self) { } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with final method should parse");
    }

    #[test]
    fn test_class_with_abstract_method() {
        let code = "class Base { abstract fun method(&self) }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with abstract method should parse");
    }

    #[test]
    fn test_class_with_async_method() {
        let code = "class AsyncClass { async fun fetch(&self) { } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with async method should parse");
    }

    #[test]
    fn test_class_with_fn_method() {
        let code = "class Point { fn get_x(&self) -> f64 { self.x } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with fn keyword should parse");
    }

    #[test]
    fn test_class_with_generic_inheritance() {
        let code = "class IntContainer : Container<i32> { }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with generic inheritance should parse"
        );
    }

    #[test]
    fn test_class_with_generic_method() {
        // Generic methods in classes may have different syntax
        let code = "class Factory { fun create<T>() -> T { } }";
        let result = Parser::new(code).parse();
        // Generic methods may or may not be supported in this grammar
        assert!(result.is_ok() || result.is_err());
    }

    #[test]
    fn test_class_with_let_field() {
        let code = "class Point { let x: f64 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with let field should parse");
    }

    #[test]
    fn test_class_traits_only() {
        let code = "class MyClass : + Trait1 + Trait2 { }";
        let result = Parser::new(code).parse();
        // Traits without superclass - depends on grammar
        // Just ensure it doesn't crash
        assert!(result.is_ok() || result.is_err());
    }

    #[test]
    fn test_class_with_return_type() {
        let code = "class Point { fun magnitude(&self) -> f64 { 0.0 } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class method with return type should parse");
    }

    #[test]
    fn test_class_with_no_return_type() {
        let code = "class Logger { fun log(&self, msg: String) { } }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class method without return type should parse"
        );
    }

    #[test]
    fn test_class_with_multiple_type_params() {
        let code = "class Map<K, V> { }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with multiple type params should parse"
        );
    }

    #[test]
    fn test_class_with_field_initialization() {
        let code = "class Point { x: f64 = 0.0 }";
        let result = Parser::new(code).parse();
        // Field initialization support depends on grammar
        assert!(result.is_ok() || result.is_err());
    }

    #[test]
    fn test_class_complete_example() {
        // Complete class with inheritance, traits, fields, and methods
        let code = r#"
            class Vector2D : BaseVector + Comparable + Serializable {
                pub mut x: f64
                pub mut y: f64

                new(x: f64, y: f64) {
                    self.x = x
                    self.y = y
                }

                fun magnitude(&self) -> f64 {
                    0.0
                }

                static fun zero() -> Vector2D {
                    Vector2D::new(0.0, 0.0)
                }
            }
        "#;
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Complete class example should parse");
    }

    #[test]
    fn test_class_empty_body() {
        let code = "class Empty { }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Empty class body should parse");
    }

    #[test]
    fn test_class_field_separator_comma() {
        let code = "class Point { x: f64, y: f64 }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with comma-separated fields should parse"
        );
    }

    #[test]
    fn test_class_field_separator_semicolon() {
        let code = "class Point { x: f64; y: f64 }";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with semicolon-separated fields should parse"
        );
    }

    #[test]
    fn test_class_field_separator_newline() {
        let code = "class Point {\n    x: f64\n    y: f64\n}";
        let result = Parser::new(code).parse();
        assert!(
            result.is_ok(),
            "Class with newline-separated fields should parse"
        );
    }

    #[test]
    fn test_class_with_pub_constructor() {
        let code = "class Point { pub new() { } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with pub constructor should parse");
    }

    #[test]
    fn test_class_with_pub_method() {
        let code = "class Point { pub fun get_x(&self) -> f64 { self.x } }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok(), "Class with pub method should parse");
    }

    #[test]
    fn test_nested_class_error() {
        let code = "class Outer { class Inner { } }";
        let result = Parser::new(code).parse();
        // Nested classes are not supported
        assert!(result.is_err(), "Nested classes should fail");
    }

    #[test]
    fn test_impl_in_class_error() {
        let code = "class MyClass { impl SomeTrait { } }";
        let result = Parser::new(code).parse();
        // Impl blocks in classes not supported
        assert!(result.is_err(), "Impl in class should fail");
    }

    #[test]
    fn test_class_with_decorated_field() {
        // Decorators on fields - depends on grammar
        let code = "class MyClass { @JsonIgnore value: i32 }";
        let result = Parser::new(code).parse();
        assert!(result.is_ok() || result.is_err());
    }

    // ============================================================
    // Additional comprehensive tests for EXTREME TDD coverage
    // ============================================================

    use crate::frontend::ast::{Expr, ExprKind};
    use crate::frontend::parser::Result;

    fn parse(code: &str) -> Result<Expr> {
        Parser::new(code).parse()
    }

    fn get_block_exprs(expr: &Expr) -> Option<&Vec<Expr>> {
        match &expr.kind {
            ExprKind::Block(exprs) => Some(exprs),
            _ => None,
        }
    }

    // ============================================================
    // Class produces Class ExprKind
    // ============================================================

    #[test]
    fn test_class_produces_class_exprkind() {
        let expr = parse("class Foo { }").unwrap();
        if let Some(exprs) = get_block_exprs(&expr) {
            assert!(
                matches!(&exprs[0].kind, ExprKind::Class { .. }),
                "Should produce Class ExprKind"
            );
        }
    }

    // ============================================================
    // Basic class variations
    // ============================================================

    #[test]
    fn test_class_single_char_name() {
        let result = parse("class A { }");
        assert!(result.is_ok(), "Single char class name should parse");
    }

    #[test]
    fn test_class_long_name() {
        let result = parse("class VeryLongClassNameWithManyChars { }");
        assert!(result.is_ok(), "Long class name should parse");
    }

    #[test]
    fn test_class_underscore_name() {
        let result = parse("class _InternalClass { }");
        assert!(result.is_ok(), "Underscore prefix class should parse");
    }

    #[test]
    fn test_class_numbers_in_name() {
        let result = parse("class Vector3D { }");
        assert!(result.is_ok(), "Class with numbers should parse");
    }

    // ============================================================
    // Field variations
    // ============================================================

    #[test]
    fn test_class_one_field() {
        let result = parse("class Point { x: i32 }");
        assert!(result.is_ok(), "One field should parse");
    }

    #[test]
    fn test_class_two_fields() {
        let result = parse("class Point { x: i32, y: i32 }");
        assert!(result.is_ok(), "Two fields should parse");
    }

    #[test]
    fn test_class_three_fields() {
        let result = parse("class Point { x: i32, y: i32, z: i32 }");
        assert!(result.is_ok(), "Three fields should parse");
    }

    #[test]
    fn test_class_field_i32() {
        let result = parse("class Data { value: i32 }");
        assert!(result.is_ok(), "i32 field should parse");
    }

    #[test]
    fn test_class_field_f64() {
        let result = parse("class Data { value: f64 }");
        assert!(result.is_ok(), "f64 field should parse");
    }

    #[test]
    fn test_class_field_string() {
        let result = parse("class Data { name: String }");
        assert!(result.is_ok(), "String field should parse");
    }

    #[test]
    fn test_class_field_bool() {
        let result = parse("class Data { flag: bool }");
        assert!(result.is_ok(), "bool field should parse");
    }

    #[test]
    fn test_class_field_option() {
        let result = parse("class Data { maybe: Option<i32> }");
        assert!(result.is_ok(), "Option field should parse");
    }

    #[test]
    fn test_class_field_vec() {
        let result = parse("class Data { items: Vec<i32> }");
        assert!(result.is_ok(), "Vec field should parse");
    }

    // ============================================================
    // Method variations
    // ============================================================

    #[test]
    fn test_class_method_no_params() {
        let result = parse("class Foo { fun get(&self) { } }");
        assert!(result.is_ok(), "Method no params should parse");
    }

    #[test]
    fn test_class_method_one_param() {
        let result = parse("class Foo { fun set(&mut self, v: i32) { } }");
        assert!(result.is_ok(), "Method one param should parse");
    }

    #[test]
    fn test_class_method_two_params() {
        let result = parse("class Foo { fun compute(&self, a: i32, b: i32) { } }");
        assert!(result.is_ok(), "Method two params should parse");
    }

    #[test]
    fn test_class_static_method_no_params() {
        let result = parse("class Foo { static fun create() { } }");
        assert!(result.is_ok(), "Static no params should parse");
    }

    #[test]
    fn test_class_static_method_with_params() {
        let result = parse("class Foo { static fun create(a: i32) { } }");
        assert!(result.is_ok(), "Static with params should parse");
    }

    // ============================================================
    // Constructor variations
    // ============================================================

    #[test]
    fn test_class_constructor_no_params() {
        let result = parse("class Foo { new() { } }");
        assert!(result.is_ok(), "Constructor no params should parse");
    }

    #[test]
    fn test_class_constructor_one_param() {
        let result = parse("class Foo { new(x: i32) { } }");
        assert!(result.is_ok(), "Constructor one param should parse");
    }

    #[test]
    fn test_class_constructor_three_params() {
        let result = parse("class Foo { new(a: i32, b: i32, c: i32) { } }");
        assert!(result.is_ok(), "Constructor three params should parse");
    }

    #[test]
    fn test_class_init_constructor_no_params() {
        let result = parse("class Foo { init() { } }");
        assert!(result.is_ok(), "Init no params should parse");
    }

    #[test]
    fn test_class_init_constructor_with_params() {
        let result = parse("class Foo { init(v: i32) { self.v = v } }");
        assert!(result.is_ok(), "Init with params should parse");
    }

    // ============================================================
    // Inheritance variations
    // ============================================================

    #[test]
    fn test_class_extends_one() {
        let result = parse("class Child : Parent { }");
        assert!(result.is_ok(), "Extends one should parse");
    }

    #[test]
    fn test_class_extends_with_trait() {
        let result = parse("class Child : Parent + Trait1 { }");
        assert!(result.is_ok(), "Extends with trait should parse");
    }

    #[test]
    fn test_class_extends_with_two_traits() {
        let result = parse("class Child : Parent + Trait1 + Trait2 { }");
        assert!(result.is_ok(), "Extends with two traits should parse");
    }

    #[test]
    fn test_class_extends_generic_parent() {
        let result = parse("class IntList : List<i32> { }");
        assert!(result.is_ok(), "Extends generic parent should parse");
    }

    // ============================================================
    // Generic class variations
    // ============================================================

    #[test]
    fn test_class_generic_one() {
        let result = parse("class Box<T> { }");
        assert!(result.is_ok(), "One generic should parse");
    }

    #[test]
    fn test_class_generic_two() {
        let result = parse("class Pair<A, B> { }");
        assert!(result.is_ok(), "Two generics should parse");
    }

    #[test]
    fn test_class_generic_three() {
        let result = parse("class Triple<A, B, C> { }");
        assert!(result.is_ok(), "Three generics should parse");
    }

    #[test]
    fn test_class_generic_with_field() {
        let result = parse("class Box<T> { value: T }");
        assert!(result.is_ok(), "Generic with field should parse");
    }

    #[test]
    fn test_class_generic_with_method() {
        let result = parse("class Box<T> { fun get(&self) -> T { self.value } }");
        assert!(result.is_ok(), "Generic with method should parse");
    }

    // ============================================================
    // Visibility combinations
    // ============================================================

    #[test]
    fn test_class_pub_field_only() {
        let result = parse("class Foo { pub x: i32 }");
        assert!(result.is_ok(), "Pub field should parse");
    }

    #[test]
    fn test_class_mut_field_only() {
        let result = parse("class Foo { mut x: i32 }");
        assert!(result.is_ok(), "Mut field should parse");
    }

    #[test]
    fn test_class_pub_method() {
        let result = parse("class Foo { pub fun get(&self) { } }");
        assert!(result.is_ok(), "Pub method should parse");
    }

    #[test]
    fn test_class_pub_static_method() {
        let result = parse("class Foo { pub static fun create() { } }");
        assert!(result.is_ok(), "Pub static method should parse");
    }

    // ============================================================
    // Combined class tests
    // ============================================================

    #[test]
    fn test_class_fields_and_methods() {
        let result = parse("class Point { x: i32, y: i32, fun len(&self) { } }");
        assert!(result.is_ok(), "Fields and methods should parse");
    }

    #[test]
    fn test_class_constructor_and_method() {
        let result = parse("class Foo { new() { } fun get(&self) { } }");
        assert!(result.is_ok(), "Constructor and method should parse");
    }

    #[test]
    fn test_class_all_elements() {
        let result = parse("class Foo { x: i32, new(x: i32) { self.x = x } fun get(&self) -> i32 { self.x } static fun zero() { } }");
        assert!(result.is_ok(), "All elements should parse");
    }

    // ===== Additional coverage tests (Round 104) =====

    // Test 82: Class with async method
    #[test]
    fn test_class_async_method() {
        let result = parse("class Client { async fun fetch(&self) { } }");
        assert!(result.is_ok(), "Async method should parse");
    }

    // Test 83: Class with generic constraint
    #[test]
    fn test_class_generic_constraint() {
        let result = parse("class Container<T: Clone> { value: T }");
        assert!(result.is_ok(), "Generic constraint should parse");
    }

    // Test 84: Class with multiple fields same type
    #[test]
    fn test_class_multiple_same_type_fields() {
        let result = parse("class Vec3 { x: f64, y: f64, z: f64 }");
        assert!(result.is_ok(), "Multiple same type fields should parse");
    }

    // Test 85: Class with method returning self type
    #[test]
    fn test_class_method_returns_self() {
        let result = parse("class Builder { fun with_value(&mut self, v: i32) -> Self { self } }");
        assert!(result.is_ok(), "Method returning Self should parse");
    }

    // Test 86: Class with impl block style method
    #[test]
    fn test_class_impl_style_method() {
        let result = parse("class Foo { fun compute(&self, x: i32, y: i32) -> i32 { x + y } }");
        assert!(result.is_ok(), "Impl style method should parse");
    }

    // Test 87: Class with default field values
    #[test]
    fn test_class_default_field() {
        let result = parse("class Config { debug: bool = false }");
        assert!(result.is_ok(), "Default field value should parse");
    }

    // Test 90: Class method with multiple return types
    #[test]
    fn test_class_method_optional_return() {
        let result = parse("class Cache { fun get(&self, key: str) -> Option<T> { None } }");
        assert!(result.is_ok(), "Optional return type should parse");
    }

    // Test 91: Class with private method
    #[test]
    fn test_class_private_method() {
        let result = parse("class Service { fun internal(&self) { } }");
        assert!(result.is_ok(), "Private method should parse");
    }

    // Test 92: Empty class variations
    #[test]
    fn test_empty_class_with_whitespace() {
        let result = parse("class Empty {\n\n}");
        assert!(result.is_ok(), "Empty class with whitespace should parse");
    }

    // Test 90: Class with constructor and init
    #[test]
    fn test_class_both_constructors() {
        let result = parse("class Dual { new() { } init() { } }");
        assert!(result.is_ok(), "Both constructors should parse");
    }

    // ========================================================================
    // parse_operator_method tests (operator overloading)
    // ========================================================================

    #[test]
    fn test_class_operator_add() {
        let result = parse("class Vec2 { x: f64  y: f64  operator+(self, other: Vec2) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } }");
        assert!(result.is_ok(), "operator+ should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_sub() {
        let result = parse("class Vec2 { x: f64  operator-(self, other: Vec2) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } }");
        assert!(result.is_ok(), "operator- should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_mul() {
        let result = parse("class Vec2 { x: f64  operator*(self, scalar: f64) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } }");
        assert!(result.is_ok(), "operator* should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_div() {
        let result = parse("class Vec2 { x: f64  operator/(self, scalar: f64) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } }");
        assert!(result.is_ok(), "operator/ should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_eq() {
        let result = parse("class Vec2 { x: f64  operator==(self, other: Vec2) -> bool { true } }");
        assert!(result.is_ok(), "operator== should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_ne() {
        let result = parse("class Vec2 { x: f64  operator!=(self, other: Vec2) -> bool { false } }");
        assert!(result.is_ok(), "operator!= should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_lt() {
        let result = parse("class Num { v: i32  operator<(self, other: Num) -> bool { true } }");
        assert!(result.is_ok(), "operator< should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_gt() {
        let result = parse("class Num { v: i32  operator>(self, other: Num) -> bool { false } }");
        assert!(result.is_ok(), "operator> should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_le() {
        let result = parse("class Num { v: i32  operator<=(self, other: Num) -> bool { true } }");
        assert!(result.is_ok(), "operator<= should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_ge() {
        let result = parse("class Num { v: i32  operator>=(self, other: Num) -> bool { false } }");
        assert!(result.is_ok(), "operator>= should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_rem() {
        let result = parse("class Num { v: i32  operator%(self, other: Num) -> Num { Num { v: 0 } } }");
        assert!(result.is_ok(), "operator% should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_index() {
        let result = parse("class Grid { data: Vec<i32>  operator[](self, idx: i32) -> i32 { 0 } }");
        assert!(result.is_ok(), "operator[] should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_operator_no_return_type() {
        let result = parse("class Vec2 { x: f64  operator+(self, other: Vec2) { 0 } }");
        assert!(result.is_ok(), "operator+ without return type should parse");
    }

    #[test]
    fn test_class_multiple_operators() {
        let code = "class Vec2 { x: f64  y: f64  operator+(self, other: Vec2) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } }  operator-(self, other: Vec2) -> Vec2 { Vec2 { x: 0.0, y: 0.0 } } }";
        let result = parse(code);
        assert!(result.is_ok(), "Multiple operators should parse");
    }

    // ============================================================
    // Coverage tests for parse_decorator_argument (classes.rs:446)
    // and parse_decorator_value (classes.rs:419)
    // parse_decorator_argument is called from parse_decorator_args,
    // which is invoked by parse_decorator for decorators INSIDE
    // class bodies (Token::At path in parse_decorator).
    // Top-level @decorators use parse_label_as_decorator instead.
    // ============================================================

    // Direct unit tests for parse_decorator_argument and parse_decorator_value
    use super::{parse_decorator_argument, parse_decorator_value};
    use crate::frontend::parser::ParserState;

    #[test]
    fn test_decorator_argument_direct_string() {
        // parse_decorator_argument: String branch
        let mut state = ParserState::new(r#""hello""#);
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "hello");
    }

    #[test]
    fn test_decorator_argument_direct_identifier_only() {
        // parse_decorator_argument: Identifier branch, no = follows
        let mut state = ParserState::new("myarg");
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "myarg");
    }

    #[test]
    fn test_decorator_argument_direct_key_value_string() {
        // parse_decorator_argument: Identifier + = + String value
        let mut state = ParserState::new(r#"key="value""#);
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), r#"key=value"#);
    }

    #[test]
    fn test_decorator_argument_direct_key_value_integer() {
        // parse_decorator_argument: Identifier + = + Integer value
        let mut state = ParserState::new("count=42");
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "count=42");
    }

    #[test]
    fn test_decorator_argument_direct_key_value_float() {
        // parse_decorator_argument: Identifier + = + Float value
        let mut state = ParserState::new("ratio=3.14");
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        let val = result.unwrap();
        assert!(val.starts_with("ratio="), "Got: {val}");
    }

    #[test]
    fn test_decorator_argument_direct_key_value_bool_true_is_lexed_as_bool() {
        // "true"/"false" are lexed as Token::Bool, not Token::Identifier,
        // so the Identifier guard in parse_decorator_value is unreachable.
        // After key=, the parser sees Token::Bool which doesn't match any branch.
        let mut state = ParserState::new("debug=true");
        let result = parse_decorator_argument(&mut state);
        // This exercises the key= path in parse_decorator_argument,
        // then hits parse_decorator_value error branch (Bool not handled)
        assert!(result.is_err(), "Bool token not handled by parse_decorator_value");
    }

    #[test]
    fn test_decorator_argument_direct_key_value_with_string_as_value() {
        // Use string value after = instead of bool
        let mut state = ParserState::new(r#"verbose="false""#);
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "verbose=false");
    }

    #[test]
    fn test_decorator_argument_direct_error_invalid_token() {
        // parse_decorator_argument: error branch (not String or Identifier)
        let mut state = ParserState::new("42");
        let result = parse_decorator_argument(&mut state);
        assert!(result.is_err(), "Should fail on numeric token");
    }

    #[test]
    fn test_decorator_value_direct_integer() {
        let mut state = ParserState::new("42");
        let result = parse_decorator_value(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "42");
    }

    #[test]
    fn test_decorator_value_direct_float() {
        let mut state = ParserState::new("3.14");
        let result = parse_decorator_value(&mut state);
        assert!(result.is_ok());
    }

    #[test]
    fn test_decorator_value_direct_string() {
        let mut state = ParserState::new(r#""hello""#);
        let result = parse_decorator_value(&mut state);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "hello");
    }

    #[test]
    fn test_decorator_value_direct_bool_true_not_handled() {
        // "true" is lexed as Token::Bool(true), not Token::Identifier("true"),
        // so parse_decorator_value's Identifier guard is unreachable.
        let mut state = ParserState::new("true");
        let result = parse_decorator_value(&mut state);
        // This exercises the error/fallthrough branch
        assert!(result.is_err(), "Bool token not in parse_decorator_value match arms");
    }

    #[test]
    fn test_decorator_value_direct_bool_false_not_handled() {
        let mut state = ParserState::new("false");
        let result = parse_decorator_value(&mut state);
        assert!(result.is_err(), "Bool token not in parse_decorator_value match arms");
    }

    #[test]
    fn test_decorator_value_direct_error() {
        // Not a valid value token
        let mut state = ParserState::new("(");
        let result = parse_decorator_value(&mut state);
        assert!(result.is_err());
    }

    // Integration tests for decorators (via full parse)

    #[test]
    fn test_decorator_on_class_method_inside_body() {
        // This path goes through parse_decorator -> parse_decorator_args
        // -> parse_decorator_argument (the classes.rs code path)
        let code = "class MyClass { @inline fun method(&self) -> i32 { 42 } }";
        let result = parse(code);
        assert!(result.is_ok(), "Decorator on method: {:?}", result.err());
    }

    #[test]
    fn test_decorator_no_args_on_class() {
        let code = "@test class MyClass { }";
        let result = parse(code);
        assert!(result.is_ok(), "Decorator no args: {:?}", result.err());
    }

    #[test]
    fn test_decorator_empty_parens_on_class() {
        let code = "@test() class MyClass { }";
        let result = parse(code);
        assert!(result.is_ok(), "Decorator empty parens: {:?}", result.err());
    }

    #[test]
    fn test_multiple_decorators_on_class() {
        let code = "@serialize @debug class MyClass { }";
        let result = parse(code);
        assert!(result.is_ok(), "Multiple decorators: {:?}", result.err());
    }

    #[test]
    fn test_decorator_with_string_on_class_method() {
        let code = r#"class C { @test("example") fun m(&self) { 42 } }"#;
        let result = parse(code);
        assert!(result.is_ok(), "Decorator with string arg in class: {:?}", result.err());
    }

    #[test]
    fn test_decorator_with_key_value_on_class_method() {
        let code = r#"class C { @config(max=100) fun m(&self) { 42 } }"#;
        let result = parse(code);
        assert!(result.is_ok(), "Decorator with key=value in class: {:?}", result.err());
    }

    // ============================================================
    // Coverage tests for parse_property_accessors (17 uncov, 0%)
    // and parse_property_setter (17 uncov, 0%)
    // ============================================================

    #[test]
    fn test_property_with_getter_only() {
        let code = "class MyClass { property value: i32 { get => 42 } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property with getter only should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_with_setter_only() {
        let code = "class MyClass { property value: i32 { set(v) => self.x = v } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property with setter only should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_with_getter_and_setter() {
        let code = "class MyClass { property value: i32 { get => self.x, set(v) => self.x = v } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property with getter and setter should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_with_setter_and_getter_reversed() {
        let code = "class MyClass { property value: i32 { set(v) => self.x = v, get => self.x } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property with setter first then getter should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_getter_returns_expression() {
        let code = "class Circle { property area: f64 { get => 3.14 * self.r * self.r } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property getter with expression should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_setter_with_param() {
        let code = "class Box { property width: f64 { set(w) => self.w = w } }";
        let result = parse(code);
        assert!(result.is_ok(), "Property setter with param should parse: {:?}", result.err());
    }

    #[test]
    fn test_class_with_multiple_properties() {
        let code = r#"class Point {
            property x: f64 { get => self._x, set(v) => self._x = v }
            property y: f64 { get => self._y }
        }"#;
        let result = parse(code);
        assert!(result.is_ok(), "Class with multiple properties should parse: {:?}", result.err());
    }

    #[test]
    fn test_property_with_method_and_field() {
        let code = r#"class MyClass {
            name: String
            property length: i32 { get => 0 }
            fun greet(&self) -> String { self.name }
        }"#;
        let result = parse(code);
        assert!(result.is_ok(), "Class with field, property and method should parse: {:?}", result.err());
    }