forked from xDrivenDevelopment/xUnitFor1C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxUnitAddTestsDesc.js
194 lines (161 loc) · 7.13 KB
/
xUnitAddTestsDesc.js
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
$engine JScript
$uname xUnitAddTestsDesc
$dname Äîáàâèòü îïèñàíèÿ òåñòîâûõ ñëó÷àå xUnitFor1C
$addin global
$addin stdlib
$addin stdcommands
stdlib.require('TextWindow.js', SelfScript);
stdlib.require('log4js.js', SelfScript);
global.connectGlobals(SelfScript);
var logger = addLogger(SelfScript.uniqueName, Log4js.Level.DEBUG); //var logger = addLogger(SelfScript.uniqueName, Log4js.Level.ERROR);
var TEST_CASE_DESC_FUNC_NAME = 'Ïîëó÷èòüÑïèñîêÒåñòîâ'
var TEST_CASE_DESC_FUNC_TEMPLATE =
"Ïåðåì þÒåñò;\n\n\
Ôóíêöèÿ Ïîëó÷èòüÑïèñîêÒåñòîâ(ÞíèòÒåñòèðîâàíèå) Ýêñïîðò\n\
\n\
þÒåñò = ÞíèòÒåñòèðîâàíèå;\n\
\n\
ÂñåÒåñòû = Íîâûé Ìàññèâ;\n\
\n\
Âîçâðàò ÂñåÒåñòû;\n\
\n\
ÊîíåöÔóíêöèè\n"
function addLogger(loggerName, logLevel) {
var logger = Log4js.getLogger(loggerName);
var appender = new Log4js.BrowserConsoleAppender();
appender.setLayout(new Log4js.PatternLayout(Log4js.PatternLayout.TTCC_CONVERSION_PATTERN));
// ñëåäóþùèé êîä íóæåí, ÷òîáû ïðè ïåðåçàïóñêå ñêðèïòà áåç ïåðåçàïóñêà Êîíôèãóðàòîðà ëîã íå çàäâîèòñÿ
appenders = [];
appenders.push(appender);
logger.onlog = new Log4js.CustomEvent();
logger.onclear = new Log4js.CustomEvent();
logger.setAppenders(appenders); // êîíåö áëîêà èñêëþ÷åíèÿ çàäâîåíèÿ ëîãà
//logger.addAppender(new Log4js.FileAppender("f:\\somefile.log"));
logger.setLevel(logLevel);
return logger;
}
SelfScript.self['macrosÂñòàâèòü îïðåäåëåíèÿ òåñòîâûõ ñëó÷àåâ xUnitFor1C'] = function() {
var tw = GetTextWindow();
if (!tw || tw.IsReadOnly()) {
logger.debug('Íå íàøëè òåêñòîâîå îêíî èëè îêíî äëÿ ÷òåíèÿ')
return true;
}
var parser = snegopat.parseSources(tw.text())
logger.debug('parser.reStream ' + parser.reStream)
var indexTestCaseDescFunc = parser.idxOfName(TEST_CASE_DESC_FUNC_NAME)
logger.debug('parser.idxOfName("'+TEST_CASE_DESC_FUNC_NAME+'")=' + indexTestCaseDescFunc)
var procNames = getTestCases(parser)
if(!procNames){
logger.debug('Íå íàøëè îïðåäåëåíèÿ òåñòîâûõ ñëó÷àåâ')
return true
}
if (-1 == indexTestCaseDescFunc) {
logger.debug('Íå íàøëè ôóíêöèþ îïèñàíèÿ òåñòîâ "'+TEST_CASE_DESC_FUNC_NAME+'"')
logger.debug('Âñòàâëÿþ øàáëîí ôóíêöèè îïèñàíèÿ òåñòîâ "'+TEST_CASE_DESC_FUNC_NAME+'"')
tw.InsertLine(1, TEST_CASE_DESC_FUNC_TEMPLATE);
parser = snegopat.parseSources(tw.text())
logger.debug('parser.reStream ' + parser.reStream)
indexTestCaseDescFunc = parser.idxOfName(TEST_CASE_DESC_FUNC_NAME)
logger.debug('parser.idxOfName("'+TEST_CASE_DESC_FUNC_NAME+'")=' + indexTestCaseDescFunc)
}
var data = getLineForInsertTestCaseDescriptions(parser, indexTestCaseDescFunc);
var line = data.EndLine;
if(line != -1){
var arrayName = data.ArrayName
deleteExistTestCaseDesc(tw, data.BeginLine, line, procNames, arrayName)
parser = snegopat.parseSources(tw.text()) // ò.ê. èçìåíèëè òåêñò, çàíîâî ïàðñèì
logger.debug('parser.reStream ' + parser.reStream)
data = getLineForInsertTestCaseDescriptions(parser, indexTestCaseDescFunc);
line = data.EndLine;
if(line != -1){
insertTestCaseDescIntoText(tw, line, procNames, arrayName);
}
}
else
logger.debug('Íå óäàëîñü ïîëó÷èòü ïîçèöèþ äëÿ âñòàâêè îïèñàíèÿ òåñòîâûõ ñëó÷àåâ')
return true;
}
function deleteExistTestCaseDesc(tw, beginLine, endLine, procNames, arrayName) {
var range = tw.Range(beginLine, 1, endLine)
var text = range.GetText()
logger.debug('Òåêñò ôóíêöèè '+TEST_CASE_DESC_FUNC_NAME + '\n'+text)
for(i=0; i < procNames.length; i++) {
var reTestCaseDesc = new RegExp( '^\\s*'+arrayName+'\\.Äîáàâèòü\\(\\s*"'+procNames[i]+'"\\s*\\)\\s*;\\s*$', "igm");
logger.debug('Ðåãóëÿðíîå âûðàæåíèå øàáëîíà çàìåíû '+reTestCaseDesc.source)
text = text.replace(reTestCaseDesc,"");
}
logger.debug('Íîâûé òåêñò ôóíêöèè '+TEST_CASE_DESC_FUNC_NAME + '\n'+text)
range.SetText(text)
}
function insertTestCaseDescIntoText(tw, line, procNames, arrayName){
logger.debug('arrayName <' + arrayName+'>')
array = new Array(procNames.length);
for(i=0; i < procNames.length; i++) {
str = '\t'+arrayName+'.Äîáàâèòü("'+procNames[i]+'");';
array[i] = str;
logger.debug('Âñòàâëÿþ ñòðîêó - ' + str)
}
array[procNames.length] = "";
tw.InsertLine(line, StringUtils.fromLines(array));
}
function getLineForInsertTestCaseDescriptions(parser, indexTestCaseDescFunc){
var resEndLine = -1;
var resArrayName = ''
var resBeginLine = -1
var ret = { BeginLine: -1, EndLine: -1, ArrayName: '' };
strForStream = addStringToTheLeft(indexTestCaseDescFunc, "0", 6-(""+indexTestCaseDescFunc).length)
// èùó Ôóíêöèÿ Ïîëó÷èòüÑïèñîêÒåñòîâ(þÒåñòèðîâàíèå) Ýêñïîðò ... ÂñåÒåñòû = Íîâûé Ìàññèâ; ... Âîçâðàò ÂñåÒåñòû; ...
var reTestCaseDescriptionsFuncBody = new RegExp('FuNm('+strForStream+')LpNm(\\d{6})RpEx.*?(Nm(\\d{6})EqNwNm(\\d{6})).*?ReNm(\\d{6})', "g");
lexemsArray = reTestCaseDescriptionsFuncBody.exec(parser.reStream)
var findRightBody = lexemsArray && lexemsArray.length >= 6
if(findRightBody)
{
logger.debug(TEST_CASE_DESC_FUNC_NAME + ' (êîíåö) lexemsArray.index ' + lexemsArray.index + ' lexemsArray.lastIndex ' + lexemsArray.lastIndex )
var testCaseArrayName = parser.name(lexemsArray[4]) //ÂñåÒåñòû èç ñòðîêè "ÂñåÒåñòû = Íîâûé Ìàññèâ"
var arrayKeywordName = parser.name(lexemsArray[5]) // Ìàññèâ èç ýòîé æå ñòðîêè
var returnValueName = parser.name(lexemsArray[6]) // Âîçâðàò ÂñåÒåñòû
logger.debug('Íàèìåíîâàíèå ìàññèâà èìåí òåñòîâûõ ñëó÷àåâ "' + testCaseArrayName+'"')
findRightBody = /ìàññèâ/i.test(arrayKeywordName) && testCaseArrayName.toLowerCase() == returnValueName.toLowerCase()
if (findRightBody) {
var lex = parser.lexem(parser.posToLexem(lexemsArray.index))
logger.debug('Ïîëó÷èëè äàííûå ïî íà÷àëó ôóíêöèè "'+TEST_CASE_DESC_FUNC_NAME+';" , ñòðîêà ' + lex.line)
resBeginLine = lex.line
var lex = parser.lexem(parser.posToLexem(lexemsArray.lastIndex))
logger.debug('Ïîëó÷èëè äàííûå ïî ñòðîêå "Âîçâðàò '+testCaseArrayName+';" , ñòðîêà ' + lex.line)
ret = { BeginLine: resBeginLine, EndLine: lex.line, ArrayName: testCaseArrayName }
}
else {
logger.error('Äîëæíà áûòü ñòðîêà "Ìàññèâ". À ïîëó÷èëè "' + arrayKeywordName+'"')
logger.error('Äîëæíà áûòü ñòðîêà "'+testCaseArrayName+'". À ïîëó÷èëè "' + returnValueName+'"')
}
}
else {
logger.error('Íå íàøëè ôóíêöèþ '+TEST_CASE_DESC_FUNC_NAME+' ñ íåîáõîäèìîé ñòðóêòóðîé');
if(lexemsArray)
logger.error('Êîëè÷åñòâî ýëåìåíòîâ â ìàññèâå ðàçáîðà ëåêñåì (lexemsArray.length) äîëæíî áûòü áîëüøå èëè ðàâíî 6, à ïîëó÷èëè "' + lexemsArray.length+'"')
}
return ret;
}
function getTestCases(parser){
var res = new Array();
var reStream = parser.reStream
var rePublicProcedureWithoutParams = /(Pc)Nm\d{6}LpRpEx/g
var reTestCaseName = /^òåñò/i
while(rePublicProcedureWithoutParams.exec(reStream))
{
var lex = parser.lexem(parser.posToLexem(RegExp.index + 2))
logger.debug('ïðîâåðÿþ ïðîöåäóðó ' + lex.text + ", ñòðîêà " + lex.line)
if (reTestCaseName.exec(lex.text)){
logger.debug('\tíàøëè òåñòîâûé ñëó÷àé ' + lex.text + ", ñòðîêà " + lex.line)
res.push( lex.text )
}
}
logger.debug('procNames.length ' + res.length)
return res.length ? res : null;
}
function addStringToTheLeft(src, str, count) {
res = src;
for(i=0; i < count; i++)
res = str + res;
return res;
}