vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
//! VB6 `WeekdayName` Function
//!
//! The `WeekdayName` function returns a string indicating the specified day of the week.
//!
//! ## Syntax
//! ```vb6
//! WeekdayName(weekday[, abbreviate[, firstdayofweek]])
//! ```
//!
//! ## Parameters
//! - `weekday`: Required. The numeric designation for the day of the week. Numeric value of each day depends on the `firstdayofweek` setting.
//! - `abbreviate`: Optional. Boolean value that indicates if the weekday name is to be abbreviated. If omitted, the default is False (not abbreviated).
//! - `firstdayofweek`: Optional. Numeric value indicating the first day of the week. See Settings section for values.
//!
//! ### `FirstDayOfWeek` Constants
//! - `vbUseSystemDayOfWeek` (0): Use National Language Support (NLS) API setting
//! - `vbSunday` (1): Sunday (default)
//! - `vbMonday` (2): Monday
//! - `vbTuesday` (3): Tuesday
//! - `vbWednesday` (4): Wednesday
//! - `vbThursday` (5): Thursday
//! - `vbFriday` (6): Friday
//! - `vbSaturday` (7): Saturday
//!
//! ## Returns
//! Returns a `String` containing the name of the specified day of the week. The string is localized based on the system's regional settings.
//!
//! ## Remarks
//! The `WeekdayName` function provides localized day names:
//!
//! - **Localization**: Returns day names according to system locale (e.g., "Monday" in English, "Lundi" in French)
//! - **Abbreviation**: When `abbreviate` is True, returns shortened form (e.g., "Mon" instead of "Monday")
//! - **Weekday parameter**: Numeric value from 1 to 7
//! - **Default first day**: Sunday (vbSunday = 1) if `firstdayofweek` not specified
//! - **Consistency with Weekday**: Use same `firstdayofweek` value as Weekday function for consistency
//! - **System locale**: Output language depends on Windows regional settings
//! - **Case sensitivity**: Returned string typically has proper capitalization
//! - **Abbreviation length**: Typically 3 characters in English, varies by locale
//!
//! ### Understanding Weekday Parameter
//! The `weekday` parameter's meaning depends on `firstdayofweek`:
//! - If `firstdayofweek` is `vbSunday` (default): 1=Sunday, 2=Monday, 3=Tuesday, etc.
//! - If `firstdayofweek` is `vbMonday`: 1=Monday, 2=Tuesday, 3=Wednesday, etc.
//! - The number always refers to the position in the week, starting from the specified first day
//!
//! ### Abbreviation Examples (English locale)
//! - Full: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
//! - Abbreviated: "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
//!
//! ### Combining with Weekday Function
//! ```vb6
//! ' Get the name of today's day
//! dayName = WeekdayName(Weekday(Date))
//! ```
//!
//! ## Typical Uses
//! 1. **Display Day Names**: Show user-friendly day names in UI
//! 2. **Report Headers**: Label columns or sections with day names
//! 3. **Calendar Applications**: Display calendar grid headers
//! 4. **Localized Applications**: Provide day names in user's language
//! 5. **Schedule Display**: Show schedule with day names
//! 6. **Date Formatting**: Create custom date format strings
//! 7. **Dropdown Lists**: Populate day selection dropdowns
//! 8. **Log Files**: Human-readable date information in logs
//!
//! ## Basic Examples
//!
//! ### Example 1: Get Today's Day Name
//! ```vb6
//! Sub ShowTodayName()
//!     Dim todayName As String
//!     todayName = WeekdayName(Weekday(Date))
//!     MsgBox "Today is " & todayName
//! End Sub
//! ```
//!
//! ### Example 2: Display All Day Names
//! ```vb6
//! Sub ListAllDays()
//!     Dim i As Integer
//!     For i = 1 To 7
//!         Debug.Print WeekdayName(i)
//!     Next i
//! End Sub
//! ```
//!
//! ### Example 3: Abbreviated Day Names
//! ```vb6
//! Function GetAbbreviatedDayName(dayNumber As Integer) As String
//!     GetAbbreviatedDayName = WeekdayName(dayNumber, True)
//! End Function
//!
//! ' Usage:
//! Debug.Print GetAbbreviatedDayName(1) ' Prints "Sun" (if vbSunday is first day)
//! ```
//!
//! ### Example 4: Create Calendar Header
//! ```vb6
//! Function CreateCalendarHeader(Optional abbreviated As Boolean = True) As String
//!     Dim i As Integer
//!     Dim header As String
//!     
//!     header = ""
//!     For i = 1 To 7
//!         header = header & WeekdayName(i, abbreviated, vbSunday) & vbTab
//!     Next i
//!     
//!     CreateCalendarHeader = header
//! End Function
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: Format Date with Day Name
//! ```vb6
//! Function FormatDateWithDayName(dt As Date) As String
//!     FormatDateWithDayName = WeekdayName(Weekday(dt)) & ", " & Format$(dt, "mmmm d, yyyy")
//! End Function
//! ```
//!
//! ### Pattern 2: Get All Day Names Array
//! ```vb6
//! Function GetDayNamesArray(Optional abbreviated As Boolean = False) As String()
//!     Dim days(1 To 7) As String
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         days(i) = WeekdayName(i, abbreviated)
//!     Next i
//!     
//!     GetDayNamesArray = days
//! End Function
//! ```
//!
//! ### Pattern 3: ISO Week Day Names (Monday First)
//! ```vb6
//! Function GetISODayName(dayNumber As Integer, Optional abbreviated As Boolean = False) As String
//!     GetISODayName = WeekdayName(dayNumber, abbreviated, vbMonday)
//! End Function
//! ```
//!
//! ### Pattern 4: Populate `ComboBox` with Days
//! ```vb6
//! Sub PopulateDayCombo(combo As ComboBox)
//!     Dim i As Integer
//!     combo.Clear
//!     For i = 1 To 7
//!         combo.AddItem WeekdayName(i)
//!     Next i
//! End Sub
//! ```
//!
//! ### Pattern 5: Get Day Initials
//! ```vb6
//! Function GetDayInitial(dayNumber As Integer) As String
//!     GetDayInitial = Left$(WeekdayName(dayNumber, True), 1)
//! End Function
//! ```
//!
//! ### Pattern 6: Create Week Schedule Header
//! ```vb6
//! Function CreateWeekSchedule() As String
//!     Dim i As Integer
//!     Dim schedule As String
//!     
//!     schedule = "Week Schedule:" & vbCrLf
//!     For i = 1 To 7
//!         schedule = schedule & WeekdayName(i) & ": _____" & vbCrLf
//!     Next i
//!     
//!     CreateWeekSchedule = schedule
//! End Function
//! ```
//!
//! ### Pattern 7: Format Event Description
//! ```vb6
//! Function FormatEventDescription(eventDate As Date, eventName As String) As String
//!     FormatEventDescription = eventName & " on " & _
//!                             WeekdayName(Weekday(eventDate)) & ", " & _
//!                             Format$(eventDate, "mmmm d")
//! End Function
//! ```
//!
//! ### Pattern 8: Get Weekday vs Weekend Label
//! ```vb6
//! Function GetDayTypeLabel(dt As Date) As String
//!     Dim dayNum As Integer
//!     dayNum = Weekday(dt)
//!     
//!     If dayNum = vbSaturday Or dayNum = vbSunday Then
//!         GetDayTypeLabel = WeekdayName(dayNum) & " (Weekend)"
//!     Else
//!         GetDayTypeLabel = WeekdayName(dayNum) & " (Weekday)"
//!     End If
//! End Function
//! ```
//!
//! ### Pattern 9: Create Pivot Headers
//! ```vb6
//! Function CreatePivotDayHeaders() As Variant
//!     Dim headers(1 To 7) As String
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         headers(i) = WeekdayName(i, True, vbMonday)
//!     Next i
//!     
//!     CreatePivotDayHeaders = headers
//! End Function
//! ```
//!
//! ### Pattern 10: Conditional Day Name Display
//! ```vb6
//! Function GetDisplayDayName(dt As Date, useAbbreviation As Boolean) As String
//!     GetDisplayDayName = WeekdayName(Weekday(dt), useAbbreviation)
//! End Function
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: Calendar Header Generator Class
//! ```vb6
//! ' Class: CalendarHeaderGenerator
//! ' Generates calendar headers with configurable options
//! Option Explicit
//!
//! Private m_FirstDayOfWeek As VbDayOfWeek
//! Private m_Abbreviated As Boolean
//! Private m_Separator As String
//!
//! Public Sub Initialize(Optional firstDay As VbDayOfWeek = vbSunday, _
//!                      Optional abbreviated As Boolean = True, _
//!                      Optional separator As String = " ")
//!     m_FirstDayOfWeek = firstDay
//!     m_Abbreviated = abbreviated
//!     m_Separator = separator
//! End Sub
//!
//! Public Function GenerateHeader() As String
//!     Dim i As Integer
//!     Dim header As String
//!     
//!     header = ""
//!     For i = 1 To 7
//!         If i > 1 Then header = header & m_Separator
//!         header = header & WeekdayName(i, m_Abbreviated, m_FirstDayOfWeek)
//!     Next i
//!     
//!     GenerateHeader = header
//! End Function
//!
//! Public Function GenerateHeaderArray() As String()
//!     Dim headers(1 To 7) As String
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         headers(i) = WeekdayName(i, m_Abbreviated, m_FirstDayOfWeek)
//!     Next i
//!     
//!     GenerateHeaderArray = headers
//! End Function
//!
//! Public Function GetDayName(dayNumber As Integer) As String
//!     If dayNumber < 1 Or dayNumber > 7 Then
//!         Err.Raise 5, , "Day number must be between 1 and 7"
//!     End If
//!     GetDayName = WeekdayName(dayNumber, m_Abbreviated, m_FirstDayOfWeek)
//! End Function
//! ```
//!
//! ### Example 2: Date Formatter Module
//! ```vb6
//! ' Module: DateFormatter
//! ' Advanced date formatting with day names
//! Option Explicit
//!
//! Public Function FormatLongDate(dt As Date) As String
//!     FormatLongDate = WeekdayName(Weekday(dt)) & ", " & _
//!                     Format$(dt, "mmmm d, yyyy")
//! End Function
//!
//! Public Function FormatShortDate(dt As Date) As String
//!     FormatShortDate = WeekdayName(Weekday(dt), True) & " " & _
//!                      Format$(dt, "mm/dd/yyyy")
//! End Function
//!
//! Public Function FormatScheduleDate(dt As Date) As String
//!     FormatScheduleDate = WeekdayName(Weekday(dt), True) & ", " & _
//!                         Format$(dt, "mmm d")
//! End Function
//!
//! Public Function FormatCalendarDate(dt As Date) As String
//!     FormatCalendarDate = WeekdayName(Weekday(dt)) & vbCrLf & _
//!                         Format$(dt, "d")
//! End Function
//!
//! Public Function GetDayWithOrdinal(dt As Date) As String
//!     Dim dayNum As Integer
//!     Dim suffix As String
//!     
//!     dayNum = Day(dt)
//!     
//!     Select Case dayNum
//!         Case 1, 21, 31
//!             suffix = "st"
//!         Case 2, 22
//!             suffix = "nd"
//!         Case 3, 23
//!             suffix = "rd"
//!         Case Else
//!             suffix = "th"
//!     End Select
//!     
//!     GetDayWithOrdinal = WeekdayName(Weekday(dt)) & ", " & _
//!                        MonthName(Month(dt)) & " " & dayNum & suffix
//! End Function
//! ```
//!
//! ### Example 3: Schedule Analyzer Class
//! ```vb6
//! ' Class: ScheduleAnalyzer
//! ' Analyzes schedules and provides day-based insights
//! Option Explicit
//!
//! Public Function GetDayDistributionReport(dates() As Date) As String
//!     Dim dayCounts(1 To 7) As Integer
//!     Dim i As Long
//!     Dim report As String
//!     Dim dayNum As Integer
//!     
//!     ' Count occurrences
//!     For i = LBound(dates) To UBound(dates)
//!         dayNum = Weekday(dates(i))
//!         dayCounts(dayNum) = dayCounts(dayNum) + 1
//!     Next i
//!     
//!     ' Build report
//!     report = "Day Distribution:" & vbCrLf
//!     For i = 1 To 7
//!         report = report & WeekdayName(i) & ": " & dayCounts(i) & vbCrLf
//!     Next i
//!     
//!     GetDayDistributionReport = report
//! End Function
//!
//! Public Function GetMostCommonDay(dates() As Date) As String
//!     Dim dayCounts(1 To 7) As Integer
//!     Dim i As Long
//!     Dim maxCount As Integer
//!     Dim maxDay As Integer
//!     Dim dayNum As Integer
//!     
//!     For i = LBound(dates) To UBound(dates)
//!         dayNum = Weekday(dates(i))
//!         dayCounts(dayNum) = dayCounts(dayNum) + 1
//!     Next i
//!     
//!     maxCount = 0
//!     maxDay = 1
//!     For i = 1 To 7
//!         If dayCounts(i) > maxCount Then
//!             maxCount = dayCounts(i)
//!             maxDay = i
//!         End If
//!     Next i
//!     
//!     GetMostCommonDay = WeekdayName(maxDay)
//! End Function
//!
//! Public Function CreateDaySummary(dates() As Date) As Collection
//!     Dim summary As New Collection
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         summary.Add 0, WeekdayName(i)
//!     Next i
//!     
//!     Dim dt As Variant
//!     For Each dt In dates
//!         Dim dayName As String
//!         dayName = WeekdayName(Weekday(dt))
//!         summary.Remove dayName
//!         summary.Add summary(dayName) + 1, dayName
//!     Next dt
//!     
//!     Set CreateDaySummary = summary
//! End Function
//! ```
//!
//! ### Example 4: Localization Helper Module
//! ```vb6
//! ' Module: LocalizationHelper
//! ' Helps with localized day name handling
//! Option Explicit
//!
//! Public Function GetLocalizedDayNames(Optional abbreviated As Boolean = False, _
//!                                     Optional firstDay As VbDayOfWeek = vbSunday) As String()
//!     Dim names(1 To 7) As String
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         names(i) = WeekdayName(i, abbreviated, firstDay)
//!     Next i
//!     
//!     GetLocalizedDayNames = names
//! End Function
//!
//! Public Function CreateDayNameLookup(Optional abbreviated As Boolean = False) As Collection
//!     Dim lookup As New Collection
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         lookup.Add WeekdayName(i, abbreviated), CStr(i)
//!     Next i
//!     
//!     Set CreateDayNameLookup = lookup
//! End Function
//!
//! Public Function FindDayNumber(dayName As String) As Integer
//!     Dim i As Integer
//!     
//!     For i = 1 To 7
//!         If UCase$(WeekdayName(i)) = UCase$(dayName) Then
//!             FindDayNumber = i
//!             Exit Function
//!         End If
//!         If UCase$(WeekdayName(i, True)) = UCase$(dayName) Then
//!             FindDayNumber = i
//!             Exit Function
//!         End If
//!     Next i
//!     
//!     FindDayNumber = 0 ' Not found
//! End Function
//!
//! Public Function IsDayNameValid(dayName As String) As Boolean
//!     IsDayNameValid = (FindDayNumber(dayName) > 0)
//! End Function
//!
//! Public Function NormalizeDayName(dayName As String) As String
//!     Dim dayNum As Integer
//!     dayNum = FindDayNumber(dayName)
//!     
//!     If dayNum > 0 Then
//!         NormalizeDayName = WeekdayName(dayNum)
//!     Else
//!         NormalizeDayName = ""
//!     End If
//! End Function
//! ```
//!
//! ## Error Handling
//! The `WeekdayName` function can raise the following errors:
//!
//! - **Error 5 (Invalid procedure call or argument)**: If `weekday` is less than 1 or greater than 7
//! - **Error 5 (Invalid procedure call or argument)**: If `firstdayofweek` is not between 0 and 7
//! - **Error 13 (Type mismatch)**: If arguments are not of correct type
//!
//! ## Performance Notes
//! - Very fast operation - simple lookup/formatting
//! - Constant time O(1) complexity
//! - No significant performance difference between abbreviated and full forms
//! - Can be called repeatedly without performance concerns
//! - Consider caching day name arrays if used frequently in loops
//!
//! ## Best Practices
//! 1. **Use consistent firstdayofweek** with Weekday function to avoid confusion
//! 2. **Cache day name arrays** if populating lists or grids repeatedly
//! 3. **Handle localization** - day names will differ based on system locale
//! 4. **Document expectations** about which day is first in week
//! 5. **Use abbreviation** parameter for space-constrained displays
//! 6. **Validate weekday range** (1-7) before calling
//! 7. **Consider `MonthName`** for consistent date formatting patterns
//! 8. **Test with different locales** if application is internationalized
//! 9. **Use named constants** (vbMonday, etc.) for clarity
//! 10. **Combine with Format$** for custom date displays
//!
//! ## Comparison Table
//!
//! | Function | Purpose | Returns | Localized |
//! |----------|---------|---------|-----------|
//! | `WeekdayName` | Get day name | String | Yes |
//! | `Weekday` | Get day number | Integer (1-7) | No |
//! | `MonthName` | Get month name | String | Yes |
//! | `Format$` | Format date | String | Partially |
//!
//! ## Platform Notes
//! - Available in VB6, VBA, and `VBScript`
//! - Behavior consistent across platforms
//! - Output localized based on system regional settings
//! - Abbreviation format varies by locale
//! - English (US): "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
//! - Other languages will return appropriate translations
//!
//! ## Limitations
//! - Cannot customize day name output (uses system locale)
//! - Abbreviation length not configurable (determined by locale)
//! - No way to get day name in specific language (uses system setting)
//! - Cannot get day names for custom calendars (e.g., Hebrew, Islamic)
//! - No built-in way to get single-letter day abbreviations
//! - Cannot specify case (capitalization) of returned string

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

    #[test]
    fn weekdayname_basic() {
        let source = r"
Sub Test()
    dayName = WeekdayName(1)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_variable_assignment() {
        let source = r"
Sub Test()
    Dim name As String
    name = WeekdayName(dayNumber)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_with_abbreviate() {
        let source = r"
Sub Test()
    shortName = WeekdayName(3, 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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_all_parameters() {
        let source = r"
Sub Test()
    name = WeekdayName(2, False, vbMonday)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_with_weekday() {
        let source = r"
Sub Test()
    todayName = WeekdayName(Weekday(Date))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_for_loop() {
        let source = r"
Sub Test()
    For i = 1 To 7
        Debug.Print WeekdayName(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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_msgbox() {
        let source = r#"
Sub Test()
    MsgBox "Today is " & WeekdayName(Weekday(Date))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_function_return() {
        let source = r"
Function GetDayName(dayNum As Integer) As String
    GetDayName = WeekdayName(dayNum)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_array_assignment() {
        let source = r"
Sub Test()
    dayNames(i) = WeekdayName(i, 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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_concatenation() {
        let source = r"
Sub Test()
    header = WeekdayName(1, True) & vbTab & WeekdayName(2, 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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_function_argument() {
        let source = r"
Sub Test()
    Call DisplayDay(WeekdayName(dayNum))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_debug_print() {
        let source = r"
Sub Test()
    Debug.Print WeekdayName(vbMonday)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_select_case() {
        let source = r#"
Sub Test()
    Select Case WeekdayName(Weekday(dt))
        Case "Monday"
            DoMonday
        Case "Friday"
            DoFriday
    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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_if_statement() {
        let source = r#"
Sub Test()
    If WeekdayName(Weekday(dt)) = "Saturday" Then
        IsWeekend = True
    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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_comparison() {
        let source = r"
Sub Test()
    If WeekdayName(day1) = WeekdayName(day2) Then
        SameDay
    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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_format() {
        let source = r#"
Sub Test()
    formatted = WeekdayName(Weekday(dt)) & ", " & Format$(dt, "mmmm d, yyyy")
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_property_assignment() {
        let source = r"
Sub Test()
    obj.DayName = WeekdayName(obj.DayNumber)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_with_statement() {
        let source = r"
Sub Test()
    With dateInfo
        .Name = WeekdayName(.DayNumber, .Abbreviate)
    End With
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_parentheses() {
        let source = r"
Sub Test()
    result = (WeekdayName(dayNum))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_error_handling() {
        let source = r#"
Sub Test()
    On Error Resume Next
    name = WeekdayName(userInput)
    If Err.Number <> 0 Then
        name = "Invalid"
    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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_print_statement() {
        let source = r"
Sub Test()
    Print #1, WeekdayName(i, 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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_class_usage() {
        let source = r"
Sub Test()
    Set formatter = New DateFormatter
    formatter.DayName = WeekdayName(Weekday(formatter.TargetDate))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_elseif() {
        let source = r#"
Sub Test()
    If x = 1 Then
        y = 1
    ElseIf WeekdayName(Weekday(dt)) = "Monday" Then
        y = 2
    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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_do_while() {
        let source = r#"
Sub Test()
    Do While WeekdayName(Weekday(dt), True) <> "Mon"
        dt = dt + 1
    Loop
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_left_function() {
        let source = r"
Sub Test()
    initial = Left$(WeekdayName(dayNum, True), 1)
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_ucase() {
        let source = r"
Sub Test()
    upperName = UCase$(WeekdayName(dayNum))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_iif() {
        let source = r"
Sub Test()
    display = IIf(abbreviated, WeekdayName(day, True), WeekdayName(day, False))
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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn weekdayname_collection_add() {
        let source = r"
Sub Test()
    days.Add WeekdayName(i), CStr(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/datetime/weekdayname",
        );
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}