vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
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
//! # `Atn` Function
//!
//! Returns a `Double` specifying the arctangent of a number.
//!
//! ## Syntax
//!
//! ```vb
//! Atn(number)
//! ```
//!
//! ## Parameters
//!
//! - `number` - Required. A `Double` or any valid numeric expression. The tangent value for which you want the angle.
//!
//! ## Return Value
//!
//! Returns a `Double` representing the arctangent of the number in radians.
//!
//! - The result is in the range -π/2 to π/2 radians (-90° to 90°)
//! - To convert from radians to degrees, multiply by 180/π (approximately 57.2957795130823)
//! - To convert from degrees to radians, multiply by π/180 (approximately 0.0174532925199433)
//!
//! ## Remarks
//!
//! The `Atn` function takes the ratio of two sides of a right triangle (opposite/adjacent) and
//! returns the corresponding angle in radians. This is the inverse of the tangent function.
//!
//! ### Important Notes
//!
//! 1. **Return Type**: Always returns `Double` regardless of input type
//! 2. **Radians**: Result is always in radians, not degrees
//! 3. **Range**: Return value is between -π/2 and π/2 (-1.5708 to 1.5708 radians)
//! 4. **Ratio Input**: The argument represents the tangent (opposite/adjacent) of the angle
//! 5. **Inverse Function**: `Atn` is the inverse of `Tan` (`Atn(Tan(x)) = x` for x in valid range)
//!
//! ### Mathematical Relationship
//!
//! ```vb
//! ' For a right triangle:
//! angle = Atn(opposite / adjacent)
//!
//! ' Converting between functions:
//! Tan(Atn(x)) = x    ' Always true
//! Atn(Tan(x)) = x    ' True when -π/2 < x < π/2
//! ```
//!
//! ### Special Values
//!
//! - `Atn(0)` returns 0 (angle is 0 radians or 0°)
//! - `Atn(1)` returns π/4 (approximately 0.785398, which is 45°)
//! - `Atn(-1)` returns -π/4 (approximately -0.785398, which is -45°)
//! - Large positive values approach π/2 (90°)
//! - Large negative values approach -π/2 (-90°)
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```vb
//! Dim angle As Double
//! angle = Atn(1)              ' Returns π/4 (approx 0.785398) = 45°
//! angle = Atn(0)              ' Returns 0 = 0°
//! angle = Atn(-1)             ' Returns -π/4 (approx -0.785398) = -45°
//! angle = Atn(1.732050808)    ' Returns π/3 (approx 1.047198) = 60°
//! ```
//!
//! ### Converting to Degrees
//!
//! ```vb
//! Function AtnDegrees(tangent As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     AtnDegrees = Atn(tangent) * 180 / PI
//! End Function
//!
//! ' Usage:
//! angle = AtnDegrees(1)       ' Returns 45 degrees
//! ```
//!
//! ### Calculating Angle from Triangle Sides
//!
//! ```vb
//! Function AngleFromSides(opposite As Double, adjacent As Double) As Double
//!     ' Returns angle in radians
//!     AngleFromSides = Atn(opposite / adjacent)
//! End Function
//!
//! ' For a right triangle with opposite=3, adjacent=4:
//! angle = AngleFromSides(3, 4)    ' Returns angle in radians
//! ```
//!
//! ### Calculating π
//!
//! ```vb
//! Function CalculatePi() As Double
//!     ' Since Atn(1) = π/4, then 4 * Atn(1) = π
//!     CalculatePi = 4 * Atn(1)
//! End Function
//! ```
//!
//! ### Full Circle Angle Calculation (Atn2 Emulation)
//!
//! ```vb
//! Function Atn2(y As Double, x As Double) As Double
//!     ' Emulates atan2 function for full circle (-π to π)
//!     Const PI As Double = 3.14159265358979
//!     
//!     If x > 0 Then
//!         Atn2 = Atn(y / x)
//!     ElseIf x < 0 Then
//!         If y >= 0 Then
//!             Atn2 = Atn(y / x) + PI
//!         Else
//!             Atn2 = Atn(y / x) - PI
//!         End If
//!     ElseIf y > 0 Then
//!         Atn2 = PI / 2
//!     ElseIf y < 0 Then
//!         Atn2 = -PI / 2
//!     Else
//!         Atn2 = 0  ' Undefined, but return 0
//!     End If
//! End Function
//! ```
//!
//! ## Common Patterns
//!
//! ### 1. Slope to Angle Conversion
//!
//! ```vb
//! Dim slope As Double
//! Dim angleRadians As Double
//! Dim angleDegrees As Double
//!
//! slope = 0.5  ' Rise over run
//! angleRadians = Atn(slope)
//! angleDegrees = angleRadians * 180 / (4 * Atn(1))
//! ```
//!
//! ### 2. Direction Calculation
//!
//! ```vb
//! Function GetDirection(deltaX As Double, deltaY As Double) As Double
//!     ' Returns angle in degrees (0-360)
//!     Const PI As Double = 3.14159265358979
//!     Dim angle As Double
//!     
//!     If deltaX = 0 Then
//!         If deltaY > 0 Then
//!             angle = 90
//!         ElseIf deltaY < 0 Then
//!             angle = 270
//!         Else
//!             angle = 0
//!         End If
//!     Else
//!         angle = Atn(deltaY / deltaX) * 180 / PI
//!         If deltaX < 0 Then angle = angle + 180
//!         If angle < 0 Then angle = angle + 360
//!     End If
//!     
//!     GetDirection = angle
//! End Function
//! ```
//!
//! ### 3. Distance and Angle from Origin
//!
//! ```vb
//! Sub GetPolarCoordinates(x As Double, y As Double, _
//!                         distance As Double, angle As Double)
//!     distance = Sqr(x * x + y * y)
//!     
//!     If x = 0 Then
//!         If y > 0 Then
//!             angle = 90
//!         Else
//!             angle = 270
//!         End If
//!     Else
//!         angle = Atn(y / x) * 180 / (4 * Atn(1))
//!         If x < 0 Then angle = angle + 180
//!     End If
//! End Sub
//! ```
//!
//! ### 4. Graphics Rotation
//!
//! ```vb
//! Function RotatePoint(x As Double, y As Double, _
//!                     centerX As Double, centerY As Double, _
//!                     angleDegrees As Double)
//!     Const PI As Double = 3.14159265358979
//!     Dim angleRadians As Double
//!     Dim currentAngle As Double
//!     Dim distance As Double
//!     Dim newAngle As Double
//!     
//!     ' Get current angle and distance from center
//!     distance = Sqr((x - centerX) ^ 2 + (y - centerY) ^ 2)
//!     currentAngle = Atn((y - centerY) / (x - centerX))
//!     
//!     ' Calculate new angle
//!     angleRadians = angleDegrees * PI / 180
//!     newAngle = currentAngle + angleRadians
//!     
//!     ' Calculate new position
//!     x = centerX + distance * Cos(newAngle)
//!     y = centerY + distance * Sin(newAngle)
//! End Function
//! ```
//!
//! ### 5. Navigation Bearing
//!
//! ```vb
//! Function CalculateBearing(lat1 As Double, lon1 As Double, _
//!                          lat2 As Double, lon2 As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     Dim dLon As Double
//!     Dim y As Double
//!     Dim x As Double
//!     Dim bearing As Double
//!     
//!     dLon = lon2 - lon1
//!     y = Sin(dLon) * Cos(lat2)
//!     x = Cos(lat1) * Sin(lat2) - Sin(lat1) * Cos(lat2) * Cos(dLon)
//!     bearing = Atn(y / x) * 180 / PI
//!     
//!     ' Normalize to 0-360
//!     CalculateBearing = (bearing + 360) Mod 360
//! End Function
//! ```
//!
//! ### 6. Inverse Trigonometry Relationships
//!
//! ```vb
//! ' Calculate arcsine using Atn
//! Function Asin(x As Double) As Double
//!     Asin = Atn(x / Sqr(1 - x * x))
//! End Function
//!
//! ' Calculate arccosine using Atn
//! Function Acos(x As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     Acos = PI / 2 - Atn(x / Sqr(1 - x * x))
//! End Function
//! ```
//!
//! ### 7. Tangent Line Slope
//!
//! ```vb
//! Function GetTangentAngle(x1 As Double, y1 As Double, _
//!                         x2 As Double, y2 As Double) As Double
//!     Dim slope As Double
//!     Const PI As Double = 3.14159265358979
//!     
//!     If x2 = x1 Then
//!         GetTangentAngle = 90  ' Vertical line
//!     Else
//!         slope = (y2 - y1) / (x2 - x1)
//!         GetTangentAngle = Atn(slope) * 180 / PI
//!     End If
//! End Function
//! ```
//!
//! ### 8. Game Development - Projectile Angle
//!
//! ```vb
//! Function AimAngle(shooterX As Double, shooterY As Double, _
//!                   targetX As Double, targetY As Double) As Double
//!     Const PI As Double = 3.14159265358979
//!     Dim deltaX As Double
//!     Dim deltaY As Double
//!     
//!     deltaX = targetX - shooterX
//!     deltaY = targetY - shooterY
//!     
//!     If deltaX = 0 Then
//!         If deltaY > 0 Then
//!             AimAngle = 90
//!         Else
//!             AimAngle = 270
//!         End If
//!     Else
//!         AimAngle = Atn(deltaY / deltaX) * 180 / PI
//!         If deltaX < 0 Then AimAngle = AimAngle + 180
//!         If AimAngle < 0 Then AimAngle = AimAngle + 360
//!     End If
//! End Function
//! ```
//!
//! ## Common Trigonometric Values
//!
//! | Angle (Degrees) | Angle (Radians) | Tangent | Atn(Tangent) |
//! |-----------------|-----------------|---------|--------------|
//! | 0°              | 0               | 0       | 0            |
//! | 30°             | π/6 ≈ 0.524     | 0.577   | π/6          |
//! | 45°             | π/4 ≈ 0.785     | 1       | π/4          |
//! | 60°             | π/3 ≈ 1.047     | 1.732   | π/3          |
//! | 90°             | π/2 ≈ 1.571     | ∞       | π/2 (limit)  |
//!
//! ## Type Conversion
//!
//! | Input Type | Converted To | Example |
//! |------------|--------------|---------|
//! | `Integer`  | `Double`     | Atn(1) → Atn(1.0) |
//! | `Long`     | `Double`     | Atn(10&) → Atn(10.0) |
//! | `Single`   | `Double`     | Atn(1.5!) → Atn(1.5) |
//! | `Double`   | `Double`     | Atn(1.5#) → 1.5 |
//! | `Currency` | `Double`     | Atn(100@) → Atn(100.0) |
//! | `Variant`  | `Double`     | Depends on content |
//!
//! ## Error Conditions
//!
//! - **Type Mismatch**: If the argument cannot be converted to a numeric value
//! - **No overflow**: Unlike some functions, `Atn` cannot overflow as it's bounded to ±π/2
//!
//! ## Related Functions
//!
//! - `Tan`: Returns the tangent of an angle (inverse of `Atn`)
//! - `Sin`: Returns the sine of an angle
//! - `Cos`: Returns the cosine of an angle
//! - `Sqr`: Returns the square root (used with `Atn` to calculate other inverse trig functions)
//! - `Abs`: Returns absolute value (useful in angle calculations)
//!
//! ## Performance Notes
//!
//! - `Atn` is a fast intrinsic function
//! - Implemented using CPU floating-point instructions
//! - No significant performance difference between `Integer`, `Long`, or `Double` arguments
//! - For repeated π calculations, cache the value of 4 * `Atn`(1) rather than recalculating
//!
//! ## Parsing Notes
//!
//! The `Atn` function is not a reserved keyword in VB6. It is parsed as a regular
//! function call (`CallExpression`). This module exists primarily for documentation
//! purposes and to provide a comprehensive test suite that validates the parser
//! correctly handles `Atn` function calls in various contexts.

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn atn_simple() {
        let source = r"
Sub Test()
    angle = Atn(1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_zero() {
        let source = r"
Sub Test()
    result = Atn(0)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_negative() {
        let source = r"
Sub Test()
    angle = Atn(-1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_variable() {
        let source = r"
Sub Test()
    angle = Atn(tangentValue)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_calculate_pi() {
        let source = r"
Sub Test()
    pi = 4 * Atn(1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_to_degrees() {
        let source = r"
Sub Test()
    degrees = Atn(ratio) * 180 / (4 * Atn(1))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_if_statement() {
        let source = r#"
Sub Test()
    If Atn(slope) > 0.785 Then
        Print "Angle > 45 degrees"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_for_loop() {
        let source = r"
Sub Test()
    For i = 0 To 10
        angle = Atn(i / 10)
    Next i
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_division() {
        let source = r"
Sub Test()
    angle = Atn(opposite / adjacent)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_sqr() {
        let source = r"
Sub Test()
    asinValue = Atn(x / Sqr(1 - x * x))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_case_insensitive() {
        let source = r"
Sub Test()
    a = ATN(1)
    b = atn(1)
    c = AtN(1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_select_case() {
        let source = r#"
Sub Test()
    Select Case Atn(value)
        Case Is > 0.5
            Print "High"
        Case Else
            Print "Low"
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_while_loop() {
        let source = r"
Sub Test()
    While Atn(counter) < 1.5
        counter = counter + 0.1
    Wend
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_do_loop() {
        let source = r"
Sub Test()
    Do While Atn(x) < threshold
        x = x + step
    Loop
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_property_access() {
        let source = r"
Sub Test()
    angle = Atn(Me.Slope)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_array_access() {
        let source = r"
Sub Test()
    angles(i) = Atn(tangents(i))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_nested_calls() {
        let source = r"
Sub Test()
    result = Atn(Tan(angle))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_function() {
        let source = r"
Function AtnDegrees(x As Double) As Double
    AtnDegrees = Atn(x) * 180 / (4 * Atn(1))
End Function
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_whitespace() {
        let source = r"
Sub Test()
    angle = Atn  (  1  )
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_with_line_continuation() {
        let source = r"
Sub Test()
    angle = Atn _
        (tangent)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_multiple_on_line() {
        let source = r"
Sub Test()
    a = Atn(0): b = Atn(1): c = Atn(-1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_with_block() {
        let source = r"
Sub Test()
    With Triangle
        angle = Atn(.Opposite / .Adjacent)
    End With
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_in_print() {
        let source = r"
Sub Test()
    Print Atn(1)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_module_level() {
        let source = r"Const PI As Double = 4 * Atn(1)";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn atn_complex_expression() {
        let source = r"
Sub Test()
    bearing = (Atn(deltaY / deltaX) * 180 / pi + 360) Mod 360
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings.set_snapshot_path("../../../../../snapshots/syntax/library/functions/math/atn");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}