@@ -581,6 +581,41 @@ def test_find_body_2
581581
582582 def test_find_body_define
583583 content = <<-EOF
584+ #define something something_else
585+
586+ #define other_function rb_other_function
587+
588+ /*
589+ * a comment for rb_other_function
590+ */
591+ VALUE
592+ rb_other_function() {
593+ }
594+
595+ void
596+ Init_Foo(void) {
597+ VALUE foo = rb_define_class("Foo", rb_cObject);
598+
599+ rb_define_method(foo, "my_method", other_function, 0);
600+ }
601+ EOF
602+
603+ klass = util_get_class content , 'foo'
604+ other_function = klass . method_list . first
605+
606+ assert_equal 'my_method' , other_function . name
607+ assert_equal 'a comment for rb_other_function' , other_function . comment
608+ assert_equal '()' , other_function . params
609+ assert_equal 118 , other_function . offset
610+ assert_equal 8 , other_function . line
611+
612+ code = other_function . token_stream . first . text
613+
614+ assert_equal "VALUE\n rb_other_function() {\n }" , code
615+ end
616+
617+ def test_find_body_define_comment
618+ content = <<-EOF
584619/*
585620 * a comment for other_function
586621 */
@@ -603,9 +638,10 @@ def test_find_body_define
603638 other_function = klass . method_list . first
604639
605640 assert_equal 'my_method' , other_function . name
606- assert_equal "a comment for other_function" ,
607- other_function . comment
641+ assert_equal 'a comment for other_function' , other_function . comment
608642 assert_equal '()' , other_function . params
643+ assert_equal 39 , other_function . offset
644+ assert_equal 4 , other_function . line
609645
610646 code = other_function . token_stream . first . text
611647
@@ -749,18 +785,36 @@ def test_find_modifiers_yields
749785 assert_equal expected , comment
750786 end
751787
752- def test_handle_method
788+ def test_handle_method_args_minus_1
753789 parser = util_parser "Document-method: Object#m\n blah */"
754790
755- parser . handle_method 'method' , 'rb_cObject' , 'm' , 'rb_m' , 2
791+ parser . content = <<-BODY
792+ VALUE
793+ rb_other(VALUE obj) {
794+ rb_funcall(obj, rb_intern("other"), 0);
795+ return rb_str_new2("blah, blah, blah");
796+ }
797+
798+ VALUE
799+ rb_m(int argc, VALUE *argv, VALUE obj) {
800+ VALUE o1, o2;
801+ rb_scan_args(argc, argv, "1", &o1, &o2);
802+ }
803+ BODY
804+
805+ parser . handle_method 'method' , 'rb_cObject' , 'm' , 'rb_m' , -1
756806
757807 m = @top_level . find_module_named ( 'Object' ) . method_list . first
758808
759809 assert_equal 'm' , m . name
760- assert_equal '(p1, p2)' , m . params
761810 assert_equal @top_level , m . file
811+ assert_equal 115 , m . offset
812+ assert_equal 7 , m . line
813+
814+ assert_equal '(p1)' , m . params
762815 end
763816
817+
764818 def test_handle_method_args_0
765819 parser = util_parser "Document-method: BasicObject#==\n blah */"
766820
@@ -803,23 +857,7 @@ def test_handle_method_args_2
803857 assert_equal '(p1, p2)' , equals2 . params
804858 end
805859
806- def test_handle_method_args_minus_1
807- parser = util_parser "Document-method: Object#m\n blah */"
808-
809- parser . content = <<-BODY
810- VALUE
811- rb_m(int argc, VALUE *argv, VALUE obj) {
812- VALUE o1, o2;
813- rb_scan_args(argc, argv, "1", &o1, &o2);
814- }
815- BODY
816-
817- parser . handle_method 'method' , 'rb_cObject' , 'm' , 'rb_m' , -1
818-
819- m = @top_level . find_module_named ( 'Object' ) . method_list . first
820-
821- assert_equal '(p1)' , m . params
822- end
860+ # test_handle_args_minus_1 handled by test_handle_method
823861
824862 def test_handle_method_args_minus_2
825863 parser = util_parser "Document-method: BasicObject#==\n blah */"
0 commit comments