vb6parse 1.0.0

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
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
//! # `Int` Function
//!
//! Returns the integer portion of a number.
//!
//! ## Syntax
//!
//! ```vb
//! Int(number)
//! ```
//!
//! ## Parameters
//!
//! - `number` (Required): Any valid numeric expression. If `number` contains `Null`, `Null` is returned
//!
//! ## Return Value
//!
//! Returns the integer portion of a number:
//! - For positive numbers: Returns the largest integer less than or equal to `number`
//! - For negative numbers: Returns the first negative integer less than or equal to `number`
//! - If `number` is `Null`: Returns `Null`
//! - Return type matches the input type (Integer, Long, Single, Double, Currency, Decimal)
//!
//! ## Remarks
//!
//! The `Int` function truncates toward negative infinity:
//!
//! - Removes the fractional part of a number
//! - For positive numbers, behaves like truncation (same as `Fix`)
//! - For negative numbers, rounds DOWN (toward negative infinity)
//! - `Fix` rounds toward zero (always truncates), `Int` rounds down
//! - `Int`(-8.4) returns -9, `Fix`(-8.4) returns -8
//! - `Int`(8.4) returns 8, `Fix`(8.4) returns 8
//! - Does not round to nearest integer (use `Round` for rounding)
//! - The return type preserves the input numeric type
//! - Commonly used with `Rnd` for generating random integers
//! - For currency calculations, consider using `Round` or `CCur` instead
//!
//! ## Typical Uses
//!
//! 1. **Remove Decimals**: Strip fractional part from numbers
//! 2. **Random Integers**: Generate random integer values with `Rnd`
//! 3. **Array Indices**: Convert floats to valid array indices
//! 4. **Loop Counters**: Ensure integer values for loops
//! 5. **Division Results**: Get whole number quotients
//! 6. **Coordinate Rounding**: Round pixel coordinates
//! 7. **Pagination**: Calculate page numbers
//! 8. **Quantity Calculations**: Ensure whole unit quantities
//!
//! ## Basic Usage Examples
//!
//! ```vb
//! ' Example 1: Remove decimal portion
//! Dim result As Integer
//! result = Int(8.7)
//! Debug.Print result  ' Prints: 8
//!
//! ' Example 2: Negative number behavior
//! Dim result As Integer
//! result = Int(-8.7)
//! Debug.Print result  ' Prints: -9 (rounds down, not toward zero)
//!
//! ' Example 3: Random integer between 1 and 100
//! Dim randomNum As Integer
//! Randomize
//! randomNum = Int(Rnd * 100) + 1
//!
//! ' Example 4: Calculate whole pages
//! Dim totalItems As Long
//! Dim itemsPerPage As Long
//! Dim totalPages As Long
//! totalItems = 47
//! itemsPerPage = 10
//! totalPages = Int(totalItems / itemsPerPage) + 1
//! Debug.Print totalPages  ' Prints: 5
//! ```
//!
//! ## Common Patterns
//!
//! ```vb
//! ' Pattern 1: Random integer in range
//! Function RandomInteger(minValue As Long, maxValue As Long) As Long
//!     Randomize
//!     RandomInteger = Int((maxValue - minValue + 1) * Rnd) + minValue
//! End Function
//!
//! ' Pattern 2: Get whole number portion
//! Function GetWholeNumber(value As Double) As Long
//!     If value >= 0 Then
//!         GetWholeNumber = Int(value)
//!     Else
//!         ' For negative numbers, Int rounds down
//!         ' Use Fix if you want to truncate toward zero
//!         GetWholeNumber = Int(value)
//!     End If
//! End Function
//!
//! ' Pattern 3: Calculate pages needed
//! Function CalculatePages(totalItems As Long, itemsPerPage As Long) As Long
//!     If itemsPerPage <= 0 Then
//!         CalculatePages = 0
//!         Exit Function
//!     End If
//!     
//!     CalculatePages = Int((totalItems - 1) / itemsPerPage) + 1
//! End Function
//!
//! ' Pattern 4: Round down to nearest multiple
//! Function RoundDownToMultiple(value As Double, multiple As Double) As Double
//!     If multiple = 0 Then
//!         RoundDownToMultiple = value
//!     Else
//!         RoundDownToMultiple = Int(value / multiple) * multiple
//!     End If
//! End Function
//!
//! ' Pattern 5: Extract integer part for display
//! Function FormatNumber(value As Double) As String
//!     Dim wholePart As Long
//!     Dim decimalPart As Double
//!     
//!     wholePart = Int(Abs(value))
//!     decimalPart = Abs(value) - wholePart
//!     
//!     FormatNumber = CStr(wholePart) & "." & _
//!                    Format$(decimalPart, "00")
//! End Function
//!
//! ' Pattern 6: Generate random array index
//! Function RandomArrayIndex(arr As Variant) As Long
//!     Dim lowerBound As Long
//!     Dim upperBound As Long
//!     
//!     lowerBound = LBound(arr)
//!     upperBound = UBound(arr)
//!     
//!     RandomArrayIndex = Int((upperBound - lowerBound + 1) * Rnd) + lowerBound
//! End Function
//!
//! ' Pattern 7: Calculate grid position
//! Sub GetGridPosition(pixelX As Double, pixelY As Double, _
//!                     gridSize As Double, _
//!                     ByRef gridX As Long, ByRef gridY As Long)
//!     gridX = Int(pixelX / gridSize)
//!     gridY = Int(pixelY / gridSize)
//! End Sub
//!
//! ' Pattern 8: Divide and get quotient
//! Function IntegerDivision(dividend As Long, divisor As Long) As Long
//!     If divisor = 0 Then
//!         Err.Raise 11, , "Division by zero"
//!     End If
//!     
//!     IntegerDivision = Int(dividend / divisor)
//! End Function
//!
//! ' Pattern 9: Time to whole seconds
//! Function GetWholeSeconds(timeValue As Double) As Long
//!     Dim secondsDecimal As Double
//!     secondsDecimal = timeValue * 86400  ' Convert days to seconds
//!     GetWholeSeconds = Int(secondsDecimal)
//! End Function
//!
//! ' Pattern 10: Percentage to whole number
//! Function GetWholePercent(value As Double, total As Double) As Long
//!     If total = 0 Then
//!         GetWholePercent = 0
//!     Else
//!         GetWholePercent = Int((value / total) * 100)
//!     End If
//! End Function
//! ```
//!
//! ## Advanced Usage Examples
//!
//! ```vb
//! ' Example 1: Random number generator class
//! Public Class RandomNumberGenerator
//!     Private m_initialized As Boolean
//!     
//!     Private Sub EnsureInitialized()
//!         If Not m_initialized Then
//!             Randomize
//!             m_initialized = True
//!         End If
//!     End Sub
//!     
//!     Public Function NextInteger(minValue As Long, maxValue As Long) As Long
//!         EnsureInitialized
//!         
//!         If minValue > maxValue Then
//!             Err.Raise 5, , "minValue cannot be greater than maxValue"
//!         End If
//!         
//!         NextInteger = Int((maxValue - minValue + 1) * Rnd) + minValue
//!     End Function
//!     
//!     Public Function NextDouble() As Double
//!         EnsureInitialized
//!         NextDouble = Rnd
//!     End Function
//!     
//!     Public Function NextBoolean() As Boolean
//!         EnsureInitialized
//!         NextBoolean = (Int(Rnd * 2) = 1)
//!     End Function
//!     
//!     Public Function Shuffle(arr As Variant) As Variant
//!         Dim i As Long
//!         Dim j As Long
//!         Dim temp As Variant
//!         Dim result() As Variant
//!         
//!         EnsureInitialized
//!         
//!         ' Copy array
//!         ReDim result(LBound(arr) To UBound(arr))
//!         For i = LBound(arr) To UBound(arr)
//!             result(i) = arr(i)
//!         Next i
//!         
//!         ' Fisher-Yates shuffle
//!         For i = UBound(result) To LBound(result) + 1 Step -1
//!             j = Int((i - LBound(result) + 1) * Rnd) + LBound(result)
//!             temp = result(i)
//!             result(i) = result(j)
//!             result(j) = temp
//!         Next i
//!         
//!         Shuffle = result
//!     End Function
//! End Class
//!
//! ' Example 2: Pagination calculator
//! Public Class PaginationHelper
//!     Private m_totalItems As Long
//!     Private m_itemsPerPage As Long
//!     
//!     Public Property Let TotalItems(value As Long)
//!         m_totalItems = value
//!     End Property
//!     
//!     Public Property Let ItemsPerPage(value As Long)
//!         If value <= 0 Then
//!             Err.Raise 5, , "ItemsPerPage must be greater than zero"
//!         End If
//!         m_itemsPerPage = value
//!     End Property
//!     
//!     Public Property Get PageCount() As Long
//!         If m_itemsPerPage = 0 Then
//!             PageCount = 0
//!         Else
//!             PageCount = Int((m_totalItems - 1) / m_itemsPerPage) + 1
//!         End If
//!     End Property
//!     
//!     Public Function GetPageStartIndex(pageNumber As Long) As Long
//!         If pageNumber < 1 Or pageNumber > PageCount Then
//!             GetPageStartIndex = -1
//!         Else
//!             GetPageStartIndex = (pageNumber - 1) * m_itemsPerPage
//!         End If
//!     End Function
//!     
//!     Public Function GetPageEndIndex(pageNumber As Long) As Long
//!         Dim startIndex As Long
//!         startIndex = GetPageStartIndex(pageNumber)
//!         
//!         If startIndex = -1 Then
//!             GetPageEndIndex = -1
//!         Else
//!             GetPageEndIndex = startIndex + m_itemsPerPage - 1
//!             If GetPageEndIndex >= m_totalItems Then
//!                 GetPageEndIndex = m_totalItems - 1
//!             End If
//!         End If
//!     End Function
//!     
//!     Public Function GetPageForItem(itemIndex As Long) As Long
//!         If itemIndex < 0 Or itemIndex >= m_totalItems Then
//!             GetPageForItem = -1
//!         Else
//!             GetPageForItem = Int(itemIndex / m_itemsPerPage) + 1
//!         End If
//!     End Function
//! End Class
//!
//! ' Example 3: Grid coordinate mapper
//! Public Class GridMapper
//!     Private m_cellWidth As Double
//!     Private m_cellHeight As Double
//!     
//!     Public Sub Initialize(cellWidth As Double, cellHeight As Double)
//!         m_cellWidth = cellWidth
//!         m_cellHeight = cellHeight
//!     End Sub
//!     
//!     Public Sub PixelToGrid(pixelX As Double, pixelY As Double, _
//!                           ByRef gridX As Long, ByRef gridY As Long)
//!         gridX = Int(pixelX / m_cellWidth)
//!         gridY = Int(pixelY / m_cellHeight)
//!     End Sub
//!     
//!     Public Sub GridToPixel(gridX As Long, gridY As Long, _
//!                           ByRef pixelX As Double, ByRef pixelY As Double)
//!         pixelX = gridX * m_cellWidth
//!         pixelY = gridY * m_cellHeight
//!     End Sub
//!     
//!     Public Function SnapToGrid(pixelX As Double, pixelY As Double) As Variant
//!         Dim gridX As Long
//!         Dim gridY As Long
//!         Dim snappedX As Double
//!         Dim snappedY As Double
//!         
//!         PixelToGrid pixelX, pixelY, gridX, gridY
//!         GridToPixel gridX, gridY, snappedX, snappedY
//!         
//!         SnapToGrid = Array(snappedX, snappedY)
//!     End Function
//! End Class
//!
//! ' Example 4: Dice roller simulator
//! Public Class DiceRoller
//!     Public Function Roll(sides As Long, Optional count As Long = 1) As Long
//!         Dim i As Long
//!         Dim total As Long
//!         
//!         Randomize
//!         total = 0
//!         
//!         For i = 1 To count
//!             total = total + Int(Rnd * sides) + 1
//!         Next i
//!         
//!         Roll = total
//!     End Function
//!     
//!     Public Function RollMultiple(sides As Long, count As Long) As Collection
//!         Dim i As Long
//!         Dim result As New Collection
//!         
//!         Randomize
//!         
//!         For i = 1 To count
//!             result.Add Int(Rnd * sides) + 1
//!         Next i
//!         
//!         Set RollMultiple = result
//!     End Function
//!     
//!     Public Function RollWithAdvantage(sides As Long) As Long
//!         Dim roll1 As Long
//!         Dim roll2 As Long
//!         
//!         Randomize
//!         roll1 = Int(Rnd * sides) + 1
//!         roll2 = Int(Rnd * sides) + 1
//!         
//!         RollWithAdvantage = IIf(roll1 > roll2, roll1, roll2)
//!     End Function
//! End Class
//! ```
//!
//! ## Error Handling
//!
//! The `Int` function can raise errors or return `Null`:
//!
//! - **Type Mismatch (Error 13)**: If `number` is not a numeric expression
//! - **Invalid use of Null (Error 94)**: If `number` is `Null` and result is assigned to non-Variant
//! - **Overflow (Error 6)**: If result exceeds the range of the target data type
//!
//! ```vb
//! On Error GoTo ErrorHandler
//! Dim result As Long
//! Dim value As Double
//!
//! value = 12.75
//! result = Int(value)
//!
//! Debug.Print "Integer portion: " & result
//! Exit Sub
//!
//! ErrorHandler:
//!     MsgBox "Error in Int: " & Err.Description, vbCritical
//! ```
//!
//! ## Performance Considerations
//!
//! - **Fast Operation**: `Int` is a very fast built-in function
//! - **Type Preservation**: Return type matches input type
//! - **No Rounding**: Faster than `Round` (no complex calculation)
//! - **Alternative**: For truncation toward zero, `Fix` is equivalent for positive numbers
//! - **Currency**: For financial calculations, consider `Round` or `CCur`
//!
//! ## Best Practices
//!
//! 1. **Understand Behavior**: Know that `Int` rounds DOWN (toward negative infinity)
//! 2. **Fix vs Int**: Use `Fix` for truncation toward zero, `Int` for floor operation
//! 3. **Random Numbers**: Always Randomize before using `Rnd` with `Int`
//! 4. **Type Awareness**: Be aware of return type matching input type
//! 5. **Null Handling**: Use Variant if input might be `Null`
//! 6. **Array Bounds**: Ensure `Int` result is within array bounds
//! 7. **Division**: For integer division, consider using \ operator instead
//!
//! ## Comparison with Other Functions
//!
//! | Function | Behavior | Example |
//! |----------|----------|---------|
//! | `Int` | Rounds down (floor) | Int(-8.7) = -9 |
//! | `Fix` | Truncates toward zero | Fix(-8.7) = -8 |
//! | `Round` | Rounds to nearest | Round(-8.7) = -9 |
//! | `CLng` | Converts to Long with rounding | CLng(-8.7) = -9 |
//! | `CInt` | Converts to Integer with rounding | CInt(-8.7) = -9 |
//! | \ | Integer division | -87 \ 10 = -8 |
//!
//! ## Platform and Version Notes
//!
//! - Available in all VB6 versions
//! - Consistent behavior across platforms
//! - Return type matches input numeric type
//! - Different from many languages `int()` which truncates toward zero
//! - Equivalent to `Math.floor()` in many other languages
//!
//! ## Limitations
//!
//! - Does not round to nearest (use Round for that)
//! - Behavior with negative numbers can be unexpected (use Fix for truncation)
//! - Return type depends on input type (can cause overflow)
//! - Cannot specify decimal places (always removes all decimals)
//! - No control over rounding direction (always down)
//!
//! ## Related Functions
//!
//! - `Fix`: Returns integer portion, truncating toward zero
//! - `Round`: Rounds to nearest integer or specified decimal places
//! - `CInt`: Converts to Integer with rounding
//! - `CLng`: Converts to Long with rounding
//! - `Rnd`: Random number generator (often used with Int)
//! - `\`: Integer division operator

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

    #[test]
    fn int_basic() {
        let source = r"
Sub Test()
    result = Int(8.7)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_negative() {
        let source = r"
Sub Test()
    result = Int(-8.7)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_random() {
        let source = r"
Sub Test()
    randomNum = Int(Rnd * 100) + 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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_if_statement() {
        let source = r#"
Sub Test()
    If Int(value) > 10 Then
        Debug.Print "Greater than 10"
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_function_return() {
        let source = r"
Function GetWhole(value As Double) As Long
    GetWhole = Int(value)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_division() {
        let source = r"
Sub Test()
    pages = Int(totalItems / itemsPerPage) + 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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_comparison() {
        let source = r#"
Sub Test()
    If Int(price) = expectedPrice Then
        MsgBox "Price matches"
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_select_case() {
        let source = r#"
Sub Test()
    Select Case Int(score / 10)
        Case 10, 9
            grade = "A"
        Case 8
            grade = "B"
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_for_loop() {
        let source = r"
Sub Test()
    Dim i As Long
    For i = 1 To Int(maxValue)
        Debug.Print i
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_debug_print() {
        let source = r#"
Sub Test()
    Debug.Print "Integer part: " & Int(value)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_array_assignment() {
        let source = r"
Sub Test()
    wholeNumbers(i) = Int(decimals(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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_property_assignment() {
        let source = r"
Sub Test()
    obj.WholeValue = Int(obj.DecimalValue)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_in_class() {
        let source = r"
Private Sub Class_Initialize()
    m_wholePart = Int(m_value)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_with_statement() {
        let source = r"
Sub Test()
    With calculator
        .WholeResult = Int(.DecimalResult)
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_function_argument() {
        let source = r"
Sub Test()
    Call ProcessInteger(Int(value))
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_concatenation() {
        let source = r#"
Sub Test()
    message = "Whole part: " & Int(number)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_math_expression() {
        let source = r"
Sub Test()
    gridX = Int(pixelX / gridSize)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_iif() {
        let source = r#"
Sub Test()
    result = IIf(Int(value) > 0, "Positive", "Zero or Negative")
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Integer value: " & Int(value)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_collection_add() {
        let source = r"
Sub Test()
    numbers.Add Int(values(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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_boolean_expression() {
        let source = r"
Sub Test()
    isValid = Int(value) >= minValue And Int(value) <= maxValue
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_nested_call() {
        let source = r"
Sub Test()
    result = CStr(Int(value))
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_do_loop() {
        let source = r"
Sub Test()
    Do While Int(counter) < limit
        counter = counter + 0.5
    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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_abs() {
        let source = r"
Sub Test()
    wholePart = Int(Abs(value))
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_array_index() {
        let source = r"
Sub Test()
    index = Int(Rnd * arraySize)
    item = items(index)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_multiple_operations() {
        let source = r"
Sub Test()
    quotient = Int(dividend / divisor)
    remainder = dividend - (quotient * divisor)
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn int_parentheses() {
        let source = r"
Sub Test()
    value = (Int(number))
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/int");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}