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
//! # `Command$` Function
//!
//! Returns the argument portion of the command line used to launch Microsoft Visual Basic or an
//! executable program developed with Visual Basic. The dollar sign suffix (`$`) explicitly
//! indicates that this function returns a `String` type (not a `Variant`).
//!
//! ## Syntax
//!
//! ```vb
//! Command$()
//! ```
//!
//! ## Parameters
//!
//! None. The `Command$` function takes no arguments.
//!
//! ## Return Value
//!
//! Returns a `String` containing the command-line arguments passed to the program. If no arguments
//! were passed, returns an empty string (""). The return value is always a `String` type (never `Variant`).
//!
//! ## Remarks
//!
//! - The `Command$` function always returns a `String`, while `Command` (without `$`) can return a `Variant`.
//! - Returns only the arguments, not the executable path or name.
//! - Arguments are returned as a single string, exactly as passed to the application.
//! - Multiple arguments are separated by spaces (unless quoted).
//! - Quoted strings preserve internal spaces but quotes may be included in the result.
//! - Leading and trailing spaces are typically trimmed by the system.
//! - Returns empty string ("") if no arguments were provided.
//! - Case is preserved as entered on the command line.
//! - For better performance when you know the result is a string, use `Command$` instead of `Command`.
//!
//! ## Command Line Processing
//!
//! When an application is launched with:
//! ```text
//! MyApp.exe /debug file.txt "long filename.doc"
//! ```
//!
//! `Command$()` returns:
//! ```text
//! /debug file.txt "long filename.doc"
//! ```
//!
//! ## Typical Uses
//!
//! 1. **Processing startup parameters** - Read switches and configuration flags
//! 2. **File path handling** - Accept file paths to open at startup
//! 3. **Debug modes** - Enable special debugging or logging modes
//! 4. **Automation** - Support scripted or automated workflows
//! 5. **Configuration** - Pass runtime configuration without config files
//! 6. **Batch processing** - Process multiple files or operations
//! 7. **Integration** - Allow other applications to control behavior
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Get command line arguments
//! Sub Main()
//!     Dim cmdLine As String
//!     cmdLine = Command$()
//!     MsgBox "Arguments: " & cmdLine
//! End Sub
//! ```
//!
//! ```vb
//! ' Example 2: Check if arguments provided
//! Sub Main()
//!     If Command$() <> "" Then
//!         MsgBox "Arguments: " & Command$()
//!     Else
//!         MsgBox "No arguments"
//!     End If
//! End Sub
//! ```
//!
//! ```vb
//! ' Example 3: Simple file opener
//! Sub Main()
//!     Dim filename As String
//!     filename = Trim$(Command$())
//!     If filename <> "" Then
//!         OpenFile filename
//!     End If
//! End Sub
//! ```
//!
//! ```vb
//! ' Example 4: Check for debug mode
//! Sub Main()
//!     If InStr(Command$(), "/debug") > 0 Then
//!         EnableDebugMode
//!     End If
//! End Sub
//! ```
//!
//! ## Common Patterns
//!
//! ### Processing Multiple Arguments
//! ```vb
//! Function ParseArguments() As Collection
//!     Dim args As String
//!     Dim result As New Collection
//!     Dim parts() As String
//!     
//!     args = Command$()
//!     If args = "" Then
//!         Set ParseArguments = result
//!         Exit Function
//!     End If
//!     
//!     parts = Split(args, " ")
//!     Dim i As Integer
//!     For i = LBound(parts) To UBound(parts)
//!         If Trim$(parts(i)) <> "" Then
//!             result.Add Trim$(parts(i))
//!         End If
//!     Next i
//!     
//!     Set ParseArguments = result
//! End Function
//! ```
//!
//! ### Processing Switches and Parameters
//! ```vb
//! Sub Main()
//!     Dim args As String
//!     args = Command$()
//!     
//!     ' Check for various switches
//!     If InStr(args, "/debug") > 0 Then
//!         App.LogMode = 1
//!     End If
//!     
//!     If InStr(args, "/silent") > 0 Then
//!         App.SilentMode = True
//!     End If
//!     
//!     If InStr(args, "/verbose") > 0 Then
//!         App.VerboseMode = True
//!     End If
//! End Sub
//! ```
//!
//! ### Opening File from Command Line
//! ```vb
//! Sub Main()
//!     Dim filename As String
//!     filename = Trim$(Command$())
//!     
//!     If filename <> "" Then
//!         ' Remove surrounding quotes if present
//!         If Left$(filename, 1) = Chr$(34) Then
//!             filename = Mid$(filename, 2)
//!         End If
//!         If Right$(filename, 1) = Chr$(34) Then
//!             filename = Left$(filename, Len(filename) - 1)
//!         End If
//!         
//!         ' Verify file exists and open it
//!         If Dir$(filename) <> "" Then
//!             LoadDocument filename
//!         Else
//!             MsgBox "File not found: " & filename
//!         End If
//!     End If
//! End Sub
//! ```
//!
//! ### Named Parameter Extraction
//! ```vb
//! Function GetParameter(paramName As String) As String
//!     Dim args As String
//!     Dim pos As Integer
//!     Dim endPos As Integer
//!     Dim result As String
//!     
//!     args = " " & Command$() & " "
//!     pos = InStr(1, args, "/" & paramName & ":", vbTextCompare)
//!     
//!     If pos > 0 Then
//!         pos = pos + Len(paramName) + 2
//!         endPos = InStr(pos, args, " ")
//!         If endPos > pos Then
//!             result = Mid$(args, pos, endPos - pos)
//!         End If
//!     End If
//!     
//!     GetParameter = result
//! End Function
//! ```
//!
//! ### Logging Startup Arguments
//! ```vb
//! Sub Main()
//!     Dim args As String
//!     Dim logFile As Integer
//!     
//!     args = Command$()
//!     
//!     logFile = FreeFile
//!     Open App.Path & "\startup.log" For Append As #logFile
//!     Print #logFile, Now & " - Started with args: " & args
//!     Close #logFile
//! End Sub
//! ```
//!
//! ### Configuration from Command Line
//! ```vb
//! Sub Main()
//!     Dim args As String
//!     args = UCase$(Command$())
//!     
//!     ' Set configuration based on arguments
//!     If InStr(args, "/SERVER:") > 0 Then
//!         App.ServerName = GetParameter("server")
//!     End If
//!     
//!     If InStr(args, "/PORT:") > 0 Then
//!         App.Port = Val(GetParameter("port"))
//!     End If
//!     
//!     If InStr(args, "/USER:") > 0 Then
//!         App.UserName = GetParameter("user")
//!     End If
//! End Sub
//! ```
//!
//! ### Help Display
//! ```vb
//! Sub Main()
//!     Dim args As String
//!     args = LCase$(Trim$(Command$()))
//!     
//!     If args = "/?" Or args = "-?" Or args = "/help" Or args = "-help" Then
//!         DisplayHelp
//!         End
//!     End If
//! End Sub
//!
//! Sub DisplayHelp()
//!     Dim helpText As String
//!     helpText = "Usage: MyApp [options]" & vbCrLf
//!     helpText = helpText & "/debug    - Enable debug mode" & vbCrLf
//!     helpText = helpText & "/silent   - Run in silent mode" & vbCrLf
//!     helpText = helpText & "/file:xxx - Open specified file" & vbCrLf
//!     MsgBox helpText
//! End Sub
//! ```
//!
//! ### Batch Mode Processing
//! ```vb
//! Sub Main()
//!     Dim args As String
//!     Dim files() As String
//!     Dim i As Integer
//!     
//!     args = Command$()
//!     
//!     If InStr(args, "/batch") > 0 Then
//!         ' Parse file list
//!         files = Split(Replace$(args, "/batch", ""), " ")
//!         
//!         For i = LBound(files) To UBound(files)
//!             If Trim$(files(i)) <> "" Then
//!                 ProcessFile Trim$(files(i))
//!             End If
//!         Next i
//!         
//!         End  ' Exit after batch processing
//!     End If
//! End Sub
//! ```
//!
//! ### Error Recovery
//! ```vb
//! Sub Main()
//!     On Error GoTo ErrorHandler
//!     
//!     Dim args As String
//!     args = Command$()
//!     
//!     ' Process arguments
//!     If args <> "" Then
//!         ProcessCommandLine args
//!     End If
//!     
//!     Exit Sub
//!     
//! ErrorHandler:
//!     MsgBox "Error processing command line: " & args & vbCrLf & _
//!            "Error: " & Err.Description
//!     End
//! End Sub
//! ```
//!
//! ### Case-Insensitive Switch Detection
//! ```vb
//! Function HasSwitch(switchName As String) As Boolean
//!     Dim args As String
//!     args = " " & UCase$(Command$()) & " "
//!     switchName = " /" & UCase$(switchName) & " "
//!     HasSwitch = (InStr(args, switchName) > 0)
//! End Function
//! ```
//!
//! ## Related Functions
//!
//! - `Command`: Returns command-line arguments as `Variant` instead of `String`
//! - `App.Path`: Returns the path where the application executable is located
//! - `App.EXEName`: Returns the name of the executable file
//! - `Environ$`: Returns environment variable values
//!
//! ## Best Practices
//!
//! 1. Always trim the result to remove leading/trailing spaces
//! 2. Handle the case where no arguments are provided (empty string)
//! 3. Use case-insensitive comparison for switches and parameters
//! 4. Document expected command-line format in your application
//! 5. Validate arguments before using them
//! 6. Provide meaningful error messages for invalid arguments
//! 7. Consider implementing a `/help` or `/?` switch
//! 8. Use `Command$` instead of `Command` for better performance
//! 9. Be careful with quoted strings - they may include the quotes
//! 10. Log startup arguments for debugging and support purposes
//!
//! ## Performance Considerations
//!
//! - `Command$` is slightly more efficient than `Command` because it avoids `Variant` overhead
//! - The function is typically called once at startup, so performance is rarely a concern
//! - Parsing complex command lines can be slow; cache the result if needed multiple times
//! - Consider using a dedicated command-line parser for complex argument processing
//!
//! ## Platform Notes
//!
//! - Command-line argument handling is consistent across Windows platforms
//! - Maximum command-line length varies by Windows version (typically 8191 characters)
//! - Arguments are passed by the operating system when the executable is launched
//! - VB6 IDE does not allow setting command-line arguments for debugging
//! - Use a shortcut or command prompt to test command-line arguments
//!
//! ## Security Considerations
//!
//! 1. Never execute command-line arguments directly as code
//! 2. Validate all file paths before accessing files
//! 3. Sanitize arguments before using in SQL queries or shell commands
//! 4. Limit accepted argument values to known good values when possible
//! 5. Log suspicious or malformed command-line arguments
//!
//! ## Limitations
//!
//! - Returns arguments as a single string (manual parsing required for multiple arguments)
//! - Does not provide the executable path or name (use `App.Path` and `App.EXEName`)
//! - No built-in support for named parameters (must implement custom parsing)
//! - Quote handling is system-dependent and may vary
//! - Cannot distinguish between missing arguments and empty string argument

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

    #[test]
    fn command_dollar_simple() {
        let source = r"
Sub Main()
    args = Command$()
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

    #[test]
    fn command_dollar_in_condition() {
        let source = r#"
Sub Main()
    If Command$() <> "" Then
        MsgBox "Arguments provided"
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

    #[test]
    fn command_dollar_with_instr() {
        let source = r#"
Sub Main()
    If InStr(Command$(), "/debug") > 0 Then
        EnableDebug
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_parse_args() {
        let source = r#"
Function ParseArguments() As Collection
    Dim args As String
    args = Command$()
    If args = "" Then Exit Function
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_multiple_checks() {
        let source = r#"
Sub Main()
    Dim args As String
    args = Command$()
    If InStr(args, "/debug") > 0 Then Debug = True
    If InStr(args, "/silent") > 0 Then Silent = True
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_file_opener() {
        let source = r#"
Sub Main()
    Dim filename As String
    filename = Trim$(Command$())
    If filename <> "" Then
        OpenFile filename
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_with_split() {
        let source = r#"
Sub Main()
    Dim parts() As String
    parts = Split(Command$(), " ")
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_logging() {
        let source = r#"
Sub Main()
    Dim logFile As Integer
    logFile = FreeFile
    Print #logFile, "Args: " & Command$()
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_ucase() {
        let source = r"
Sub Main()
    Dim args As String
    args = UCase$(Command$())
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_lcase() {
        let source = r"
Sub Main()
    args = LCase$(Trim$(Command$()))
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_help_check() {
        let source = r#"
Sub Main()
    If Command$() = "/?" Then
        DisplayHelp
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_replace() {
        let source = r#"
Sub Main()
    args = Replace$(Command$(), "/batch", "")
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_concatenation() {
        let source = r#"
Sub Main()
    msg = "Started with: " & Command$()
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_function_call() {
        let source = r"
Function HasSwitch(switchName As String) As Boolean
    Dim args As String
    args = UCase$(Command$())
    HasSwitch = (InStr(args, switchName) > 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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_empty_check() {
        let source = r#"
Sub Main()
    If Len(Command$()) = 0 Then
        MsgBox "No arguments"
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_direct_print() {
        let source = r"
Sub Main()
    Debug.Print Command$()
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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn command_dollar_select_case() {
        let source = r#"
Sub Main()
    Select Case LCase$(Command$())
        Case "/debug"
            DebugMode = True
        Case "/release"
            DebugMode = False
    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/interaction/command_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}