Bug #2957
closedIO.print emits field separator after each object, rather than between
Description
=begin
In versions prior to 1.9, IO.print emits the field separator "$," between each object printed when non-nil.
As of r11003, IO.print emits the field separator after each field. This change was reported by
Alex DeCaria in [ruby-talk:358633].
The following patch
(a) reverts the behavior to what it was in 1.8.X
(b) Documents the behavior of the field separator
(c) Adds a test case
Index: io.c¶
--- io.c (revision 26905)
+++ io.c (working copy)
@@ -5879,7 +5879,9 @@
-
ios.print(obj, ...) => nil
- Writes the given object(s) to ios. The stream must be
-
- opened for writing. If the output record separator (
$\
)
- opened for writing. If the output record separator (
-
- opened for writing. If the output field separator (
$,
)
- opened for writing. If the output field separator (
-
- is not
nil
, it will be inserted between each object.
- is not
-
- If the output record separator (
$\
) - is not
nil
, it will be appended to the output. If no - arguments are given, prints
$_
. Objects that aren't - strings will be converted by calling their
to_s
method.
@@ -5906,10 +5908,10 @@
argv = &line;
}
for (i=0; i<argc; i++) {
- If the output record separator (
- rb_io_write(out, argv[i]);
- if (!NIL_P(rb_output_fs)) {
-
if (!NIL_P(rb_output_fs) && i>0) {
rb_io_write(out, rb_output_fs);
} -
rb_io_write(out, argv[i]);
}
if (argc > 0 && !NIL_P(rb_output_rs)) {
rb_io_write(out, rb_output_rs);
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb (revision 26905)
+++ test/ruby/test_io.rb (working copy)
@@ -1386,6 +1386,23 @@
assert_in_out_err(["-", t.path], "print while $<.gets", %w(foo bar baz), [])
end -
def test_print_separators
-
$, = ':'
-
$\ = "\n"
-
r, w = IO.pipe
-
w.print('a')
-
w.print('a','b','c')
-
w.close
-
assert_equal("a\n", r.gets)
-
assert_equal("a:b:c\n", r.gets)
-
assert_nil r.gets
-
r.close
-
ensure
-
$, = nil
-
$\ = nil
-
end
-
def test_putc
pipe(proc do |w|
w.putc "A"
=end
Updated by dkelley (Daniel Kelley) over 14 years ago
=begin
Ok, somebody beat me to the code, great! Documentation and test case is still relevant.
=end
Updated by matz (Yukihiro Matsumoto) over 14 years ago
=begin
Hi,
In message "Re: [ruby-core:28644] [Bug #2957] IO.print emits field separator after each object, rather than between"
on Sun, 14 Mar 2010 00:30:25 +0900, Daniel Kelley redmine@ruby-lang.org writes:
|Ok, somebody beat me to the code, great! Documentation and test case is still relevant.
Your documentation patch and test case were merged. Thank you.
matz.
=end
Updated by matz (Yukihiro Matsumoto) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
This issue was solved with changeset r26938.
Daniel, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
=end