vb6parse 1.0.0

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
1092
1093
1094
1095
1096
1097
1098
1099
1100
//! # `LCase` Function
//!
//! Returns a `String` that has been converted to lowercase.
//!
//! ## Syntax
//!
//! ```vb
//! LCase(string)
//! ```
//!
//! ## Parameters
//!
//! - `string` (Required): Any valid string expression
//!   - If string contains `Null`, `Null` is returned
//!
//! ## Return Value
//!
//! Returns a `String`:
//! - Contains the same string with all uppercase letters converted to lowercase
//! - Lowercase letters and non-alphabetic characters are unchanged
//! - Returns `Null` if string argument is `Null`
//! - Empty string returns empty string
//! - Only affects A-Z characters (not accented characters in some locales)
//! - Numbers, punctuation, and symbols are unchanged
//! - Whitespace is preserved
//!
//! ## Remarks
//!
//! The `LCase` function converts uppercase letters to lowercase:
//!
//! - Only affects uppercase letters A-Z
//! - All other characters remain unchanged
//! - Counterpart to `UCase` function (converts to uppercase)
//! - `Null` propagates through the function (`Null` input returns `Null`)
//! - Does not modify the original string (strings are immutable in VB6)
//! - Locale-aware in some versions (may affect accented characters)
//! - Common for case-insensitive string comparisons
//! - Useful for normalizing user input
//! - Works with string variables, literals, and expressions
//! - Can be combined with other string functions (`Trim`, `Replace`, etc.)
//! - Performance is generally fast for typical strings
//! - For single character, consider using `LCase$` for slightly better performance
//! - `LCase$` variant returns `String` type (not `Variant`)
//!
//! ## Typical Uses
//!
//! 1. **Case-Insensitive Comparison**: Compare strings ignoring case
//! 2. **User Input Normalization**: Convert user input to consistent case
//! 3. **File Path Comparison**: Compare file paths case-insensitively (on Windows)
//! 4. **Search Operations**: Case-insensitive text searching
//! 5. **Data Validation**: Normalize data for validation
//! 6. **Database Queries**: Prepare strings for case-insensitive matching
//! 7. **Email Addresses**: Normalize email addresses to lowercase
//! 8. **Configuration Keys**: Standardize configuration key format
//!
//! ## Basic Usage Examples
//!
//! ```vb
//! ' Example 1: Basic lowercase conversion
//! Dim result As String
//!
//! result = LCase("HELLO")              ' "hello"
//! result = LCase("Hello World")        ' "hello world"
//! result = LCase("VB6 Programming")    ' "vb6 programming"
//!
//! ' Example 2: Case-insensitive comparison
//! Dim input As String
//! input = "Yes"
//!
//! If LCase(input) = "yes" Then
//!     MsgBox "User answered yes"
//! End If
//!
//! ' Example 3: Mixed case preservation
//! Dim text As String
//! text = "Hello123WORLD"
//!
//! Debug.Print LCase(text)              ' "hello123world" - numbers unchanged
//!
//! ' Example 4: Null handling
//! Dim value As Variant
//! value = Null
//!
//! Debug.Print IsNull(LCase(value))     ' True - Null propagates
//! ```
//!
//! ## Common Patterns
//!
//! ```vb
//! ' Pattern 1: Case-insensitive string comparison
//! Function EqualsIgnoreCase(str1 As String, str2 As String) As Boolean
//!     EqualsIgnoreCase = (LCase(str1) = LCase(str2))
//! End Function
//!
//! ' Pattern 2: Case-insensitive contains check
//! Function ContainsIgnoreCase(text As String, searchFor As String) As Boolean
//!     ContainsIgnoreCase = (InStr(1, LCase(text), LCase(searchFor)) > 0)
//! End Function
//!
//! ' Pattern 3: Normalize user input
//! Function NormalizeInput(userInput As String) As String
//!     NormalizeInput = LCase(Trim(userInput))
//! End Function
//!
//! ' Pattern 4: Validate yes/no input
//! Function IsYes(input As String) As Boolean
//!     Select Case LCase(Trim(input))
//!         Case "yes", "y", "true", "1"
//!             IsYes = True
//!         Case Else
//!             IsYes = False
//!     End Select
//! End Function
//!
//! ' Pattern 5: Case-insensitive array search
//! Function FindInArray(arr As Variant, searchValue As String) As Long
//!     Dim i As Long
//!     Dim searchLower As String
//!     
//!     FindInArray = -1
//!     If Not IsArray(arr) Then Exit Function
//!     
//!     searchLower = LCase(searchValue)
//!     For i = LBound(arr) To UBound(arr)
//!         If LCase(arr(i)) = searchLower Then
//!             FindInArray = i
//!             Exit Function
//!         End If
//!     Next i
//! End Function
//!
//! ' Pattern 6: Extract lowercase letters only
//! Function GetLowercaseLetters(text As String) As String
//!     Dim i As Long
//!     Dim char As String
//!     Dim result As String
//!     
//!     result = ""
//!     For i = 1 To Len(text)
//!         char = Mid(text, i, 1)
//!         If char = LCase(char) And char >= "a" And char <= "z" Then
//!             result = result & char
//!         End If
//!     Next i
//!     
//!     GetLowercaseLetters = result
//! End Function
//!
//! ' Pattern 7: Normalize email address
//! Function NormalizeEmail(email As String) As String
//!     NormalizeEmail = LCase(Trim(email))
//! End Function
//!
//! ' Pattern 8: Case-insensitive Replace
//! Function ReplaceIgnoreCase(text As String, findStr As String, _
//!                            replaceStr As String) As String
//!     Dim pos As Long
//!     Dim result As String
//!     Dim textLower As String
//!     Dim findLower As String
//!     
//!     result = text
//!     textLower = LCase(text)
//!     findLower = LCase(findStr)
//!     
//!     pos = InStr(1, textLower, findLower)
//!     Do While pos > 0
//!         result = Left(result, pos - 1) & replaceStr & _
//!                  Mid(result, pos + Len(findStr))
//!         textLower = LCase(result)
//!         pos = InStr(pos + Len(replaceStr), textLower, findLower)
//!     Loop
//!     
//!     ReplaceIgnoreCase = result
//! End Function
//!
//! ' Pattern 9: Check if string is all lowercase
//! Function IsAllLowercase(text As String) As Boolean
//!     IsAllLowercase = (text = LCase(text))
//! End Function
//!
//! ' Pattern 10: Toggle case
//! Function ToggleCase(text As String) As String
//!     Dim i As Long
//!     Dim char As String
//!     Dim result As String
//!     
//!     result = ""
//!     For i = 1 To Len(text)
//!         char = Mid(text, i, 1)
//!         If char = UCase(char) Then
//!             result = result & LCase(char)
//!         Else
//!             result = result & UCase(char)
//!         End If
//!     Next i
//!     
//!     ToggleCase = result
//! End Function
//! ```
//!
//! ## Advanced Usage Examples
//!
//! ```vb
//! ' Example 1: Case-insensitive dictionary/lookup
//! Public Class CaseInsensitiveDictionary
//!     Private m_dict As Object  ' Scripting.Dictionary
//!     
//!     Private Sub Class_Initialize()
//!         Set m_dict = CreateObject("Scripting.Dictionary")
//!         m_dict.CompareMode = vbTextCompare  ' Alternative to LCase
//!     End Sub
//!     
//!     Public Sub Add(key As String, value As Variant)
//!         Dim keyLower As String
//!         keyLower = LCase(key)
//!         
//!         If m_dict.Exists(keyLower) Then
//!             Err.Raise 457, "CaseInsensitiveDictionary", "Key already exists"
//!         End If
//!         
//!         If IsObject(value) Then
//!             Set m_dict(keyLower) = value
//!         Else
//!             m_dict(keyLower) = value
//!         End If
//!     End Sub
//!     
//!     Public Function Get(key As String) As Variant
//!         Dim keyLower As String
//!         keyLower = LCase(key)
//!         
//!         If Not m_dict.Exists(keyLower) Then
//!             Err.Raise 5, "CaseInsensitiveDictionary", "Key not found"
//!         End If
//!         
//!         If IsObject(m_dict(keyLower)) Then
//!             Set Get = m_dict(keyLower)
//!         Else
//!             Get = m_dict(keyLower)
//!         End If
//!     End Function
//!     
//!     Public Function Exists(key As String) As Boolean
//!         Exists = m_dict.Exists(LCase(key))
//!     End Function
//!     
//!     Public Sub Remove(key As String)
//!         m_dict.Remove LCase(key)
//!     End Sub
//! End Class
//!
//! ' Example 2: Text search with case-insensitive highlighting
//! Public Class TextHighlighter
//!     Public Function Highlight(text As String, searchTerm As String, _
//!                               highlightStart As String, _
//!                               highlightEnd As String) As String
//!         Dim result As String
//!         Dim pos As Long
//!         Dim lastPos As Long
//!         Dim textLower As String
//!         Dim searchLower As String
//!         
//!         If Len(searchTerm) = 0 Then
//!             Highlight = text
//!             Exit Function
//!         End If
//!         
//!         result = ""
//!         lastPos = 1
//!         textLower = LCase(text)
//!         searchLower = LCase(searchTerm)
//!         
//!         pos = InStr(lastPos, textLower, searchLower)
//!         Do While pos > 0
//!             ' Add text before match
//!             result = result & Mid(text, lastPos, pos - lastPos)
//!             ' Add highlighted match
//!             result = result & highlightStart & _
//!                      Mid(text, pos, Len(searchTerm)) & highlightEnd
//!             
//!             lastPos = pos + Len(searchTerm)
//!             pos = InStr(lastPos, textLower, searchLower)
//!         Loop
//!         
//!         ' Add remaining text
//!         result = result & Mid(text, lastPos)
//!         
//!         Highlight = result
//!     End Function
//! End Class
//!
//! ' Example 3: String matcher with wildcards
//! Public Class WildcardMatcher
//!     Public Function Matches(text As String, pattern As String, _
//!                             Optional caseSensitive As Boolean = False) As Boolean
//!         Dim textToMatch As String
//!         Dim patternToMatch As String
//!         
//!         If caseSensitive Then
//!             textToMatch = text
//!             patternToMatch = pattern
//!         Else
//!             textToMatch = LCase(text)
//!             patternToMatch = LCase(pattern)
//!         End If
//!         
//!         Matches = MatchesInternal(textToMatch, patternToMatch)
//!     End Function
//!     
//!     Private Function MatchesInternal(text As String, pattern As String) As Boolean
//!         ' Simple wildcard matching (* = any chars, ? = any single char)
//!         If pattern = "*" Then
//!             MatchesInternal = True
//!             Exit Function
//!         End If
//!         
//!         If Len(pattern) = 0 Then
//!             MatchesInternal = (Len(text) = 0)
//!             Exit Function
//!         End If
//!         
//!         If Left(pattern, 1) = "*" Then
//!             ' Try matching rest of pattern at various positions
//!             Dim i As Long
//!             For i = 0 To Len(text)
//!                 If MatchesInternal(Mid(text, i + 1), Mid(pattern, 2)) Then
//!                     MatchesInternal = True
//!                     Exit Function
//!                 End If
//!             Next i
//!             MatchesInternal = False
//!         ElseIf Left(pattern, 1) = "?" Then
//!             If Len(text) > 0 Then
//!                 MatchesInternal = MatchesInternal(Mid(text, 2), Mid(pattern, 2))
//!             Else
//!                 MatchesInternal = False
//!             End If
//!         Else
//!             If Len(text) > 0 And Left(text, 1) = Left(pattern, 1) Then
//!                 MatchesInternal = MatchesInternal(Mid(text, 2), Mid(pattern, 2))
//!             Else
//!                 MatchesInternal = False
//!             End If
//!         End If
//!     End Function
//! End Class
//!
//! ' Example 4: Command parser with case-insensitive commands
//! Public Class CommandParser
//!     Private m_commands As Collection
//!     
//!     Private Sub Class_Initialize()
//!         Set m_commands = New Collection
//!     End Sub
//!     
//!     Public Sub RegisterCommand(commandName As String, handler As Object)
//!         m_commands.Add handler, LCase(commandName)
//!     End Sub
//!     
//!     Public Function Parse(input As String) As Boolean
//!         Dim parts() As String
//!         Dim command As String
//!         Dim handler As Object
//!         
//!         Parse = False
//!         input = Trim(input)
//!         If Len(input) = 0 Then Exit Function
//!         
//!         parts = Split(input, " ")
//!         If UBound(parts) < 0 Then Exit Function
//!         
//!         command = LCase(parts(0))
//!         
//!         On Error Resume Next
//!         Set handler = m_commands(command)
//!         On Error GoTo 0
//!         
//!         If Not handler Is Nothing Then
//!             ' Execute command handler
//!             ' handler.Execute(parts)
//!             Parse = True
//!         End If
//!     End Function
//!     
//!     Public Function GetCommandList() As String
//!         Dim i As Long
//!         Dim result As String
//!         
//!         result = ""
//!         For i = 1 To m_commands.Count
//!             If i > 1 Then result = result & ", "
//!             ' Note: Can't easily get key from Collection
//!             ' This is simplified example
//!         Next i
//!         
//!         GetCommandList = result
//!     End Function
//! End Class
//! ```
//!
//! ## Error Handling
//!
//! `LCase` handles special cases gracefully:
//!
//! ```vb
//! ' Empty string returns empty string
//! Debug.Print LCase("")                ' ""
//!
//! ' Null propagates
//! Dim value As Variant
//! value = Null
//! Debug.Print IsNull(LCase(value))     ' True
//!
//! ' Non-alphabetic characters unchanged
//! Debug.Print LCase("123!@#")          ' "123!@#"
//!
//! ' Mixed content
//! Debug.Print LCase("ABC123xyz")       ' "abc123xyz"
//!
//! ' Safe pattern with Null check
//! Function SafeLCase(value As Variant) As String
//!     If IsNull(value) Then
//!         SafeLCase = ""
//!     Else
//!         SafeLCase = LCase(value)
//!     End If
//! End Function
//! ```
//!
//! ## Performance Considerations
//!
//! - **Fast Operation**: `LCase` is generally very fast
//! - **String Creation**: Creates new string (strings are immutable)
//! - **Repeated Calls**: Cache result if using same lowercase value multiple times
//! - **`LCase$` Variant**: Use `LCase$` for `String` return type (slightly faster)
//!
//! Performance tips:
//! ```vb
//! ' Less efficient - multiple conversions
//! If LCase(str1) = LCase(str2) And LCase(str1) = LCase(str3) Then
//!
//! ' More efficient - cache conversion
//! Dim str1Lower As String
//! str1Lower = LCase(str1)
//! If str1Lower = LCase(str2) And str1Lower = LCase(str3) Then
//! ```
//!
//! ## Best Practices
//!
//! 1. **Case-Insensitive Comparisons**: Always use `LCase` for both operands
//! 2. **Null Handling**: Check for `Null` before calling `LCase` if needed
//! 3. **Cache Results**: Store converted strings when used multiple times
//! 4. **Database Comparisons**: Use `LCase` to normalize before database queries
//! 5. **User Input**: Always normalize user input with `LCase` + `Trim`
//! 6. **Email Addresses**: Convert email addresses to lowercase for storage/comparison
//! 7. **File Extensions**: Use `LCase` when comparing file extensions
//! 8. **Configuration**: Use consistent casing for configuration keys
//!
//! ## Comparison with Related Functions
//!
//! | Function | Purpose | Returns | Use Case |
//! |----------|---------|---------|----------|
//! | `LCase` | Convert to lowercase | `String` | Lowercase conversion |
//! | `UCase` | Convert to uppercase | `String` | Uppercase conversion |
//! | `StrComp` | Compare strings | `Integer` | Case-sensitive or insensitive comparison |
//! | `Trim` | Remove whitespace | `String` | Cleanup whitespace |
//! | `Left`/`Right`/`Mid` | Extract substring | `String` | Substring extraction |
//!
//! ## `LCase` vs `StrComp`
//!
//! ```vb
//! Dim str1 As String, str2 As String
//! str1 = "Hello"
//! str2 = "HELLO"
//!
//! ' Using LCase for comparison
//! If LCase(str1) = LCase(str2) Then
//!     MsgBox "Equal (case-insensitive)"
//! End If
//!
//! ' Using StrComp for comparison
//! If StrComp(str1, str2, vbTextCompare) = 0 Then
//!     MsgBox "Equal (case-insensitive)"
//! End If
//!
//! ' LCase is more explicit and readable for simple comparisons
//! ' StrComp is better when you need the comparison result (-1, 0, 1)
//! ```
//!
//! ## `LCase$` Variant
//!
//! ```vb
//! ' LCase returns Variant
//! Dim result As Variant
//! result = LCase("HELLO")
//!
//! ' LCase$ returns String (slightly faster, cannot handle Null)
//! Dim resultStr As String
//! resultStr = LCase$("HELLO")
//!
//! ' LCase$ will error on Null
//! ' resultStr = LCase$(Null)  ' Error 94: Invalid use of Null
//! ```
//!
//! ## Platform and Version Notes
//!
//! - Available in all VB6 versions
//! - Part of VBA core functions
//! - Returns `Variant` containing `String` (`LCase$` returns `String` type)
//! - Locale-aware in some implementations
//! - Only converts A-Z in most locales
//! - Accented characters may or may not be converted depending on locale
//!
//! ## Limitations
//!
//! - Only converts standard ASCII uppercase letters (A-Z)
//! - Accented characters may not be converted consistently
//! - Does not handle Unicode case mapping comprehensively
//! - Cannot convert specific ranges of characters
//! - No option to preserve certain characters
//! - Creates new string (cannot modify in place)
//!
//! ## Related Functions
//!
//! - `UCase`: Convert string to uppercase
//! - `StrComp`: Compare strings with case options
//! - `Trim`/`LTrim`/`RTrim`: Remove whitespace
//! - `Replace`: Replace substrings (with case-sensitive option)
//! - `InStr`: Find substring (can be case-insensitive)

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

    #[test]
    fn lcase_basic() {
        let source = r"
Sub Test()
    result = LCase(myString)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_string_literal() {
        let source = r#"
Sub Test()
    result = LCase("HELLO")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_if_statement() {
        let source = r#"
Sub Test()
    If LCase(input) = "yes" Then
        ProcessYes
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_function_return() {
        let source = r"
Function Normalize(text As String) As String
    Normalize = LCase(text)
End Function
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_comparison() {
        let source = r#"
Sub Test()
    If LCase(str1) = LCase(str2) Then
        MsgBox "Equal"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_debug_print() {
        let source = r#"
Sub Test()
    Debug.Print LCase("TEST")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_msgbox() {
        let source = r"
Sub Test()
    MsgBox LCase(userName)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_variable_assignment() {
        let source = r"
Sub Test()
    Dim lower As String
    lower = LCase(original)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_property_assignment() {
        let source = r"
Sub Test()
    obj.LowerText = LCase(obj.Text)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_concatenation() {
        let source = r#"
Sub Test()
    result = "Value: " & LCase(data)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_in_class() {
        let source = r"
Private Sub Class_Initialize()
    m_key = LCase(m_name)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_with_statement() {
        let source = r"
Sub Test()
    With record
        .NormalizedName = LCase(.Name)
    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/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_function_argument() {
        let source = r"
Sub Test()
    Call ProcessString(LCase(input))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_select_case() {
        let source = r#"
Sub Test()
    Select Case LCase(command)
        Case "open"
            OpenFile
        Case "close"
            CloseFile
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_for_loop() {
        let source = r"
Sub Test()
    Dim i As Integer
    For i = 0 To UBound(arr)
        arr(i) = LCase(arr(i))
    Next i
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_elseif() {
        let source = r#"
Sub Test()
    If LCase(value) = "a" Then
        HandleA
    ElseIf LCase(value) = "b" Then
        HandleB
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_iif() {
        let source = r#"
Sub Test()
    result = IIf(LCase(status) = "active", 1, 0)
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_parentheses() {
        let source = r"
Sub Test()
    result = (LCase(text))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_array_assignment() {
        let source = r"
Sub Test()
    normalized(i) = LCase(original(i))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_collection_add() {
        let source = r"
Sub Test()
    keywords.Add LCase(word)
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_nested_call() {
        let source = r"
Sub Test()
    result = Trim(LCase(input))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_while_wend() {
        let source = r#"
Sub Test()
    While LCase(response) <> "quit"
        response = InputBox("Command:")
    Wend
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_do_while() {
        let source = r#"
Sub Test()
    Do While LCase(line) <> "end"
        line = ReadLine()
    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/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_do_until() {
        let source = r#"
Sub Test()
    Do Until LCase(answer) = "yes"
        answer = InputBox("Continue?")
    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/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_instr() {
        let source = r"
Sub Test()
    pos = InStr(1, LCase(text), LCase(search))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_with_trim() {
        let source = r"
Sub Test()
    normalized = LCase(Trim(userInput))
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn lcase_dictionary_key() {
        let source = r"
Sub Test()
    dict.Add LCase(key), value
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/string/lcase");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}