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
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
//! # `Trim$` Function
//!
//! The `Trim$` function in Visual Basic 6 returns a string with both leading and trailing spaces
//! removed. The dollar sign (`$`) suffix indicates that this function always returns a `String`
//! type, never a `Variant`.
//!
//! ## Syntax
//!
//! ```vb6
//! Trim$(string)
//! ```
//!
//! ## Parameters
//!
//! - `string` - Required. Any valid string expression. If `string` contains `Null`, `Null` is returned.
//!
//! ## Return Value
//!
//! Returns a `String` with all leading and trailing space characters (ASCII 32) removed from `string`.
//!
//! ## Behavior and Characteristics
//!
//! ### Space Removal
//!
//! - Removes both leading (left-side) and trailing (right-side) spaces
//! - Only removes space characters (ASCII character 32)
//! - Does not remove tabs, newlines, or other whitespace characters
//! - If the string contains only spaces, returns an empty string ("")
//! - Preserves spaces in the middle of the string
//!
//! ### Type Differences: `Trim$` vs `Trim`
//!
//! - `Trim$`: Always returns `String` type (never `Variant`)
//! - `Trim`: Returns `Variant` (can propagate `Null` values)
//! - Use `Trim$` when you need guaranteed `String` return type
//! - Use `Trim` when working with potentially `Null` values
//!
//! ## Common Usage Patterns
//!
//! ### 1. Clean User Input
//!
//! ```vb6
//! Function CleanInput(userInput As String) As String
//!     CleanInput = Trim$(userInput)
//! End Function
//!
//! Dim cleaned As String
//! cleaned = CleanInput("  Hello World  ")  ' Returns "Hello World"
//! ```
//!
//! ### 2. Process Text File Lines
//!
//! ```vb6
//! Function ReadCleanLine(fileNum As Integer) As String
//!     Dim rawLine As String
//!     Line Input #fileNum, rawLine
//!     ReadCleanLine = Trim$(rawLine)
//! End Function
//! ```
//!
//! ### 3. Validate Non-Empty Input
//!
//! ```vb6
//! Function IsValidInput(input As String) As Boolean
//!     IsValidInput = (Len(Trim$(input)) > 0)
//! End Function
//!
//! If IsValidInput(txtName.Text) Then
//!     ' Process the input
//! Else
//!     MsgBox "Please enter a value"
//! End If
//! ```
//!
//! ### 4. String Comparison
//!
//! ```vb6
//! Function CompareValues(value1 As String, value2 As String) As Boolean
//!     ' Compare strings ignoring leading/trailing spaces
//!     CompareValues = (Trim$(value1) = Trim$(value2))
//! End Function
//! ```
//!
//! ### 5. Database Field Cleaning
//!
//! ```vb6
//! Function GetFieldValue(rs As Recordset, fieldName As String) As String
//!     If Not IsNull(rs.Fields(fieldName).Value) Then
//!         GetFieldValue = Trim$(rs.Fields(fieldName).Value & "")
//!     Else
//!         GetFieldValue = ""
//!     End If
//! End Function
//! ```
//!
//! ### 6. Configuration File Parsing
//!
//! ```vb6
//! Function ParseConfigLine(configLine As String) As String
//!     Dim equalPos As Integer
//!     equalPos = InStr(configLine, "=")
//!     If equalPos > 0 Then
//!         ParseConfigLine = Trim$(Mid$(configLine, equalPos + 1))
//!     Else
//!         ParseConfigLine = ""
//!     End If
//! End Function
//! ```
//!
//! ### 7. Clean Array Elements
//!
//! ```vb6
//! Sub CleanStringArray(arr() As String)
//!     Dim i As Integer
//!     For i = LBound(arr) To UBound(arr)
//!         arr(i) = Trim$(arr(i))
//!     Next i
//! End Sub
//! ```
//!
//! ### 8. Form Input Processing
//!
//! ```vb6
//! Sub ProcessForm()
//!     Dim userName As String
//!     Dim userEmail As String
//!     
//!     userName = Trim$(txtName.Text)
//!     userEmail = Trim$(txtEmail.Text)
//!     
//!     If Len(userName) > 0 And Len(userEmail) > 0 Then
//!         SaveUserData userName, userEmail
//!     End If
//! End Sub
//! ```
//!
//! ### 9. CSV Field Processing
//!
//! ```vb6
//! Function ParseCSVField(field As String) As String
//!     ' Remove quotes and trim spaces
//!     Dim cleaned As String
//!     cleaned = field
//!     If Left$(cleaned, 1) = """" Then cleaned = Mid$(cleaned, 2)
//!     If Right$(cleaned, 1) = """" Then cleaned = Left$(cleaned, Len(cleaned) - 1)
//!     ParseCSVField = Trim$(cleaned)
//! End Function
//! ```
//!
//! ### 10. Search Query Preparation
//!
//! ```vb6
//! Function PrepareSearchQuery(query As String) As String
//!     Dim cleaned As String
//!     cleaned = Trim$(query)
//!     ' Remove multiple spaces
//!     While InStr(cleaned, "  ") > 0
//!         cleaned = Replace$(cleaned, "  ", " ")
//!     Wend
//!     PrepareSearchQuery = cleaned
//! End Function
//! ```
//!
//! ## Related Functions
//!
//! - `Trim()` - Returns a `Variant` with leading and trailing spaces removed (can handle `Null`)
//! - `LTrim$()` - Removes only leading (left-side) spaces from a string
//! - `RTrim$()` - Removes only trailing (right-side) spaces from a string
//! - `Left$()` - Returns a specified number of characters from the left side
//! - `Right$()` - Returns a specified number of characters from the right side
//! - `Len()` - Returns the length of a string
//! - `Space$()` - Creates a string consisting of the specified number of spaces
//!
//! ## Best Practices
//!
//! ### When to Use `Trim$` vs `LTrim$` vs `RTrim$`
//!
//! ```vb6
//! Dim text As String
//! text = "  Hello  "
//!
//! Debug.Print Trim$(text)   ' "Hello" (both sides trimmed)
//! Debug.Print LTrim$(text)  ' "Hello  " (left side only)
//! Debug.Print RTrim$(text)  ' "  Hello" (right side only)
//! ```
//!
//! ### Use for User Input Validation
//!
//! ```vb6
//! Function ValidateInput(input As String) As Boolean
//!     ' Check if input is meaningful after trimming
//!     Dim cleaned As String
//!     cleaned = Trim$(input)
//!     
//!     If Len(cleaned) = 0 Then
//!         MsgBox "Input cannot be empty or only spaces"
//!         ValidateInput = False
//!     Else
//!         ValidateInput = True
//!     End If
//! End Function
//! ```
//!
//! ### Combine with Other String Functions
//!
//! ```vb6
//! Function NormalizeText(text As String) As String
//!     Dim result As String
//!     result = Trim$(text)
//!     result = UCase$(result)  ' Convert to uppercase
//!     NormalizeText = result
//! End Function
//! ```
//!
//! ### Handle Null Values Safely
//!
//! ```vb6
//! Function SafeTrim(value As Variant) As String
//!     If IsNull(value) Then
//!         SafeTrim = ""
//!     Else
//!         SafeTrim = Trim$(CStr(value))
//!     End If
//! End Function
//! ```
//!
//! ## Performance Considerations
//!
//! - `Trim$` is very efficient and lightweight
//! - Performs a single pass from both ends of the string
//! - More efficient than calling `LTrim$` and `RTrim$` separately
//! - No performance penalty for strings without leading/trailing spaces
//!
//! ```vb6
//! ' Efficient: single Trim$ call
//! Dim cleaned As String
//! cleaned = Trim$(input)
//!
//! ' Less efficient: two function calls
//! cleaned = LTrim$(RTrim$(input))
//!
//! ' Use Trim$ instead of the above
//! ```
//!
//! ## Common Pitfalls
//!
//! ### 1. Only Removes Spaces (ASCII 32)
//!
//! ```vb6
//! Dim text As String
//! text = vbTab & "Hello" & vbTab  ' Tabs at both ends
//!
//! ' Trim$ does NOT remove tabs
//! Debug.Print Trim$(text)  ' Still has tabs!
//!
//! ' To remove all whitespace, use custom function
//! Function TrimAllWhitespace(s As String) As String
//!     Dim i As Integer, j As Integer
//!     
//!     ' Trim from left
//!     For i = 1 To Len(s)
//!         Select Case Mid$(s, i, 1)
//!             Case " ", vbTab, vbCr, vbLf
//!                 ' Continue
//!             Case Else
//!                 Exit For
//!         End Select
//!     Next i
//!     
//!     ' Trim from right
//!     For j = Len(s) To 1 Step -1
//!         Select Case Mid$(s, j, 1)
//!             Case " ", vbTab, vbCr, vbLf
//!                 ' Continue
//!             Case Else
//!                 Exit For
//!         End Select
//!     Next j
//!     
//!     If i <= j Then
//!         TrimAllWhitespace = Mid$(s, i, j - i + 1)
//!     Else
//!         TrimAllWhitespace = ""
//!     End If
//! End Function
//! ```
//!
//! ### 2. Null Value Handling
//!
//! ```vb6
//! ' Trim$ with Null causes runtime error
//! Dim result As String
//! result = Trim$(nullValue)  ' ERROR if nullValue is Null
//!
//! ' Protect against Null
//! If Not IsNull(value) Then
//!     result = Trim$(value)
//! Else
//!     result = ""
//! End If
//! ```
//!
//! ### 3. Empty String vs Spaces-Only String
//!
//! ```vb6
//! Dim input As String
//! input = "     "  ' Only spaces
//!
//! ' Trim$ returns empty string
//! Debug.Print Len(Trim$(input))  ' 0
//!
//! ' Check for meaningful content
//! If Len(Trim$(input)) = 0 Then
//!     Debug.Print "No content"
//! End If
//! ```
//!
//! ### 4. Database Field Assumptions
//!
//! ```vb6
//! ' Wrong: not handling Null
//! value = Trim$(rs!TextField)  ' May error if field is Null
//!
//! ' Better: handle Null explicitly
//! If IsNull(rs!TextField) Then
//!     value = ""
//! Else
//!     value = Trim$(rs!TextField & "")
//! End If
//! ```
//!
//! ### 5. Case Sensitivity
//!
//! ```vb6
//! ' Trim$ does not change case
//! Debug.Print Trim$("  HELLO  ")  ' "HELLO" (not "hello")
//!
//! ' Combine with case conversion if needed
//! Debug.Print UCase$(Trim$("  hello  "))  ' "HELLO"
//! Debug.Print LCase$(Trim$("  HELLO  "))  ' "hello"
//! ```
//!
//! ### 6. Non-Breaking Spaces
//!
//! ```vb6
//! ' Trim$ only removes regular spaces (ASCII 32)
//! ' Non-breaking spaces (Chr$(160)) are NOT removed
//! Dim text As String
//! text = Chr$(160) & "Hello" & Chr$(160)
//! Debug.Print Trim$(text)  ' Still has Chr$(160) at both ends
//! ```
//!
//! ## Practical Examples
//!
//! ### Processing INI File Values
//!
//! ```vb6
//! Function GetINIValue(section As String, key As String, fileName As String) As String
//!     Dim fileNum As Integer
//!     Dim currentLine As String
//!     Dim inSection As Boolean
//!     Dim equalPos As Integer
//!     Dim lineKey As String
//!     
//!     fileNum = FreeFile
//!     Open fileName For Input As #fileNum
//!     
//!     While Not EOF(fileNum)
//!         Line Input #fileNum, currentLine
//!         currentLine = Trim$(currentLine)
//!         
//!         If currentLine = "[" & section & "]" Then
//!             inSection = True
//!         ElseIf Left$(currentLine, 1) = "[" Then
//!             inSection = False
//!         ElseIf inSection Then
//!             equalPos = InStr(currentLine, "=")
//!             If equalPos > 0 Then
//!                 lineKey = Trim$(Left$(currentLine, equalPos - 1))
//!                 If lineKey = key Then
//!                     GetINIValue = Trim$(Mid$(currentLine, equalPos + 1))
//!                     Close #fileNum
//!                     Exit Function
//!                 End If
//!             End If
//!         End If
//!     Wend
//!     
//!     Close #fileNum
//!     GetINIValue = ""
//! End Function
//! ```
//!
//! ### Form Validation
//!
//! ```vb6
//! Function ValidateForm() As Boolean
//!     Dim errors As String
//!     
//!     If Len(Trim$(txtName.Text)) = 0 Then
//!         errors = errors & "Name is required" & vbCrLf
//!     End If
//!     
//!     If Len(Trim$(txtEmail.Text)) = 0 Then
//!         errors = errors & "Email is required" & vbCrLf
//!     End If
//!     
//!     If Len(errors) > 0 Then
//!         MsgBox errors, vbExclamation
//!         ValidateForm = False
//!     Else
//!         ValidateForm = True
//!     End If
//! End Function
//! ```
//!
//! ### Clean Data Import
//!
//! ```vb6
//! Sub ImportCSVData(fileName As String)
//!     Dim fileNum As Integer
//!     Dim currentLine As String
//!     Dim fields() As String
//!     Dim i As Integer
//!     
//!     fileNum = FreeFile
//!     Open fileName For Input As #fileNum
//!     
//!     While Not EOF(fileNum)
//!         Line Input #fileNum, currentLine
//!         fields = Split(currentLine, ",")
//!         
//!         ' Clean all fields
//!         For i = LBound(fields) To UBound(fields)
//!             fields(i) = Trim$(fields(i))
//!         Next i
//!         
//!         ' Process cleaned fields
//!         ProcessRecord fields
//!     Wend
//!     
//!     Close #fileNum
//! End Sub
//! ```
//!
//! ## Limitations
//!
//! - Only removes space characters (ASCII 32), not other whitespace
//! - Cannot handle `Null` values (use `Trim` variant function instead)
//! - Does not remove non-breaking spaces (character 160) or Unicode whitespace
//! - No option to specify custom characters to remove
//! - Works with strings only, not byte arrays
//! - Does not change character case (use with `UCase$` or `LCase$` if needed)

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

    #[test]
    fn trim_dollar_simple() {
        let source = r#"
Sub Main()
    result = Trim$("  Hello  ")
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_assignment() {
        let source = r"
Sub Main()
    Dim cleaned As String
    cleaned = Trim$(userInput)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_variable() {
        let source = r#"
Sub Main()
    Dim text As String
    Dim result As String
    text = "  Sample  "
    result = Trim$(text)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_clean_input() {
        let source = r"
Function CleanInput(userInput As String) As String
    CleanInput = Trim$(userInput)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_validate_input() {
        let source = r"
Function IsValidInput(input As String) As Boolean
    IsValidInput = (Len(Trim$(input)) > 0)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_in_condition() {
        let source = r#"
Sub Main()
    If Trim$(input) = "Expected" Then
        Debug.Print "Match found"
    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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_comparison() {
        let source = r"
Function CompareValues(value1 As String, value2 As String) As Boolean
    CompareValues = (Trim$(value1) = Trim$(value2))
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_database_field() {
        let source = r"
Function GetFieldValue(fieldValue As String) As String
    GetFieldValue = Trim$(fieldValue)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_array_cleanup() {
        let source = r"
Sub CleanStringArray(arr() As String)
    Dim i As Integer
    For i = LBound(arr) To UBound(arr)
        arr(i) = Trim$(arr(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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_multiple_uses() {
        let source = r"
Sub ProcessForm()
    Dim userName As String
    Dim userEmail As String
    userName = Trim$(txtName.Text)
    userEmail = Trim$(txtEmail.Text)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_select_case() {
        let source = r#"
Sub Main()
    Select Case Trim$(status)
        Case "Active"
            Debug.Print "Active record"
        Case "Inactive"
            Debug.Print "Inactive record"
    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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_concatenation() {
        let source = r#"
Sub Main()
    Dim output As String
    output = "Name: " & Trim$(nameField)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_config_parsing() {
        let source = r#"
Function ParseConfigLine(configLine As String) As String
    Dim equalPos As Integer
    equalPos = InStr(configLine, "=")
    If equalPos > 0 Then
        ParseConfigLine = Trim$(Mid$(configLine, equalPos + 1))
    End If
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_file_processing() {
        let source = r"
Function ReadCleanLine(fileNum As Integer) As String
    Dim rawLine As String
    Line Input #fileNum, rawLine
    ReadCleanLine = Trim$(rawLine)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_empty_check() {
        let source = r#"
Sub Main()
    If Len(Trim$(input)) = 0 Then
        Debug.Print "Empty or spaces only"
    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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_with_ucase() {
        let source = r"
Function NormalizeText(text As String) As String
    NormalizeText = UCase$(Trim$(text))
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_loop_processing() {
        let source = r"
Sub ProcessLines()
    Dim i As Integer
    Dim cleanLine As String
    For i = 1 To 10
        cleanLine = Trim$(lines(i))
        Debug.Print cleanLine
    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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_in_function() {
        let source = r"
Function GetCleanValue(value As String) As String
    GetCleanValue = Trim$(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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_csv_parsing() {
        let source = r"
Function ParseCSVField(field As String) As String
    ParseCSVField = Trim$(field)
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn trim_dollar_search_query() {
        let source = r"
Function PrepareSearchQuery(query As String) As String
    Dim cleaned As String
    cleaned = Trim$(query)
    PrepareSearchQuery = cleaned
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/string/trim_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}