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
//! # `CurDir` Function
//!
//! Returns a `String` representing the current path for the specified drive or the default drive.
//!
//! ## 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.
//!
//! ## Remarks
//!
//! The `CurDir` function returns the current working directory for a specified drive. This is
//! useful for:
//!
//! - Determining the current directory before changing it
//! - Building relative file paths
//! - Saving and restoring directory context
//! - File path validation
//! - Log file location determination
//!
//! **Important Characteristics:**
//!
//! - 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
//! - Each drive maintains its own current directory
//! - On Windows, returns full path (e.g., "C:\Windows\System32")
//! - Root directory returns drive with backslash (e.g., "C:\")
//!
//! ## 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
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```vb
//! ' Get current directory of current drive
//! Dim currentDir As String
//! currentDir = CurDir()  ' Returns something like "C:\Users\Username\Documents"
//!
//! ' Get current directory of specific drive
//! Dim cDrive As String
//! cDrive = CurDir("C")  ' Returns current directory on C: drive
//!
//! Dim dDrive As String
//! dDrive = CurDir("D:")  ' Returns current directory on D: drive
//! ```
//!
//! ### Save and Restore Directory
//!
//! ```vb
//! Sub ProcessInDifferentDirectory(targetDir As String)
//!     Dim savedDir As String
//!     
//!     ' Save current directory
//!     savedDir = CurDir()
//!     
//!     ' Change to target directory
//!     ChDir targetDir
//!     
//!     ' Do work in target directory
//!     ProcessFiles
//!     
//!     ' Restore original directory
//!     ChDir savedDir
//! End Sub
//! ```
//!
//! ### Building Relative Paths
//!
//! ```vb
//! Function GetFullPath(relativePath As String) As String
//!     ' Combine current directory with relative path
//!     If Right(CurDir(), 1) = "\" Then
//!         GetFullPath = CurDir() & relativePath
//!     Else
//!         GetFullPath = CurDir() & "\" & relativePath
//!     End If
//! End Function
//! ```
//!
//! ## Common Patterns
//!
//! ### Check if at Root Directory
//!
//! ```vb
//! Function IsRootDirectory() As Boolean
//!     Dim currentPath As String
//!     currentPath = CurDir()
//!     
//!     ' Root directory ends with backslash (e.g., "C:\")
//!     IsRootDirectory = (Len(currentPath) = 3 And Right(currentPath, 1) = "\")
//! End Function
//! ```
//!
//! ### Get Current Drive Letter
//!
//! ```vb
//! Function GetCurrentDrive() As String
//!     Dim currentPath As String
//!     currentPath = CurDir()
//!     
//!     ' Extract drive letter (first character)
//!     GetCurrentDrive = Left(currentPath, 1)
//! End Function
//! ```
//!
//! ### Ensure Trailing Backslash
//!
//! ```vb
//! Function EnsureTrailingBackslash(path As String) As String
//!     If Right(path, 1) <> "\" Then
//!         EnsureTrailingBackslash = path & "\"
//!     Else
//!         EnsureTrailingBackslash = path
//!     End If
//! End Function
//!
//! ' Usage
//! Dim dirPath As String
//! dirPath = EnsureTrailingBackslash(CurDir())
//! ```
//!
//! ### Directory Context Manager
//!
//! ```vb
//! Type DirectoryContext
//!     SavedDirectory As String
//! End Type
//!
//! Function PushDirectory(newDir As String) As DirectoryContext
//!     Dim ctx As DirectoryContext
//!     ctx.SavedDirectory = CurDir()
//!     ChDir newDir
//!     PushDirectory = ctx
//! End Function
//!
//! Sub PopDirectory(ctx As DirectoryContext)
//!     ChDir ctx.SavedDirectory
//! End Sub
//!
//! ' Usage
//! Dim ctx As DirectoryContext
//! ctx = PushDirectory("C:\Temp")
//! ' Do work...
//! PopDirectory ctx
//! ```
//!
//! ### Multi-Drive Path Tracking
//!
//! ```vb
//! Function GetAllDrivePaths() As Collection
//!     Dim paths As New Collection
//!     Dim drives() As String
//!     Dim i As Integer
//!     
//!     drives = Array("C", "D", "E", "F")
//!     
//!     On Error Resume Next
//!     For i = LBound(drives) To UBound(drives)
//!         paths.Add CurDir(drives(i)), drives(i)
//!     Next i
//!     On Error GoTo 0
//!     
//!     Set GetAllDrivePaths = paths
//! End Function
//! ```
//!
//! ### Log File in Current Directory
//!
//! ```vb
//! Function GetLogFilePath() As String
//!     Dim currentDir As String
//!     Dim logFile As String
//!     
//!     currentDir = CurDir()
//!     logFile = "application.log"
//!     
//!     If Right(currentDir, 1) = "\" Then
//!         GetLogFilePath = currentDir & logFile
//!     Else
//!         GetLogFilePath = currentDir & "\" & logFile
//!     End If
//! End Function
//! ```
//!
//! ### Temporary Directory Operations
//!
//! ```vb
//! Sub ProcessInTempDirectory()
//!     Dim originalDir As String
//!     Dim tempDir As String
//!     
//!     originalDir = CurDir()
//!     tempDir = Environ("TEMP")
//!     
//!     On Error GoTo Cleanup
//!     
//!     ChDir tempDir
//!     
//!     ' Process files in temp directory
//!     ProcessTempFiles
//!     
//! Cleanup:
//!     ChDir originalDir
//! End Sub
//! ```
//!
//! ### Validate Relative Path
//!
//! ```vb
//! Function IsRelativePath(path As String) As Boolean
//!     ' Check if path is relative (doesn't start with drive letter)
//!     IsRelativePath = (InStr(path, ":") = 0)
//! End Function
//!
//! Function ResolveRelativePath(relativePath As String) As String
//!     If IsRelativePath(relativePath) Then
//!         ResolveRelativePath = CurDir() & "\" & relativePath
//!     Else
//!         ResolveRelativePath = relativePath
//!     End If
//! End Function
//! ```
//!
//! ### Directory Breadcrumb Trail
//!
//! ```vb
//! Function GetDirectoryParts() As String()
//!     Dim currentDir As String
//!     Dim parts() As String
//!     
//!     currentDir = CurDir()
//!     
//!     ' Remove drive letter and colon
//!     If InStr(currentDir, ":") > 0 Then
//!         currentDir = Mid(currentDir, 3)
//!     End If
//!     
//!     ' Remove leading backslash
//!     If Left(currentDir, 1) = "\" Then
//!         currentDir = Mid(currentDir, 2)
//!     End If
//!     
//!     ' Split by backslash
//!     If Len(currentDir) > 0 Then
//!         parts = Split(currentDir, "\")
//!     End If
//!     
//!     GetDirectoryParts = parts
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Cross-Drive File Operations
//!
//! ```vb
//! Sub CopyFileToAnotherDrive(sourceFile As String, targetDrive As String)
//!     Dim sourceDrive As String
//!     Dim targetPath As String
//!     
//!     ' Get current directory on target drive
//!     On Error Resume Next
//!     targetPath = CurDir(targetDrive)
//!     
//!     If Err.Number = 0 Then
//!         ' Build target file path
//!         If Right(targetPath, 1) <> "\" Then
//!             targetPath = targetPath & "\"
//!         End If
//!         
//!         FileCopy sourceFile, targetPath & Dir(sourceFile)
//!     End If
//! End Sub
//! ```
//!
//! ### Directory Stack Implementation
//!
//! ```vb
//! Private dirStack As Collection
//!
//! Sub InitDirectoryStack()
//!     Set dirStack = New Collection
//! End Sub
//!
//! Sub PushDir(Optional newDir As String)
//!     If dirStack Is Nothing Then InitDirectoryStack
//!     
//!     ' Save current directory
//!     dirStack.Add CurDir()
//!     
//!     ' Change to new directory if specified
//!     If Len(newDir) > 0 Then
//!         ChDir newDir
//!     End If
//! End Sub
//!
//! Sub PopDir()
//!     If dirStack Is Nothing Then Exit Sub
//!     If dirStack.Count = 0 Then Exit Sub
//!     
//!     ' Restore previous directory
//!     ChDir dirStack(dirStack.Count)
//!     dirStack.Remove dirStack.Count
//! End Sub
//! ```
//!
//! ### Smart Path Concatenation
//!
//! ```vb
//! Function CombinePaths(ParamArray paths() As Variant) As String
//!     Dim result As String
//!     Dim i As Integer
//!     Dim part As String
//!     
//!     If UBound(paths) < LBound(paths) Then
//!         ' No paths provided, return current directory
//!         CombinePaths = CurDir()
//!         Exit Function
//!     End If
//!     
//!     result = CStr(paths(LBound(paths)))
//!     
//!     For i = LBound(paths) + 1 To UBound(paths)
//!         part = CStr(paths(i))
//!         
//!         ' Remove leading backslash from part
//!         If Left(part, 1) = "\" Then part = Mid(part, 2)
//!         
//!         ' Add backslash if needed
//!         If Right(result, 1) <> "\" Then result = result & "\"
//!         
//!         result = result & part
//!     Next i
//!     
//!     CombinePaths = result
//! End Function
//! ```
//!
//! ## Error Handling
//!
//! ```vb
//! Function GetCurrentDirectorySafe(Optional drive As String = "") As String
//!     On Error GoTo ErrorHandler
//!     
//!     If Len(drive) = 0 Then
//!         GetCurrentDirectorySafe = CurDir()
//!     Else
//!         GetCurrentDirectorySafe = CurDir(drive)
//!     End If
//!     
//!     Exit Function
//!     
//! ErrorHandler:
//!     Select Case Err.Number
//!         Case 68  ' Device unavailable
//!             MsgBox "Drive " & drive & " is not available.", vbExclamation
//!         Case 71  ' Disk not ready
//!             MsgBox "Drive " & drive & " is not ready.", vbExclamation
//!         Case Else
//!             MsgBox "Error getting current directory: " & Err.Description, vbCritical
//!     End Select
//!     
//!     GetCurrentDirectorySafe = ""
//! End Function
//! ```
//!
//! ### Common Errors
//!
//! - **Error 68** (Device unavailable): Specified drive does not exist
//! - **Error 71** (Disk not ready): Drive exists but is not ready (e.g., no CD in drive)
//! - **Error 5** (Invalid procedure call): Invalid drive specification
//!
//! ## Performance Considerations
//!
//! - `CurDir` is a fast function with minimal overhead
//! - Results can be cached if directory won't change during execution
//! - Accessing network drives may have latency
//! - For frequently used paths, cache the result in a variable
//!
//! ## Best Practices
//!
//! ### Always Restore Directory
//!
//! ```vb
//! Sub SafeDirectoryOperation()
//!     Dim savedDir As String
//!     savedDir = CurDir()
//!     
//!     On Error GoTo Cleanup
//!     
//!     ' Change directory and do work
//!     ChDir "C:\Temp"
//!     ProcessFiles
//!     
//! Cleanup:
//!     ChDir savedDir
//! End Sub
//! ```
//!
//! ### Use Absolute Paths When Possible
//!
//! ```vb
//! ' Instead of relying on current directory:
//! Open "data.txt" For Input As #1  ' Depends on CurDir
//!
//! ' Use absolute paths:
//! Open "C:\MyApp\Data\data.txt" For Input As #1  ' Explicit path
//! ```
//!
//! ### Validate Drive Before Use
//!
//! ```vb
//! Function IsDriveAvailable(drive As String) As Boolean
//!     On Error Resume Next
//!     Dim test As String
//!     test = CurDir(drive)
//!     IsDriveAvailable = (Err.Number = 0)
//!     On Error GoTo 0
//! End Function
//! ```
//!
//! ## Platform Considerations
//!
//! - **Windows**: Returns paths with backslashes (e.g., "C:\Windows")
//! - **Drive letters**: Windows-specific concept
//! - **Network paths**: `UNC` paths (\\server\share) not supported by `CurDir`
//! - **Long paths**: Paths longer than 260 characters may cause issues
//! - **Case sensitivity**: Windows file system is case-insensitive
//!
//! ## Limitations
//!
//! - Returns only local drive paths, not `UNC` network paths
//! - Cannot set the current directory (use `ChDir` for that)
//! - Drive must be available and ready
//! - Does not validate that the returned path still exists
//! - Each drive remembers its own current directory independently
//! - Does not work with drives that don't have current directory concept
//!
//! ## Related Functions
//!
//! - `ChDir`: Changes the current directory
//! - `ChDrive`: Changes the current drive
//! - `Dir`: Returns files/directories matching a pattern
//! - `MkDir`: Creates a new directory
//! - `RmDir`: Removes an empty directory
//! - `App.Path`: Returns the path where the application started

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

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

    #[test]
    fn curdir_with_drive() {
        let source = r#"
path = CurDir("C")
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_drive_colon() {
        let source = r#"
path = CurDir("C:")
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_assignment() {
        let source = r"
Dim savedDir As String
savedDir = CurDir()
";
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_save_restore() {
        let source = r#"
savedDir = CurDir()
ChDir "C:\Temp"
ChDir savedDir
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_function() {
        let source = r"
Function GetCurrentPath() As String
    GetCurrentPath = CurDir()
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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_concatenation() {
        let source = r#"
fullPath = CurDir() & "\data.txt"
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_if_statement() {
        let source = r#"
If Right(CurDir(), 1) = "\" Then
    ProcessRoot
End If
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

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

    #[test]
    fn curdir_with_left() {
        let source = r"
drive = Left(CurDir(), 1)
";
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_multiple_drives() {
        let source = r#"
cPath = CurDir("C")
dPath = CurDir("D")
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_error_handling() {
        let source = r#"
On Error Resume Next
path = CurDir("X")
If Err.Number <> 0 Then
    MsgBox "Drive not available"
End If
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_msgbox() {
        let source = r#"
MsgBox "Current directory: " & CurDir()
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_variable() {
        let source = r#"
Dim drv As String
drv = "C"
path = CurDir(drv)
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_select_case() {
        let source = r#"
Select Case CurDir()
    Case "C:\"
        ProcessRoot
    Case Else
        ProcessOther
End Select
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_len() {
        let source = r"
If Len(CurDir()) = 3 Then
    isRoot = True
End If
";
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_loop() {
        let source = r#"
For i = 1 To 5
    path = CurDir() & "\file" & i & ".txt"
Next i
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_instr() {
        let source = r#"
If InStr(CurDir(), "Windows") > 0 Then
    ProcessWindowsDir
End If
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_empty_string() {
        let source = r#"
currentPath = CurDir("")
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_print() {
        let source = r#"
Print "Current directory: "; CurDir()
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_comparison() {
        let source = r#"
If CurDir() = "C:\Windows" Then
    ProcessWindows
End If
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_do_loop() {
        let source = r#"
Do While CurDir() <> "C:\"
    ChDir ".."
Loop
"#;
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_mid() {
        let source = r"
pathPart = Mid(CurDir(), 4)
";
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_in_sub() {
        let source = r"
Sub SaveCurrentDir()
    savedPath = 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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn curdir_with_whitespace() {
        let source = r"
path = CurDir( )
";
        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");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}