summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_parser_c.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rdoc/test_rdoc_parser_c.rb')
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb124
1 files changed, 120 insertions, 4 deletions
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index 8fe1bf46ec..99f2159203 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -534,10 +534,6 @@ void Init_curses(){
def test_do_constants_file
content = <<-EOF
void Init_File(void) {
- rb_cFile = rb_define_class("File", rb_cIO);
- rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
- rb_include_module(rb_cIO, rb_mFConst);
-
/* Document-const: LOCK_SH
*
* Shared lock
@@ -1000,6 +996,36 @@ init_gi_repository (void)
assert_equal 2, klass.method_list.length
end
+ def test_find_body_cast
+ content = <<-EOF
+/*
+ * a comment for other_function
+ */
+VALUE
+other_function() {
+}
+
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+
+ rb_define_method(foo, "my_method", (METHOD)other_function, 0);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+ other_function = klass.method_list.first
+
+ assert_equal 'my_method', other_function.name
+ assert_equal "a comment for other_function",
+ other_function.comment.text
+ assert_equal '()', other_function.params
+
+ code = other_function.token_stream.first.text
+
+ assert_equal "VALUE\nother_function() {\n}", code
+ end
+
def test_find_body_define
content = <<-EOF
#define something something_else
@@ -1669,6 +1695,96 @@ void Init(void) {
assert_equal expected, @store.c_singleton_class_variables
end
+ def test_scan_method_copy
+ parser = util_parser <<-C
+/*
+ * call-seq:
+ * pathname.to_s -> string
+ * pathname.to_path -> string
+ *
+ * Return the path as a String.
+ *
+ * to_path is implemented so Pathname objects are usable with File.open, etc.
+ */
+static VALUE
+path_to_s(VALUE self) { }
+
+/*
+ * call-seq:
+ * str[index] -> new_str or nil
+ * str[start, length] -> new_str or nil
+ * str.slice(index) -> new_str or nil
+ * str.slice(start, length) -> new_str or nil
+ */
+static VALUE
+path_aref_m(int argc, VALUE *argv, VALUE str) { }
+
+/*
+ * call-seq:
+ * string <=> other_string -> -1, 0, +1 or nil
+ */
+static VALUE
+path_cmp_m(VALUE str1, VALUE str2) { }
+
+/*
+ * call-seq:
+ * str == obj -> true or false
+ * str === obj -> true or false
+ */
+VALUE
+rb_str_equal(VALUE str1, VALUE str2) { }
+
+Init_pathname()
+{
+ rb_cPathname = rb_define_class("Pathname", rb_cObject);
+
+ rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
+ rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
+ rb_define_method(rb_cPathname, "[]", path_aref_m, -1);
+ rb_define_method(rb_cPathname, "slice", path_aref_m, -1);
+ rb_define_method(rb_cPathname, "<=>", path_cmp_m, 1);
+ rb_define_method(rb_cPathname, "==", rb_str_equal), 2);
+ rb_define_method(rb_cPathname, "===", rb_str_equal), 2);
+}
+ C
+
+ parser.scan
+
+ pathname = @store.classes_hash['Pathname']
+
+ to_path = pathname.method_list.find { |m| m.name == 'to_path' }
+ assert_equal "pathname.to_path -> string", to_path.call_seq
+
+ to_s = pathname.method_list.find { |m| m.name == 'to_s' }
+ assert_equal "pathname.to_s -> string", to_s.call_seq
+
+ index_expected = <<-EXPECTED.chomp
+str[index] -> new_str or nil
+str[start, length] -> new_str or nil
+ EXPECTED
+
+ index = pathname.method_list.find { |m| m.name == '[]' }
+ assert_equal index_expected, index.call_seq, '[]'
+
+ slice_expected = <<-EXPECTED.chomp
+str.slice(index) -> new_str or nil
+str.slice(start, length) -> new_str or nil
+ EXPECTED
+
+ slice = pathname.method_list.find { |m| m.name == 'slice' }
+ assert_equal slice_expected, slice.call_seq
+
+ spaceship = pathname.method_list.find { |m| m.name == '<=>' }
+ assert_equal "string <=> other_string -> -1, 0, +1 or nil",
+ spaceship.call_seq
+
+ equals2 = pathname.method_list.find { |m| m.name == '==' }
+ assert_match 'str == obj', equals2.call_seq
+
+ equals3 = pathname.method_list.find { |m| m.name == '===' }
+ assert_match 'str === obj', equals3.call_seq
+ end
+
def test_scan_order_dependent
parser = util_parser <<-C
void a(void) {