-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest_generation_from_code.txt
1096 lines (784 loc) · 34.1 KB
/
Test_generation_from_code.txt
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
Option Explicit
' InExSu 18.05.2019 15:50
'26.01.2019 23:12:41
' ' https://www.youtube.com/channel/UCQMbRhaPEFa1NoZLhRzQzSA/videos?view=0&shelf_id=0&sort=dd
' https://inexsu.wordpress.com
Public Const VAR_PREF As String = "var_"
Public Const ARRAY_SIGN As String = "{}"
'Test generation from code
Public Type String_Cut
' для вырезки парных символов
str As String
symb As String
Position_01 As Long
Position_02 As Long
End Type
Public Module_Test_code_Global As String ' коды функций
Public Module_Test_code As String ' код одной функции
Public Proc_Call_Bracket As String ' вызов функции, аргументы в скобках
Public Proc_Return_Type As String 'тип возвращаемый процедурой
Public Sub Code_All_2_Units_Tests(Optional ByVal msg As String) _
' тестом Покрыто опосредованно
' создать юнит тесты для всего кода
' МетаПрограммирование = код, который пишет код.
MsgBoxEx _
Var_Public_Clear( _
to_ClipBoard( _
Array_walk( _
Array_Comments_delete( _
Split_by(vbCrLf, _
Тестом_Покрыт_Очистить( _
in_Quotes_remove( _
Underscore_replace( _
as_Replace( _
Paste_from_clipboard( _
Settings))))))))))
End Sub
Public Function Array_walk(a1 As Variant) ' As Variant
' тестом Покрыто опосредованно
' формирует строку Module_Test_code_Global, которая
' пойдёт в буфер обмена
Dim x As Long
For x = LBound(a1) To UBound(a1)
'all func "Proc_" also write to var Module_Test_code
If Like_Proc_Declare(a1(x)) Then
vbCrLF_2 Module_Test_code_Global, _
Code_Local_2_Global( _
Костыль_As_Lic( _
Replace_AsBrackets_2_BracketsAs( _
Var_Insert( _
Variables_Search( _
RubberDuck_Sign( _
Proc_Bottom( _
Code_Comments_Delete( _
Proc_Call( _
Proc_Call_Bracket_Make( _
String_Proc_Call( _
String_Args( _
Code_Add_Var_Declare( _
Array_As( _
Arg_is_One( _
Comma_wo_As_to_Variant( _
Args_String( _
Code_String_first( _
Brackets_Round_2_Curly( _
Proc_Top( _
Proc_Declare( _
Proc_Return_Type_Get( _
Module_Test_code_Trim( _
Proc_Name(a1(x)))))))))))))))))))))))))
End If
Next
End Function
Public Function Костыль_As_Lic(Optional ByVal msg As String)
' тестом Покрыто опосредованно
' Не хватило сил разобраться с:
' если процедура без аргументов, то в тесте появляется строка:
' Dim varReturn () As lic Function
' Заменяю часть строки
Module_Test_code = Replace(Module_Test_code, _
" () As lic ", " As Variant ' ")
' {} As Variant
Module_Test_code = Replace(Module_Test_code, _
"{} As Variant", " ' ")
End Function
Public Function vbCrLF_2(msg As String, Optional ByVal msg2 As String)
' тестом Покрыто опосредованно
' сначал делаю одинарными
' затем двойными
Module_Test_code_Global = Symb_1_2( _
Symb_2_1(msg, vbCrLf), vbCrLf)
End Function
Public Function Symb_1_2(msg As String, ByVal symb As String) _
As String
' тестом Покрыто опосредованно
' удвоить символ
Dim symb2 As String
symb2 = symb & symb
Symb_1_2 = Replace(msg, symb, symb2)
End Function
Public Function Symb_2_1(msg As String, symb) _
As String
' тестом Покрыто опосредованно
' устраняет подряд идущие символы
Dim symb2 As String
symb2 = symb & symb
Do While InStr(msg, symb2) > 0
msg = Replace(msg, symb2, symb)
Loop
Symb_2_1 = msg
End Function
Public Function Replace_AsBrackets_2_BracketsAs(Optional ByVal msg As String)
' тестом Покрыто опосредованно
' костыль
Module_Test_code = Replace(Module_Test_code, " As () ", " () As ")
End Function
Public Function Var_Insert(ByVal msg As String)
' тестом Покрыто опосредованно
'
Dim assign As String
If IsObjectName(Proc_Return_Type) Then
assign = "Set varReturn = "
Else
assign = "varReturn = "
End If
If Trim$(Proc_Return_Type) = vbNullString Then
Module_Test_code = Replace(Module_Test_code, "TestExit:", _
msg & vbCrLf & _
Bracket_Remove(Proc_Call_Bracket) & _
vbCrLf & _
"TestExit:")
Else ' Function
If Proc_Return_Type = vbNullString Then
Module_Test_code = Replace(Module_Test_code, "TestExit:", _
msg & vbCrLf & _
Bracket_Remove(Proc_Call_Bracket) & _
vbCrLf & _
"'if varReturn <> 0 Then Err.Raise 567, " & Chr(34) & Proc_Call_Bracket & Chr(34) & vbCrLf & _
"TestExit:")
Else
Module_Test_code = Replace(Module_Test_code, "TestExit:", _
msg & vbCrLf & _
"Dim varReturn As" & " " & Proc_Return_Type & vbCrLf & _
assign & _
Proc_Call_Bracket & _
vbCrLf & _
"'if varReturn <> 0 Then Err.Raise 567, " & Chr(34) & Proc_Call_Bracket & Chr(34) & vbCrLf & _
"TestExit:")
End If
End If
End Function
Public Function Variables_Search(Optional ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' создать строки, которые генерируют значения в переменные
If InStr(Module_Test_code, vbCrLf) < 1 Then
Exit Function
End If
Dim code_Var_Gen As String
Dim a1 As Variant
a1 = Split(Module_Test_code, vbCrLf)
Dim x As Long: For x = LBound(a1) To UBound(a1)
If InStr(UCase(a1(x)), " AS ") > 0 Then
code_Var_Gen = code_Var_Gen & Variable_Generate(a1(x)) & vbCrLf
End If
Next
Variables_Search = code_Var_Gen
End Function
Public Function Variable_Generate(ByVal str_w_As As String) _
As String
' тестом Покрыто опосредованно
'
Dim var_Name As String
var_Name = extract_Between(str_w_As, "Dim ", " As ")
If InStr(var_Name, "()") > 1 Then
var_Name = Replace(var_Name, "()", vbNullString)
If InStr(var_Name, "a1") > 0 Then
Variable_Generate = var_Name & " = " & "Mock.Generator_a1"
ElseIf InStr(var_Name, "a2") > 0 Then
Variable_Generate = var_Name & " = " & "Mock.Generator_a2"
Else
Variable_Generate = var_Name & " = " & "Mock.Generator_ArrayX"
End If
Else
' не массив
Variable_Generate = nonArray_VarGen(str_w_As)
End If
End Function
Public Function nonArray_VarGen(Optional ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' из строки объявления переменной не массива
' "Dim var_2 As String"
' создать строку инициализации переменной генератором
' var_2 = Mock.Generator_String
' для объектных переменных нужно добавить Set
Dim var_Name As String
var_Name = extract_Between(msg, "Dim ", " As ")
Dim data_Type As String
data_Type = Right_After(msg, " As ")
If IsObjectName(data_Type) Then
var_Name = "Set " & var_Name
Else
End If
nonArray_VarGen = var_Name & " = Mock.Generator_" & data_Type
End Function
Public Function IsObjectName(ByVal msg As String) _
As Boolean
' тестом Покрыто опосредованно
msg = Trim$(LCase(msg))
Dim a1() As Variant ' список объектов
a1 = Array("range", "shape", "worksheet", "workbook", "массив_дин")
Dim x As Long: For x = LBound(a1) To UBound(a1)
If InStr(msg, a1(x)) > 0 Then
IsObjectName = True
Exit For
End If
Next
End Function
Public Function Right_After(ByVal str_Long As String, ByVal str_short As String) _
As String
' тестом Покрыто опосредованно
' искать справа на лево
' вернуть справа от найденной подстроки
' из "12_56_56789" и "56" вернуть "789"
Dim pos_short As Long
pos_short = InStrRev(str_Long, str_short)
If pos_short < 1 Then Exit Function '=>
Dim short_Symb_Last_Pos As Long
short_Symb_Last_Pos = pos_short + Len(str_short) - 1
Right_After = Right$(str_Long, Len(str_Long) - short_Symb_Last_Pos)
End Function
Public Function Var_Public_Clear(Optional ByVal msg As String)
' тестом Покрыто опосредованно
' VBA забывает обнулять глобальные переменные
Module_Test_code = vbNullString
Module_Test_code_Global = vbNullString
End Function
Public Function to_ClipBoard(Optional ByVal msg As String)
' Тестом покрыта
Text_2_Clipboard Module_Test_code_Global
End Function
Public Function RubberDuck_Sign(Optional ByVal msg As String)
' Тестом покрыта
Module_Test_code = "'@TestMethod" & _
Module_Test_code
End Function
Public Function Code_Local_2_Global(Optional ByVal msg As String) ' Тестом покрыта
' наращиваю строку с юниттестами
Module_Test_code_Global = Module_Test_code_Global _
& vbCrLf & Module_Test_code
Module_Test_code = vbNullString
End Function
Public Function Proc_Bottom(Optional ByVal msg As String)
' Тестом покрыта
' процедура пришивает низ
Dim str As String
str = "TestExit:" & vbCrLf & _
"Mock.wb.Close False" & vbCrLf & _
"Exit Sub" & vbCrLf & _
"TestFail:" & vbCrLf & _
"Mock.wb.Close False" & vbCrLf & _
"Assert.Fail ""Test error: #"" & Err.Number & "" - "" & Err.Description" & vbCrLf & _
"End Sub" & vbCrLf
Module_Test_code = Module_Test_code & vbCrLf & str
End Function
Public Function Code_Comments_Delete(Optional ByVal msg As String)
' Тестом покрыта
' очистить комментарии
Module_Test_code = Comments_delete(Module_Test_code)
End Function
Public Function Proc_Call(str As String)
' Тестом покрыта
' Module_Test_code = Module_Test_code & vbCrLf & _
str
'хочу избавиться от вызова процедуры с неинициализированными параметрами
Module_Test_code = Module_Test_code & vbCrLf & _
"'" & str 'эту строку должна удалить процедура очистки комментов
End Function
Public Function Bracket_Remove(ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' убрать одиночные скобки
' "из Settings_01(var_0a1(),var_1a2(),var_2)" сделать
' "Settings_01 var_0a1(),var_1a2(),var_2"
msg = Replace(msg, "()", "BrackBrack")
msg = Replace(msg, "(", " ")
msg = Replace(msg, ")", " ")
msg = Replace(msg, "BrackBrack", "()")
Bracket_Remove = msg
End Function
Public Function Proc_Call_Bracket_Make(ByVal msg As String) _
As String
' тестом Покрыто опосредованно
'
Proc_Call_Bracket = Replace(msg, " ", "(") & _
")"
Proc_Call_Bracket_Make = msg
End Function
Public Function String_Proc_Call(str As String) _
As Variant ' Тестом покрыта
'получает из String_Args
' ToDo: удалить процедуру
String_Proc_Call = Proc_Name(Module_Test_code) & _
" " & str
End Function
Public Function String_Args(Optional ByVal msg As String) _
As String ' Тестом покрыта
' создать подстроку аргументов для вызова процедуры
If InStr(Module_Test_code, vbCrLf) < 1 Then
Exit Function
End If
Dim a1 As Variant
a1 = Split(Module_Test_code, vbCrLf)
Dim x As Long, sArgs As String
' пропускаю первую строку ибот там " As "
For x = LBound(a1) + 1 To UBound(a1)
If InStr(a1(x), " As ") > 0 Then
sArgs = sArgs & Var_Name_from_Declare(a1(x)) & ","
End If
Next
String_Args = Symb_Right_Cut(sArgs, ",") 'Comma_Right_Delete
End Function
Public Function Var_Name_from_Declare(str As Variant) _
As String ' Тестом покрыта
' вернуть имя переменной из объявления переменной
Dim sTemp As String
sTemp = extract_Between( _
str, "Dim ", " As ")
If sTemp = Empty Then
Var_Name_from_Declare = str
Else
Var_Name_from_Declare = sTemp
End If
End Function
Public Function Code_Add_Var_Declare(a1 As Variant)
' Тестом покрыта
' add variable declaration lines to call the
' function being tested
' ищет в массиве ячейку " As ", берёт
' из следующей ячейки тип переменной и
' дописывает строку с объявлением переменной
Dim x As Long, var_Count As Long
Dim arg As String 'текущая переменная
For x = LBound(a1) To UBound(a1)
If a1(x) = "As" Then
If InStr(a1(x - 1), ARRAY_SIGN) > 0 Then
Dim aX As String
' запомнить в имение переменной размерность массива
' для подстановки подходящего генератора
arg = a1(x - 1)
arg = Replace(arg, "_", vbNullString)
If Left$(arg, 2) = "a1" Then aX = "a1"
If Left$(arg, 2) = "a2" Then aX = "a2"
' InExSu 12.05.2019 00:34
' Module_Test_code = Module_Test_code & _
' vbCrLf & _
' "Dim var_" & var_Count & aX & "()" & " As " & _
' Replace(a1(x + 1), ",", vbNullString)
' пусть переменные называются как в оригинале
Module_Test_code = Module_Test_code & _
vbCrLf & _
"Dim " & Replace(a1(x - 1), "{}", "()") & " As " & _
Replace(a1(x + 1), ",", vbNullString)
Else
' InExSu 12.05.2019 00:34
' Module_Test_code = Module_Test_code & _
' vbCrLf & _
' "Dim var_" & var_Count & " As " & _
' Replace(a1(x + 1), ",", vbNullString)
' пусть переменные называются как в оригинале
Module_Test_code = Module_Test_code & _
vbCrLf & _
"Dim " & a1(x - 1) & " As " & _
Replace(a1(x + 1), ",", vbNullString)
End If
var_Count = var_Count + 1
End If
Next
End Function
Public Function Array_As(ByVal str As String) _
As Variant ' Тестом покрыта
If InStr(str, " ") > 0 Then
Array_As = Split(str)
Else
Dim a1(0 To 0) ' Split Returns a zero-based
Array_As = a1
End If
End Function
Public Function Arg_is_One(ByVal str As String) _
As String ' Тестом покрыта
' если между скобок один аргумент, то сделать его Variant
Arg_is_One = str
If Len(str) > 0 And _
InStr(str, ",") = 0 And _
InStr(UCase(str), " AS ") = 0 Then _
Arg_is_One = str & " As Variant"
End Function
Public Function Comma_wo_As_to_Variant(ByVal str As String) _
As String ' Тестом покрыта
' если между скобками есть запятые, но нет As, принудительно объявить необъявленные переменные как Variant
' if there are commas between brackets, but no As, force declare undeclared variables as Variant
' Dim sTemp As String
' sTemp = str
'
' If InStr(str, ",") > 0 And _
' InStr(str, " As ") = 0 Then
'
' sTemp = Replace(str, ",", " As Variant,")
' sTemp = sTemp & " As Variant"
'
' ElseIf InStr(str, ",") = 0 And _
' InStr(str, " As ") > 0 Then
' ' не въехал
' End If
'
' Comma_wo_As_to_Variant = sTemp
If InStr(str, ",") > 0 Then
'InExSu ToDo 12.05.2019:
'Comma_wo_As_to_Variant = Join( _
Arg_Type_Array(str))
Comma_wo_As_to_Variant = Join( _
Arg_Type_Array(str), ",")
Else
If InStr(UCase(str), " AS ") < 1 Then
Comma_wo_As_to_Variant = str & " As Variant"
Else
Comma_wo_As_to_Variant = str
End If
End If
End Function
Public Function Arg_Type_Array(ByVal msg As String) _
As Variant
' тестом Покрыто опосредованно
'
Dim a1 As Variant
a1 = Split(msg, ",")
Dim x As Long: For x = LBound(a1) To UBound(a1)
a1(x) = Arg_Type_String(a1(x))
Next
Arg_Type_Array = a1
End Function
Public Function Arg_Type_String(ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' если в строке нет As приваивает As Variant
If InStr(UCase(msg), " AS ") < 1 Then
Arg_Type_String = msg & " As Variant"
Else
Arg_Type_String = msg
End If
End Function
Public Function Args_String(ByVal str As String) _
As Variant ' Тестом покрыта
' procedure argument string, in braces
' get a string from Code_String_first
Args_String = extract_Between(str, "(", ")")
End Function
Public Function Code_String_first(Optional ByVal msg As String) _
As String ' Тестом покрыта
' The first line contains a declaration of procedure.
If Left$(Module_Test_code, 1) <> "'" Then _
Err.Raise 567, "Code_String_first", "Left$(Module_Test_code, 1) <> " '"
Dim a1 As Variant
a1 = Split(Module_Test_code, vbCrLf)
Code_String_first = a1(LBound(a1))
End Function
Public Function Brackets_Round_2_Curly(Optional ByVal msg As String) _
As Variant
' тестом Покрыто опосредованно
' скобки круглые заменить на фигурные
Module_Test_code = Replace(Module_Test_code, "() ", ARRAY_SIGN & " ")
End Function
Public Function Proc_Top(Optional ByVal msg As String) _
As Variant ' Тестом покрыта
Module_Test_code = Module_Test_code & vbCrLf & _
"On Error GoTo TestFail" & vbCrLf & _
"bDebug = True" & vbCrLf & _
"Settings" & vbCrLf
End Function
Public Function Proc_Declare(ByVal str As String) _
As String ' Тестом покрыта
' delaring test-unit
Dim sTemp As String
sTemp = Replace("Public Sub Proc_Name_TestMethod()", _
"Proc_Name", str)
Module_Test_code = Module_Test_code & sTemp
End Function
Public Function Proc_Name(ByVal str As String) _
As String ' Тестом покрыта
Module_Test_code = "'" & Trim$(str) & vbCrLf
' The first line will be a commented line from the source code.
' из неё и беру имя
' return from the string the name of the procedure
If InStr(1, str, "Function ", vbTextCompare) > 0 Then
Proc_Name = extract_Between(str, "Function ", "(")
Else: If InStr(1, str, "Sub ", vbTextCompare) > 0 _
Then Proc_Name = extract_Between(str, "Sub ", "(")
End If
End Function
Public Function Like_Proc_Declare(ByVal msg As String) _
As Boolean ' Тестом покрыта
If Trim$(UCase$(msg)) Like UCase$("*Function *(*") _
Or _
Trim$(UCase$(msg)) Like UCase$("*Sub *(*") Then _
Like_Proc_Declare = True
End Function
Public Function Array_Comments_delete(a1 As Variant) _
As Variant ' Тестом покрыта
Dim x As Long
For x = LBound(a1) To UBound(a1)
a1(x) = Comments_delete(a1(x))
Next
Array_Comments_delete = a1
End Function
Public Function Comments_delete(ByVal str As String) _
As Variant ' Тестом покрыта
If Сколько_раз(vbCrLf, str) = 0 Then
Comments_delete = Part_Left(str, _
Apostrophe_Position(str))
Else
' заменить разбиение строк подчеркиваниями
' загнать в массив по сплит через vbCrLf
' в массиве удалить комментарии
' собрать через джойн
Comments_delete = Array_2_String( _
Array_Comments_delete( _
String_2_Array( _
Underscore_replace(str), vbCrLf)), _
vbCrLf)
End If
End Function
Public Function Right_After_Left(ByVal str_Long As String, _
ByVal str_short As String) _
As String
' тестом Покрыто опосредованно
' искать слева на право
' из строки "12_12_34" и "12 "вернуь "_12_34"
Dim pos_short As Long
pos_short = InStr(str_Long, str_short)
If pos_short < 1 Then Exit Function '=>
Dim short_Symb_Last_Pos As Long
short_Symb_Last_Pos = pos_short + Len(str_short) - 1
Right_After_Left = Right$(str_Long, Len(str_Long) - short_Symb_Last_Pos)
End Function
Public Function Array_2_String(a1 As Variant, ByVal symb As String) _
As Variant ' Тестом покрыта
Array_2_String = Join(a1, symb)
End Function
Public Function String_2_Array(ByVal str As String, ByVal symb As String) _
As Variant ' Тестом покрыта
String_2_Array = Split(str, symb)
End Function
Public Function Part_Left(ByVal str As String, _
ByVal place As Long) _
As String ' Тестом покрыта
If place > 0 Then
Part_Left = Left$(str, place - 1)
Else
Part_Left = str
End If
End Function
Public Function Apostrophe_Position(ByVal str As String) _
As Long ' Тестом покрыта
Apostrophe_Position = InStr(str, "'")
End Function
Public Function Split_by(ByVal symb As String, _
ByVal str As String) _
As Variant ' Тестом покрыта
Split_by = Split(str, symb)
End Function
'Public Function Split_by_vbrclf(ByVal str As String) _
' As Variant ' Тестом покрыта
'
' Split_by_vbrclf = Split(str, vbCrLf)
'
'End Function
Public Function in_Quotes_remove(ByVal str As String) _
As String ' Тестом покрыта
'удалить - заключённые в кавычки
Dim x As Long
For x = 1 To Len(str) 'чтобы не сваливаться в бесконечный цикл
If Сколько_раз(Chr$(34), str) < 2 Then _
Exit For
str = Symb_Pair_Remove(str, Chr$(34))
Next
in_Quotes_remove = str
End Function
Public Function Symb_Pair_Remove(ByVal str As String, _
ByVal symb As String) _
As String ' Тестом покрыта
' найти два ближайших одинаовых символа и удалить их и между ними
Symb_Pair_Remove = Cut_BeTween( _
Position_02( _
Position_01(str, symb))) 'между Position_01 и Position_01 передаю String_Cut
End Function
Public Function Cut_BeTween(a1SC As String_Cut) _
As String ' Тестом покрыта
' вырезить из строки середину
With a1SC
Cut_BeTween = Side_Left(.str, .Position_01 - 1) & _
Side_Right(.str, Len(.str) - .Position_02)
End With
End Function
Public Function Side_Left(ByVal str As String, ByVal iPos As Long) _
As String ' Тестом покрыта
If iPos < 0 Then _
Exit Function
Side_Left = Left$(str, iPos)
End Function
Public Function Side_Right(ByVal str As String, ByVal iPos As Long) _
As String ' Тестом покрыта
If iPos < 0 Then _
Exit Function
Side_Right = Right$(str, iPos)
End Function
Public Function Cut_Edges(a1SC As String_Cut) _
As String ' Тестом покрыта
' не пригодилась :-)
' строка края обрезать
With a1SC
If .Position_01 > 0 And .Position_02 > 0 Then
Cut_Edges = Cut_Right( _
Cut_Left(.str, .Position_01), _
.Position_02)
Else
Cut_Edges = .str
End If
End With
End Function
Public Function Position_01(ByVal str As String, _
ByVal symb As String) _
As String_Cut ' Тестом покрыта
Dim a1SC As String_Cut
With a1SC
.str = str
.symb = symb
.Position_01 = InStr(str, symb)
End With
Position_01 = a1SC
End Function
Public Function Position_02(a1SC As String_Cut) _
As String_Cut ' Тестом покрыта
With a1SC
If .Position_01 > 0 Then _
.Position_02 = InStr(.Position_01 + 1, .str, .symb)
End With
Position_02 = a1SC
End Function
Public Function Cut_Left(ByVal str As String, ByVal iPos As Long) _
As String ' Тестом покрыта
'string cut from left
Cut_Left = Right$(str, Len(str) - iPos)
End Function
Public Function Cut_Right(ByVal str As String, ByVal iPos As Long) _
As String ' Тестом покрыта
' string cut from Right
' строку отрезать обрезать справа
Cut_Right = Left$(str, Len(str) - iPos)
End Function
Public Function Proc_Return_Type_Get(ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' запомнить тип возвращаемый функцией в паблик переменную
Dim str As String
str = extract_Between_Right(Module_Test_code, ") As ", "()")
If str = vbNullString Then 'возвращает не массив. Узнаю есть ли возврат вообще.
Proc_Return_Type = Trim$(" " & Right_After( _
wo_Brackets(Module_Test_code), ") As "))
Else
Proc_Return_Type = "()" & " " & str ' пробел чтобы сработало автозавершение кода
End If
Proc_Return_Type_Get = msg
End Function
Public Function wo_Brackets(ByVal msg As String) _
As String
' тестом Покрыто опосредованно
' скобки сплошные () удалить
wo_Brackets = Replace(Module_Test_code, "()", vbNullString)
End Function
Public Function extract_Between_Right(ByVal msg As String, _
ByVal str_Left As String, _
ByVal str_Right As String) _
As String
' тестом Покрыто опосредованно
' вытащить между str_Left и str_Right
Dim pos_Left As Long
pos_Left = InStrRev(msg, str_Left) + Len(str_Left)
Dim pos_Right As Long
pos_Right = InStrRev(msg, str_Right)
If pos_Left < 1 Then Exit Function
If pos_Right < 1 Then Exit Function
If pos_Left >= pos_Right Then Exit Function
extract_Between_Right = Mid(msg, pos_Left, pos_Right - pos_Left)
End Function
Public Function Module_Test_code_Trim(Optional ByVal msg As String) _
As String
' тестом Покрыто опосредованно
Module_Test_code = WorksheetFunction.Trim(Module_Test_code)
Module_Test_code_Trim = msg
End Function
Public Function Тестом_Покрыт_Очистить(ByVal msg As String) _
As String
' тестом Покрыто
msg = Replace(msg, vbCrLf, Chr(23))
msg = Строку_с_Краями_Заменить( _
msg, "Function ", "естом Покрыт", _
vbNullString, True, False)
msg = Строку_с_Краями_Заменить( _
msg, "Sub ", "естом Покрыт", _
vbNullString, True, False)