Skip to content

Commit 903f89e

Browse files
committed
comment
1 parent 281178a commit 903f89e

File tree

2 files changed

+91
-17
lines changed

2 files changed

+91
-17
lines changed

bin/rbt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def readfile(filename, fdw):
194194
fdw(line)
195195

196196

197-
def find_next(line, tags, use_re=False):
197+
def find_next(line, begin_tag, end_tag):
198198
index_min = len(line)
199199
found = None
200-
for tag in tags:
200+
for tag in {begin_tag, end_tag}:
201201
index = line.find(tag)
202202
if index != -1 and index < index_min:
203203
index_min = index
@@ -218,13 +218,12 @@ def apply_on_file(config, fileinfo):
218218
(fno, temporary_file) = tempfile.mkstemp()
219219
fd_out = open(fno, 'wt')
220220
move = True
221-
tags = {config.begin_tag, config.end_tag}
222221
with fd_out:
223222
for line in fd_in:
224223
begin_of_line = True
225224
rest, le = chomp(line)
226225
while rest:
227-
(next_tag, next_index) = find_next(rest, tags)
226+
(next_tag, next_index) = find_next(rest, config.begin_tag, config.end_tag)
228227
# if (config.comment or config.uncomment) and next_index != 0:
229228
# text_inside.write(LINE_ENDING)
230229
if depth > 0 and begin_of_line and (config.comment or config.uncomment):
@@ -252,7 +251,7 @@ def apply_on_file(config, fileinfo):
252251
if config.begin_tag != config.end_tag and next_tag == config.begin_tag:
253252
depth = depth + 1
254253
if config.comment or config.uncomment:
255-
text_inside.write("xx"+rest[:next_index])
254+
text_inside.write(rest[:next_index])
256255
rest = rest[next_index + len(next_tag):]
257256
elif next_tag == config.end_tag:
258257
depth = depth - 1
@@ -344,16 +343,8 @@ class Config:
344343
self.style = a
345344
if o in ("-b", "--begin-tag"):
346345
self.begin_tag = a
347-
self.use_re = False
348-
if o in ("-B", "--begin-regexp-tag"):
349-
self.begin_tag = a
350-
self.use_re = True
351346
if o in ("-e", "--end-tag"):
352347
self.end_tag = a
353-
self.use_re = False
354-
if o in ("-E", "--end-regexp-tag"):
355-
self.end_tag = a
356-
self.use_re = True
357348
if o in ("-s", "--simulate"):
358349
self.simulate = True
359350
if o in ("-d", "--delete-tags"):

tests/rbt_tests.sh

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ EOF
143143
assert_exec_equals \
144144
"cd .. ; ./bin/rbt -b '*BEGIN*' -e '*END*' -r 'new text here' < /tmp/lorem_ipsum" \
145145
"${EXPECTED}" \
146-
"#6: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin)."
146+
"#6: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin)"
147147

148148

149149
################################################################################################################
@@ -169,7 +169,7 @@ EOF
169169
assert_exec_equals \
170170
"cd .. ; ./bin/rbt -b '*BEGIN*' -e '*END*' -r 'new text here' < /tmp/lorem_ipsum" \
171171
"${EXPECTED}" \
172-
"#7: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin and before end)."
172+
"#7: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin and before end)"
173173

174174

175175
################################################################################################################
@@ -193,7 +193,7 @@ EOF
193193
assert_exec_equals \
194194
"cd .. ; ./bin/rbt -b '*BEGIN*' -e '*END*' -r 'new text here' < /tmp/lorem_ipsum" \
195195
"${EXPECTED}" \
196-
"#8: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin)."
196+
"#8: Two blocks on non consecutive lines. The second block is on two lines (force LF after begin)"
197197

198198

199199
################################################################################################################
@@ -215,7 +215,7 @@ EOF
215215
assert_exec_equals \
216216
"cd .. ; ./bin/rbt -b '*BEGIN*' -e '*END*' -r 'new text here' < /tmp/lorem_ipsum" \
217217
"${EXPECTED}" \
218-
"#9: Two blocks with end of the first block/begin of the second block are on the same line."
218+
"#9: Two blocks with end of the first block/begin of the second block are on the same line"
219219

220220

221221
################################################################################################################
@@ -390,6 +390,89 @@ assert_exec_equals \
390390

391391
rm -f /tmp/lorem_ipsum
392392

393+
################################################################################################################
394+
395+
cat > /tmp/lorem_ipsum <<'EOF'
396+
texte sans rien
397+
--
398+
texte avec un ~tag~ en plein milieu
399+
--
400+
~tag~ au début
401+
--
402+
la fin se termine par ~tag~
403+
--
404+
~tag~
405+
--
406+
la fin se termine par ~tag~
407+
--
408+
la fin se termine par ~tag
409+
sur deux lignes~
410+
--
411+
la fin se termine par ~tag
412+
sur deux lignes~ avec texte après
413+
--
414+
~tag
415+
sur deux lignes~
416+
--
417+
~tag
418+
sur deux lignes~ avec texte après
419+
--
420+
deux ~tag1~ et ~tag2~
421+
--
422+
deux ~tag1~ et ~tag sur
423+
ligne suivante~
424+
--
425+
entre
426+
~
427+
texte à
428+
changer
429+
~
430+
EOF
431+
432+
read -r -d '' EXPECTED <<'EOF'
433+
texte sans rien
434+
--
435+
texte avec un /* tag */ en plein milieu
436+
--
437+
/* tag */ au début
438+
--
439+
la fin se termine par /* tag */
440+
--
441+
/* tag */
442+
--
443+
la fin se termine par /* tag */
444+
--
445+
la fin se termine par /* tag
446+
sur deux lignes */
447+
--
448+
la fin se termine par /* tag
449+
sur deux lignes */ avec texte après
450+
--
451+
/* tag
452+
sur deux lignes */
453+
--
454+
/* tag
455+
sur deux lignes */ avec texte après
456+
--
457+
deux /* tag1 */ et /* tag2 */
458+
--
459+
deux /* tag1 */ et /* tag sur
460+
ligne suivante */
461+
--
462+
entre
463+
464+
/* texte à
465+
changer */
466+
467+
EOF
468+
469+
assert_exec_equals \
470+
"cd .. ; ./bin/rbt -b '~' -e '~' --comment java-block -d < /tmp/lorem_ipsum" \
471+
"${EXPECTED}" \
472+
"#15: Several tests with comment /* */ (begin and end strings are equal), begin/end strings are deleted"
473+
474+
rm -f /tmp/lorem_ipsum
475+
393476
echo "${ok}/${total} (${ko} errors)"
394477

395478
#rm -f /tmp/lorem_ipsum

0 commit comments

Comments
 (0)