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
//! # `Str$` Function
//!
//! The `Str$` function in Visual Basic 6 converts a numeric value to a string representation.
//! The dollar sign (`$`) suffix indicates that this function always returns a `String` type,
//! never a `Variant`.
//!
//! ## Syntax
//!
//! ```vb6
//! Str$(number)
//! ```
//!
//! ## Parameters
//!
//! - `number` - Required. Any valid numeric expression. Can be of type `Byte`, `Integer`, `Long`,
//!   `Single`, `Double`, or `Currency`.
//!
//! ## Return Value
//!
//! Returns a `String` representation of the number. Positive numbers include a leading space
//! for the sign position. Negative numbers include a leading minus sign (-).
//!
//! ## Behavior and Characteristics
//!
//! ### Sign Handling
//!
//! - Positive numbers: Include a leading space (e.g., " 123")
//! - Negative numbers: Include a leading minus sign (e.g., "-123")
//! - Zero: Returns " 0" (with leading space)
//! - The leading space reserves position for the sign
//!
//! ### Numeric Formatting
//!
//! - No thousands separators (e.g., "1000" not "1,000")
//! - Scientific notation for very large or very small numbers
//! - Floating-point numbers may show precision artifacts
//! - No control over decimal places
//!
//! ### Type Differences: `Str$` vs `Str`
//!
//! - `Str$`: Always returns `String` type (never `Variant`)
//! - `Str`: Returns `Variant` containing a string
//! - Use `Str$` when you need guaranteed `String` return type
//! - Use `Str` when working with `Variant` variables
//!
//! ## Common Usage Patterns
//!
//! ### 1. Basic Number to String Conversion
//!
//! ```vb6
//! Dim numStr As String
//! numStr = Str$(123)  ' Returns " 123" (note leading space)
//! numStr = Str$(-45)  ' Returns "-45"
//! ```
//!
//! ### 2. Concatenating Numbers with Text
//!
//! ```vb6
//! Function FormatMessage(count As Integer) As String
//!     FormatMessage = "Found" & Str$(count) & " items"
//! End Function
//!
//! Debug.Print FormatMessage(5)  ' "Found 5 items"
//! ```
//!
//! ### 3. Trimming the Leading Space
//!
//! ```vb6
//! Function NumberToString(value As Long) As String
//!     NumberToString = LTrim$(Str$(value))
//! End Function
//!
//! Dim result As String
//! result = NumberToString(100)  ' Returns "100" (no leading space)
//! ```
//!
//! ### 4. Building Comma-Separated Values
//!
//! ```vb6
//! Function BuildCSV(values() As Integer) As String
//!     Dim i As Integer
//!     Dim result As String
//!     For i = LBound(values) To UBound(values)
//!         If i > LBound(values) Then result = result & ","
//!         result = result & LTrim$(Str$(values(i)))
//!     Next i
//!     BuildCSV = result
//! End Function
//! ```
//!
//! ### 5. Logging and Debug Output
//!
//! ```vb6
//! Sub LogValue(name As String, value As Double)
//!     Debug.Print name & " =" & Str$(value)
//! End Sub
//! ```
//!
//! ### 6. Creating Numeric Labels
//!
//! ```vb6
//! Function CreateLabel(index As Integer) As String
//!     CreateLabel = "Item" & LTrim$(Str$(index))
//! End Function
//!
//! Dim label As String
//! label = CreateLabel(42)  ' Returns "Item42"
//! ```
//!
//! ### 7. File Output Formatting
//!
//! ```vb6
//! Sub WriteDataLine(fileNum As Integer, id As Long, amount As Currency)
//!     Print #fileNum, LTrim$(Str$(id)) & "," & LTrim$(Str$(amount))
//! End Sub
//! ```
//!
//! ### 8. Array Index Display
//!
//! ```vb6
//! Sub ShowArrayContents(arr() As Integer)
//!     Dim i As Integer
//!     For i = LBound(arr) To UBound(arr)
//!         Debug.Print "[" & LTrim$(Str$(i)) & "] = " & LTrim$(Str$(arr(i)))
//!     Next i
//! End Sub
//! ```
//!
//! ### 9. Simple Calculator Display
//!
//! ```vb6
//! Function UpdateDisplay(value As Double) As String
//!     UpdateDisplay = LTrim$(Str$(value))
//! End Function
//! ```
//!
//! ### 10. Building SQL Statements
//!
//! ```vb6
//! Function BuildQuery(userId As Long) As String
//!     BuildQuery = "SELECT * FROM Users WHERE ID = " & LTrim$(Str$(userId))
//! End Function
//! ```
//!
//! ## Related Functions
//!
//! - `Str()` - Returns a `Variant` containing the string representation of a number
//! - `CStr()` - Converts an expression to a `String` (no leading space for positive numbers)
//! - `Format$()` - Provides extensive formatting control for numeric values
//! - `Val()` - Converts a string to a numeric value (inverse operation)
//! - `LTrim$()` - Removes leading spaces (often used with `Str$`)
//! - `Hex$()` - Converts a number to hexadecimal string
//! - `Oct$()` - Converts a number to octal string
//!
//! ## Best Practices
//!
//! ### When to Use `Str$` vs `CStr` vs `Format$`
//!
//! ```vb6
//! Dim value As Integer
//! value = 42
//!
//! ' Str$ includes leading space for positive numbers
//! Debug.Print Str$(value)  ' " 42"
//!
//! ' CStr has no leading space
//! Debug.Print CStr(value)  ' "42"
//!
//! ' Format$ provides control over formatting
//! Debug.Print Format$(value, "000")  ' "042"
//! ```
//!
//! ### Always Trim for Display
//!
//! ```vb6
//! ' Without trim (has leading space for positive numbers)
//! Label1.Caption = Str$(count)  ' " 5"
//!
//! ' With trim (clean output)
//! Label1.Caption = LTrim$(Str$(count))  ' "5"
//!
//! ' Or use CStr instead
//! Label1.Caption = CStr(count)  ' "5"
//! ```
//!
//! ### Use `Format$` for Formatted Output
//!
//! ```vb6
//! ' Str$ has no formatting control
//! Debug.Print Str$(1234.5678)  ' " 1234.5678"
//!
//! ' Format$ provides control
//! Debug.Print Format$(1234.5678, "#,##0.00")  ' "1,234.57"
//! ```
//!
//! ### Handle Negative Numbers
//!
//! ```vb6
//! Function SafeConvert(value As Long) As String
//!     ' Str$ handles negative numbers correctly
//!     SafeConvert = LTrim$(Str$(value))
//!     ' For negative: "-123", for positive: "123"
//! End Function
//! ```
//!
//! ## Performance Considerations
//!
//! - `Str$` is very fast for simple conversions
//! - Faster than `Format$` when formatting is not needed
//! - Similar performance to `CStr`
//! - No significant overhead for any numeric type
//!
//! ```vb6
//! ' Fast: simple conversion
//! For i = 1 To 10000
//!     text = LTrim$(Str$(i))
//! Next i
//!
//! ' Slower: formatted conversion (but more control)
//! For i = 1 To 10000
//!     text = Format$(i, "0000")
//! Next i
//! ```
//!
//! ## Common Pitfalls
//!
//! ### 1. Leading Space for Positive Numbers
//!
//! ```vb6
//! Dim result As String
//! result = Str$(100)  ' " 100" (note the leading space!)
//!
//! ' This can cause problems in comparisons
//! If Str$(100) = "100" Then  ' FALSE! (" 100" <> "100")
//!     Debug.Print "Match"
//! End If
//!
//! ' Use LTrim$ or CStr instead
//! If LTrim$(Str$(100)) = "100" Then  ' TRUE
//!     Debug.Print "Match"
//! End If
//! ```
//!
//! ### 2. Confusion with `CStr`
//!
//! ```vb6
//! Dim value As Integer
//! value = 42
//!
//! Debug.Print Str$(value)   ' " 42" (with space)
//! Debug.Print CStr(value)   ' "42" (no space)
//!
//! ' Know which one you need
//! ```
//!
//! ### 3. No Formatting Control
//!
//! ```vb6
//! Dim amount As Currency
//! amount = 1234.56
//!
//! ' Str$ gives no control
//! Debug.Print Str$(amount)  ' " 1234.56"
//!
//! ' Use Format$ for currency
//! Debug.Print Format$(amount, "$#,##0.00")  ' "$1,234.56"
//! ```
//!
//! ### 4. Floating-Point Precision Issues
//!
//! ```vb6
//! Dim value As Double
//! value = 0.1 + 0.2
//!
//! Debug.Print Str$(value)  ' May show " 0.30000000000000004"
//!
//! ' Use Format$ to control precision
//! Debug.Print Format$(value, "0.00")  ' "0.30"
//! ```
//!
//! ### 5. Not Handling Very Large or Small Numbers
//!
//! ```vb6
//! Dim bigNum As Double
//! bigNum = 1E+20
//!
//! Debug.Print Str$(bigNum)  ' " 1E+20" (scientific notation)
//!
//! ' Be aware of scientific notation in output
//! ```
//!
//! ### 6. Null Values
//!
//! ```vb6
//! ' Str$ cannot handle Null
//! Dim result As String
//! result = Str$(nullValue)  ' Runtime error if nullValue is Null
//!
//! ' Check first
//! If Not IsNull(value) Then
//!     result = Str$(value)
//! Else
//!     result = ""
//! End If
//! ```
//!
//! ## Practical Examples
//!
//! ### Building a Progress Message
//!
//! ```vb6
//! Function ProgressMessage(current As Long, total As Long) As String
//!     ProgressMessage = "Processing item" & Str$(current) & _
//!                      " of" & Str$(total)
//! End Function
//!
//! Debug.Print ProgressMessage(5, 10)  ' "Processing item 5 of 10"
//! ```
//!
//! ### Creating Sequential Filenames
//!
//! ```vb6
//! Function GenerateFileName(baseNameStr As String, index As Integer) As String
//!     GenerateFileName = baseNameStr & LTrim$(Str$(index)) & ".dat"
//! End Function
//!
//! Dim fileName As String
//! fileName = GenerateFileName("data", 1)  ' "data1.dat"
//! ```
//!
//! ### Simple Data Export
//!
//! ```vb6
//! Sub ExportToCSV(data() As Double, fileName As String)
//!     Dim i As Integer
//!     Dim lineData As String
//!     
//!     Open fileName For Output As #1
//!     For i = LBound(data) To UBound(data)
//!         Print #1, LTrim$(Str$(data(i)))
//!     Next i
//!     Close #1
//! End Sub
//! ```
//!
//! ## Limitations
//!
//! - Always includes leading space for positive numbers (use `LTrim$` or `CStr` to remove)
//! - No formatting control (no thousands separators, decimal places, etc.)
//! - Cannot handle `Null` values (use `CStr` with error handling instead)
//! - May produce scientific notation for very large or small numbers
//! - Floating-point precision artifacts may appear in output
//! - No locale-specific formatting (always uses invariant format)

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

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

    #[test]
    fn str_dollar_assignment() {
        let source = r"
Sub Main()
    Dim numStr As String
    numStr = Str$(456)
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

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

    #[test]
    fn str_dollar_with_ltrim() {
        let source = r"
Function NumberToString(value As Long) As String
    NumberToString = LTrim$(Str$(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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_concatenation() {
        let source = r#"
Function FormatMessage(count As Integer) As String
    FormatMessage = "Found" & Str$(count) & " items"
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_in_condition() {
        let source = r#"
Sub Main()
    If LTrim$(Str$(value)) = "100" Then
        Debug.Print "Match"
    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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_create_label() {
        let source = r#"
Function CreateLabel(index As Integer) As String
    CreateLabel = "Item" & LTrim$(Str$(index))
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_logging() {
        let source = r#"
Sub LogValue(valueName As String, value As Double)
    Debug.Print valueName & " =" & Str$(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/string/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_multiple_uses() {
        let source = r"
Sub ProcessValues()
    Dim text1 As String
    Dim text2 As String
    text1 = Str$(10)
    text2 = Str$(20)
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_select_case() {
        let source = r#"
Sub Main()
    Select Case LTrim$(Str$(code))
        Case "1"
            Debug.Print "One"
        Case "2"
            Debug.Print "Two"
    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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_csv_building() {
        let source = r#"
Function BuildCSV(val1 As Integer, val2 As Integer) As String
    BuildCSV = LTrim$(Str$(val1)) & "," & LTrim$(Str$(val2))
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_file_output() {
        let source = r"
Sub WriteData(fileNum As Integer, id As Long)
    Print #fileNum, LTrim$(Str$(id))
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_loop_processing() {
        let source = r#"
Sub ShowArray(arr() As Integer)
    Dim i As Integer
    For i = LBound(arr) To UBound(arr)
        Debug.Print "[" & Str$(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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_progress_message() {
        let source = r#"
Function ProgressMessage(current As Long, total As Long) As String
    ProgressMessage = "Item" & Str$(current) & " of" & Str$(total)
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_filename_generation() {
        let source = r#"
Function GenerateFileName(baseName As String, index As Integer) As String
    GenerateFileName = baseName & LTrim$(Str$(index)) & ".dat"
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

    #[test]
    fn str_dollar_currency_value() {
        let source = r"
Sub Main()
    Dim amount As Currency
    Dim text As String
    amount = 1234.56
    text = Str$(amount)
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_in_function() {
        let source = r"
Function ConvertNumber(num As Long) As String
    ConvertNumber = Str$(num)
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn str_dollar_sql_building() {
        let source = r#"
Function BuildQuery(userId As Long) As String
    BuildQuery = "SELECT * FROM Users WHERE ID = " & LTrim$(Str$(userId))
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/str_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}