* ext/psych/emitter.c (line_width, set_line_width): preferred line may

be set on the emitter.
* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
* test/psych/test_emitter.rb: corresponding tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2010-07-08 16:02:26 +00:00
Родитель 74d40e4196
Коммит ba9a959a18
4 изменённых файлов: 42 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Jul 9 00:49:46 2010 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/emitter.c (line_width, set_line_width): preferred line may
be set on the emitter.
* test/psych/test_emitter.rb: corresponding tests.
Thu Jul 8 15:47:34 2010 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_str_conv_enc_opts): fix infinite loop because

Просмотреть файл

@ -460,6 +460,32 @@ static VALUE indentation(VALUE self)
return INT2NUM(emitter->best_indent);
}
/* call-seq: emitter.line_width
*
* Get the preferred line width.
*/
static VALUE line_width(VALUE self)
{
yaml_emitter_t * emitter;
Data_Get_Struct(self, yaml_emitter_t, emitter);
return INT2NUM(emitter->best_width);
}
/* call-seq: emitter.line_width = width
*
* Set the preferred line with to +width+.
*/
static VALUE set_line_width(VALUE self, VALUE width)
{
yaml_emitter_t * emitter;
Data_Get_Struct(self, yaml_emitter_t, emitter);
yaml_emitter_set_width(emitter, NUM2INT(width));
return width;
}
void Init_psych_emitter()
{
VALUE psych = rb_define_module("Psych");
@ -483,6 +509,8 @@ void Init_psych_emitter()
rb_define_method(cPsychEmitter, "canonical=", set_canonical, 1);
rb_define_method(cPsychEmitter, "indentation", indentation, 0);
rb_define_method(cPsychEmitter, "indentation=", set_indentation, 1);
rb_define_method(cPsychEmitter, "line_width", line_width, 0);
rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1);
id_write = rb_intern("write");
}

Просмотреть файл

@ -54,7 +54,7 @@ module Psych
version = @options[:version].split('.').map { |x| x.to_i }
else
version = [1,1]
end if @options[:version]
end if @options.key? :version
@emitter.start_document version, [], false
accept object

Просмотреть файл

@ -10,6 +10,12 @@ module Psych
@emitter = Psych::Emitter.new @out
end
def test_line_width
assert_equal 0, @emitter.line_width
assert_equal 10, @emitter.line_width = 10
assert_equal 10, @emitter.line_width
end
def test_set_canonical
@emitter.canonical = true
assert_equal true, @emitter.canonical