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
//! # `CurDir$` Function
//!
//! Returns a `String` representing the current path for the specified drive or the default drive.
//! The dollar sign suffix (`$`) explicitly indicates that this function returns a `String` type
//! (not a `Variant`).
//!
//! ## Syntax
//!
//! ```vb
//! CurDir$[(drive)]
//! ```
//!
//! ## Parameters
//!
//! - **`drive`**: Optional. `String` expression that specifies an existing drive. If no drive is
//!   specified or if drive is a zero-length string (""), `CurDir$` returns the path for the
//!   current drive. The drive parameter can be just the drive letter (e.g., "C") or include
//!   a colon (e.g., "C:").
//!
//! ## Return Value
//!
//! Returns a `String` containing the current directory path for the specified drive. The returned
//! path does not include a trailing backslash unless the current directory is the root directory.
//! The return value is always a `String` type (never `Variant`).
//!
//! ## Remarks
//!
//! - The `CurDir$` function always returns a `String`, while `CurDir` (without `$`) can return a `Variant`.
//! - Without arguments, returns current directory of current drive.
//! - With drive specified, returns current directory of that drive.
//! - Does not include trailing backslash (except for root directory).
//! - Drive parameter is case-insensitive ("C" and "c" are equivalent).
//! - Each drive maintains its own current directory in Windows.
//! - On Windows, returns full path (e.g., "C:\Windows\System32").
//! - Root directory returns drive with backslash (e.g., "C:\").
//! - For better performance when you know the result is a string, use `CurDir$` instead of `CurDir`.
//!
//! ## Drive Specification
//!
//! The drive parameter can be specified in several ways:
//! - `CurDir$()` - Current drive
//! - `CurDir$("")` - Current drive
//! - `CurDir$("C")` - Drive C
//! - `CurDir$("C:")` - Drive C
//! - `CurDir$("D")` - Drive D
//!
//! ## Typical Uses
//!
//! 1. **Directory context** - Determine current working directory
//! 2. **Path building** - Construct full paths from relative paths
//! 3. **Directory restoration** - Save and restore directory state
//! 4. **File operations** - Locate files relative to current directory
//! 5. **Logging** - Record current directory for debugging
//! 6. **Validation** - Verify expected working directory
//! 7. **Multi-drive operations** - Work with multiple drives simultaneously
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Get current directory
//! Dim currentDir As String
//! currentDir = CurDir$()
//! ```
//!
//! ```vb
//! ' Example 2: Get current directory of specific drive
//! Dim cDrive As String
//! cDrive = CurDir$("C")
//! ```
//!
//! ```vb
//! ' Example 3: Check if in expected directory
//! If CurDir$() = "C:\MyApp" Then
//!     MsgBox "In correct directory"
//! End If
//! ```
//!
//! ```vb
//! ' Example 4: Display current directory
//! MsgBox "Current directory: " & CurDir$()
//! ```
//!
//! ## Common Patterns
//!
//! ### Save and Restore Directory
//! ```vb
//! Sub ProcessInDifferentDirectory(targetDir As String)
//!     Dim savedDir As String
//!     
//!     ' Save current directory
//!     savedDir = CurDir$()
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Change to target directory
//!     ChDir targetDir
//!     
//!     ' Do work in target directory
//!     ProcessFiles
//!     
//!     ' Restore original directory
//!     ChDir savedDir
//!     Exit Sub
//!     
//! ErrorHandler:
//!     ' Always restore directory even on error
//!     ChDir savedDir
//!     Err.Raise Err.Number, , Err.Description
//! End Sub
//! ```
//!
//! ### Building Full Path from Relative Path
//! ```vb
//! Function GetFullPath(relativePath As String) As String
//!     Dim currentDir As String
//!     currentDir = CurDir$()
//!     
//!     ' Check if current dir already ends with backslash
//!     If Right$(currentDir, 1) = "\" Then
//!         GetFullPath = currentDir & relativePath
//!     Else
//!         GetFullPath = currentDir & "\" & relativePath
//!     End If
//! End Function
//! ```
//!
//! ### Ensuring Correct Working Directory
//! ```vb
//! Sub EnsureWorkingDirectory(expectedDir As String)
//!     Dim currentDir As String
//!     currentDir = CurDir$()
//!     
//!     If UCase$(currentDir) <> UCase$(expectedDir) Then
//!         ChDir expectedDir
//!     End If
//! End Sub
//! ```
//!
//! ### Multi-Drive Directory Tracking
//! ```vb
//! Function GetAllDriveDirs() As Collection
//!     Dim drives() As String
//!     Dim result As New Collection
//!     Dim i As Integer
//!     
//!     drives = Array("C", "D", "E", "F")
//!     
//!     For i = LBound(drives) To UBound(drives)
//!         On Error Resume Next
//!         result.Add CurDir$(drives(i)), drives(i)
//!         On Error GoTo 0
//!     Next i
//!     
//!     Set GetAllDriveDirs = result
//! End Function
//! ```
//!
//! ### Path Validation
//! ```vb
//! Function IsValidDirectory(dirPath As String) As Boolean
//!     Dim savedDir As String
//!     Dim result As Boolean
//!     
//!     savedDir = CurDir$()
//!     result = False
//!     
//!     On Error Resume Next
//!     ChDir dirPath
//!     If Err.Number = 0 Then
//!         result = True
//!         ChDir savedDir
//!     End If
//!     On Error GoTo 0
//!     
//!     IsValidDirectory = result
//! End Function
//! ```
//!
//! ### Log File Path Construction
//! ```vb
//! Function GetLogFilePath() As String
//!     Dim logDir As String
//!     Dim logFile As String
//!     
//!     logDir = CurDir$()
//!     logFile = "application_" & Format$(Now, "yyyymmdd") & ".log"
//!     
//!     If Right$(logDir, 1) = "\" Then
//!         GetLogFilePath = logDir & logFile
//!     Else
//!         GetLogFilePath = logDir & "\" & logFile
//!     End If
//! End Function
//! ```
//!
//! ### Working Directory Report
//! ```vb
//! Sub ReportCurrentDirectories()
//!     Dim report As String
//!     
//!     report = "Current Directory: " & CurDir$() & vbCrLf
//!     
//!     On Error Resume Next
//!     report = report & "C: Drive: " & CurDir$("C") & vbCrLf
//!     report = report & "D: Drive: " & CurDir$("D") & vbCrLf
//!     On Error GoTo 0
//!     
//!     MsgBox report, vbInformation, "Directory Report"
//! End Sub
//! ```
//!
//! ### Relative File Search
//! ```vb
//! Function FindFileInCurrentDir(filename As String) As String
//!     Dim fullPath As String
//!     Dim currentDir As String
//!     
//!     currentDir = CurDir$()
//!     
//!     If Right$(currentDir, 1) = "\" Then
//!         fullPath = currentDir & filename
//!     Else
//!         fullPath = currentDir & "\" & filename
//!     End If
//!     
//!     If Dir$(fullPath) <> "" Then
//!         FindFileInCurrentDir = fullPath
//!     Else
//!         FindFileInCurrentDir = ""
//!     End If
//! End Function
//! ```
//!
//! ### Directory Depth Calculator
//! ```vb
//! Function GetDirectoryDepth() As Integer
//!     Dim path As String
//!     Dim depth As Integer
//!     Dim i As Integer
//!     
//!     path = CurDir$()
//!     depth = 0
//!     
//!     For i = 1 To Len(path)
//!         If Mid$(path, i, 1) = "\" Then
//!             depth = depth + 1
//!         End If
//!     Next i
//!     
//!     GetDirectoryDepth = depth - 1  ' Subtract 1 for root backslash
//! End Function
//! ```
//!
//! ### Safe Directory Operation Wrapper
//! ```vb
//! Function ExecuteInDirectory(dirPath As String, operation As String) As Boolean
//!     Dim savedDir As String
//!     Dim success As Boolean
//!     
//!     savedDir = CurDir$()
//!     success = False
//!     
//!     On Error GoTo ErrorHandler
//!     
//!     ' Change to target directory
//!     ChDir dirPath
//!     
//!     ' Execute operation based on parameter
//!     Select Case operation
//!         Case "CLEANUP"
//!             DeleteTempFiles
//!         Case "BACKUP"
//!             BackupFiles
//!         Case "SCAN"
//!             ScanFiles
//!     End Select
//!     
//!     success = True
//!     
//! ErrorHandler:
//!     ' Always restore directory
//!     ChDir savedDir
//!     ExecuteInDirectory = success
//! End Function
//! ```
//!
//! ## Related Functions
//!
//! - `CurDir`: Returns current directory as `Variant` instead of `String`
//! - `ChDir`: Changes the current directory
//! - `ChDrive`: Changes the current drive
//! - `App.Path`: Returns the path where the application executable is located
//! - `Dir$`: Returns files or directories matching a pattern
//! - `MkDir`: Creates a new directory
//! - `RmDir`: Removes an empty directory
//!
//! ## Best Practices
//!
//! 1. Always save current directory before changing it
//! 2. Use error handling when changing directories
//! 3. Restore original directory in error handlers
//! 4. Use `App.Path` for application-relative paths instead of relying on current directory
//! 5. Check for trailing backslash when building paths
//! 6. Use `CurDir$` instead of `CurDir` for better performance
//! 7. Be aware that current directory can be changed by other code
//! 8. Document assumptions about current directory in your code
//! 9. Use absolute paths when possible to avoid directory dependencies
//! 10. Test code with different working directories
//!
//! ## Performance Considerations
//!
//! - `CurDir$` is slightly more efficient than `CurDir` because it avoids `Variant` overhead
//! - Directory queries are fast system calls
//! - Cache the result if you need to use it multiple times in quick succession
//! - Avoid excessive directory changes as they affect all operations
//!
//! ## Platform Notes
//!
//! - Windows maintains separate current directories for each drive
//! - Network paths (UNC paths) are supported (e.g., "\\\\server\\share\\folder")
//! - Long path names (> 260 characters) may cause issues in VB6
//! - Current directory is process-specific and thread-safe
//! - Some operations (like file dialogs) may change the current directory
//!
//! ## Error Conditions
//!
//! - If the specified drive does not exist, an error occurs (Error 68: Device unavailable)
//! - If the drive is not ready (e.g., no disk in drive), an error occurs (Error 71: Disk not ready)
//! - Network drives that are disconnected will cause errors
//!
//! ## Security Considerations
//!
//! 1. Don't assume the current directory for security-sensitive operations
//! 2. Use absolute paths for configuration and data files
//! 3. Be aware that current directory can be manipulated by attackers
//! 4. Validate directory paths before changing to them
//! 5. Use `App.Path` for application resources rather than current directory
//!
//! ## Limitations
//!
//! - Cannot set the current directory (use `ChDir` for that)
//! - Path is limited to `MAX_PATH` characters (typically 260) in VB6
//! - Does not resolve symbolic links or junctions
//! - Drive letter parameter is Windows-specific

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

    #[test]
    fn curdir_dollar_no_args() {
        let source = r"
Sub Main()
    currentDir = CurDir$()
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_with_drive() {
        let source = r#"
Sub Main()
    cDrive = CurDir$("C")
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_with_drive_colon() {
        let source = r#"
Sub Main()
    dDrive = CurDir$("D:")
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_in_condition() {
        let source = r#"
Sub Main()
    If CurDir$() = "C:\MyApp" Then
        MsgBox "Correct directory"
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_save_restore() {
        let source = r#"
Sub Main()
    Dim savedDir As String
    savedDir = CurDir$()
    ChDir "C:\Temp"
    ChDir savedDir
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_path_building() {
        let source = r#"
Function GetFullPath(relativePath As String) As String
    GetFullPath = CurDir$() & "\" & relativePath
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_with_right() {
        let source = r#"
Sub Main()
    If Right$(CurDir$(), 1) = "\" Then
        path = CurDir$() & "file.txt"
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_msgbox() {
        let source = r#"
Sub Main()
    msg = "Current: " & CurDir$()
    MsgBox msg
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_ucase() {
        let source = r#"
Sub Main()
    If UCase$(CurDir$()) = "C:\MYAPP" Then
        Process
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_multiple_drives() {
        let source = r#"
Sub Main()
    Dim c As String, d As String
    c = CurDir$("C")
    d = CurDir$("D")
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_error_handler() {
        let source = r#"
Sub Main()
    Dim savedDir As String
    savedDir = CurDir$()
    On Error GoTo ErrorHandler
    ChDir "C:\NewPath"
    Exit Sub
ErrorHandler:
    ChDir savedDir
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_with_dir() {
        let source = r#"
Function FindFile(filename As String) As String
    fullPath = CurDir$() & "\" & filename
    If Dir$(fullPath) <> "" Then
        FindFile = fullPath
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_depth_calc() {
        let source = r"
Function GetDepth() As Integer
    Dim path As String
    path = CurDir$()
    GetDepth = Len(path)
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_log_path() {
        let source = r#"
Function GetLogPath() As String
    GetLogPath = CurDir$() & "\app.log"
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_validation() {
        let source = r"
Sub EnsureDirectory(expectedDir As String)
    If CurDir$() <> expectedDir Then
        ChDir expectedDir
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_format() {
        let source = r#"
Sub Main()
    logFile = CurDir$() & "\log_" & Format$(Now, "yyyymmdd") & ".txt"
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_debug_print() {
        let source = r#"
Sub Main()
    Debug.Print "Current Dir: " & CurDir$()
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_select_case() {
        let source = r#"
Sub Main()
    Select Case UCase$(CurDir$())
        Case "C:\WINDOWS"
            mode = 1
        Case "C:\TEMP"
            mode = 2
    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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_empty_string() {
        let source = r#"
Sub Main()
    currentDir = CurDir$("")
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_dollar_variable_drive() {
        let source = r#"
Sub Main()
    Dim drive As String
    drive = "C"
    path = CurDir$(drive)
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/file/curdir_dollar",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}