ruby-changes:14659
From: yugui <ko1@a...>
Date: Sat, 30 Jan 2010 22:22:14 +0900 (JST)
Subject: [ruby-changes:14659] Ruby:r26508 (ruby_1_9_1): merges r25499 from trunk into ruby_1_9_1.
yugui 2010-01-30 21:53:47 +0900 (Sat, 30 Jan 2010) New Revision: 26508 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26508 Log: merges r25499 from trunk into ruby_1_9_1. -- * parse.y (ripper_filename): add Ripper#filename. [ruby-dev:37856] * test/ripper/test_filter.rb: add more tests. Modified files: branches/ruby_1_9_1/parse.y branches/ruby_1_9_1/test/ripper/test_filter.rb branches/ruby_1_9_1/version.h Index: ruby_1_9_1/parse.y =================================================================== --- ruby_1_9_1/parse.y (revision 26507) +++ ruby_1_9_1/parse.y (revision 26508) @@ -10415,6 +10415,24 @@ /* * call-seq: + * ripper#filename -> String + * + * Return current parsing filename. + */ +static VALUE +ripper_filename(VALUE self) +{ + struct parser_params *parser; + + Data_Get_Struct(self, struct parser_params, parser); + if (!ripper_initialized_p(parser)) { + rb_raise(rb_eArgError, "method called for uninitialized object"); + } + return parser->parser_ruby_sourcefile_string; +} + +/* + * call-seq: * ripper#lineno -> Integer * * Return line number of current parsing line. @@ -10464,6 +10482,7 @@ rb_define_method(Ripper, "initialize", ripper_initialize, -1); rb_define_method(Ripper, "parse", ripper_parse, 0); rb_define_method(Ripper, "column", ripper_column, 0); + rb_define_method(Ripper, "filename", ripper_filename, 0); rb_define_method(Ripper, "lineno", ripper_lineno, 0); rb_define_method(Ripper, "end_seen?", rb_parser_end_seen_p, 0); rb_define_method(Ripper, "encoding", rb_parser_encoding, 0); Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 26507) +++ ruby_1_9_1/version.h (revision 26508) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 413 +#define RUBY_PATCHLEVEL 414 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_1/test/ripper/test_filter.rb =================================================================== --- ruby_1_9_1/test/ripper/test_filter.rb (revision 26507) +++ ruby_1_9_1/test/ripper/test_filter.rb (revision 26508) @@ -23,31 +23,60 @@ File.expand_path(__FILE__) end - def test_filter_filename + def test_filter_filename_unset data = {} - Filter.new(File.read(filename)).parse(data) + filter = Filter.new(File.read(filename)) + filter.parse(data) assert_equal('-', data[:filename], "[ruby-dev:37856]") + assert_equal('-', filter.filename) + end + def test_filter_filename data = {} - Filter.new(File.read(filename), filename).parse(data) + filter = Filter.new(File.read(filename), filename) + assert_equal(filename, filter.filename) + filter.parse(data) assert_equal(filename, data[:filename]) + assert_equal(filename, filter.filename) end def test_filter_lineno data = {} - Filter.new(File.read(filename)).parse(data) + src = File.read(filename) + src_lines = src.count("\n") + filter = Filter.new(src) + assert_equal(nil, filter.lineno) + filter.parse(data) assert_equal(1, data[:lineno]) + assert_equal(src_lines, filter.lineno) end + def test_filter_lineno_set + data = {} + src = File.read(filename) + src_lines = src.count("\n") + filter = Filter.new(src, '-', 100) + assert_equal(nil, filter.lineno) + filter.parse(data) + assert_equal(100, data[:lineno]) + assert_equal(src_lines+100-1, filter.lineno) + end + def test_filter_column data = {} - Filter.new(File.read(filename)).parse(data) + src = File.read(filename) + last_columns = src[/(.*)\Z/].size + filter = Filter.new(src) + assert_equal(nil, filter.column) + filter.parse(data) assert_equal(0, data[:column]) + assert_equal(last_columns, filter.column) end def test_filter_token data = {} - Filter.new(File.read(filename)).parse(data) + filter = Filter.new(File.read(filename)) + filter.parse(data) assert_equal("begin", data[:token]) end end if ripper_test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/