Repository navigation
in-place editing: treat each file as a separate input - #569
Conversation
| Ok(()) | ||
| } | ||
|
|
||
| // -i implies -s: each file is edited as a separate stream. |
There was a problem hiding this comment.
almost the same setup code 11 times
could you please add a small helper that creates the two files? :)
or do a loop ?
There was a problem hiding this comment.
i think you can still do a loop
like
"input", "arg", "expected"
| std::fs::write(&path1, "a1\na2\na3\n")?; | ||
| std::fs::write(&path2, "b1\nb2\nb3\n")?; | ||
|
|
||
| // Lines collected in the hold space stay in their own file. |
There was a problem hiding this comment.
are you sure about this one?
as far as i know, GNU does not reset the hold space between files, even with -s/-i
so i would expect a3,b1,b2,b3 in the second file
| std::fs::write(&path1, "one\n")?; | ||
| std::fs::write(&path2, "two\n")?; | ||
|
|
||
| // Neither file has a line 2, so Q never runs. |
There was a problem hiding this comment.
this doesn't test much if Q never runs
could you please test that q in the first file leaves the second file untouched?
1b21caf to
a5a0c58
Compare
|
Thanks for the review. I addressed all three points and folded the changes Test setup. I added a Hold space. GNU clears the hold space between files under both No additional hold-space change is needed. Quit. You were right that the old test proved very little. I replaced it I also added the requested There are now 12 tests in this area. Reverting the two source changes makes |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #569 +/- ##
=======================================
Coverage 82.84% 82.84%
=======================================
Files 13 13
Lines 6865 6865
Branches 401 402 +1
=======================================
Hits 5687 5687
Misses 1175 1175
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sed -i with more than one file treated them as one continuous stream: line numbers continued across files, $ matched only the last line of the last file, and N could join lines from different files. GNU sed documents -i as implying -s, so enable separate-file processing for --in-place as well as --separate. There was a second bug when automatic output was suppressed. At the end of a file, process_file cleared a pending N action only when !context.quiet. With -n, the action carried into the next file and joined with its first line. Clear the action in either mode, but write the pattern space only when automatic output is enabled. The same bug can be reproduced without -i. With f1 containing a1, a2, a3 and f2 containing b1, b2, b3: sed -n -s -e 'N;s/\n/+/;p' f1 f2 Before this change it prints a1+a2, a3+b1, b2+b3. GNU prints a1+a2, b1+b2. Add coverage for line numbers, $, ranges, N across file boundaries, hold space, Q, backup suffixes, and -n.
a5a0c58 to
25c9a2d
Compare
|
Done - the ten two-file cases are now a single table, with the arguments, the two Two cases stayed separate: the backup test, which also checks the two This brings the test additions down from 260 lines to 134. Reverting the two |
Fixes #567.
GNU documents
-ias implying-s, so--in-placenow enables thesame per-file handling as
--separate.The second hunk fixes the same problem under
-n. Without it,can still carry the last line of
f1intof2, because a pendingNis cleared at the end of a file only when automatic output is enabled.
The bug is not specific to
-i. Withf1containinga1,a2,a3and
f2containingb1,b2,b3,currently prints
a1+a2,a3+b1,b2+b3. GNU printsa1+a2,b1+b2.While testing this, I found five other existing differences from GNU
sed that this change does not address:
Nadds a newline to a final line that has none, related to Extra newline character to last line. #258Nreads the line matching its start, Ranges: a numeric first address that has already been passed never latches #541nstarts a new cycle instead of continuing with the next command,nstarts a new cycle instead of continuing with the next command #568cprints its text for a range still open at the end of input-zrecord splitting, Adjust record separator when --zero-terminated is specified #530Expected output in the new tests matches GNU sed 4.9 and 4.10.