@@ -1699,6 +1699,80 @@ def test_scan
16991699 assert_equal expected , @store . c_singleton_class_variables
17001700 end
17011701
1702+ def test_scan_method_copy
1703+ parser = util_parser <<-C
1704+ /*
1705+ * call-seq:
1706+ * pathname.to_s -> string
1707+ * pathname.to_path -> string
1708+ *
1709+ * Return the path as a String.
1710+ *
1711+ * to_path is implemented so Pathname objects are usable with File.open, etc.
1712+ */
1713+ static VALUE
1714+ path_to_s(VALUE self) { }
1715+
1716+ /*
1717+ * call-seq:
1718+ * str[index] -> new_str or nil
1719+ * str[start, length] -> new_str or nil
1720+ * str.slice(index) -> new_str or nil
1721+ * str.slice(start, length) -> new_str or nil
1722+ */
1723+ static VALUE
1724+ path_aref_m(int argc, VALUE *argv, VALUE str) { }
1725+
1726+ /*
1727+ * call-seq:
1728+ * string <=> other_string -> -1, 0, +1 or nil
1729+ */
1730+ static VALUE
1731+ path_cmp_m(VALUE str1, VALUE str2) { }
1732+
1733+ Init_pathname()
1734+ {
1735+ rb_cPathname = rb_define_class("Pathname", rb_cObject);
1736+
1737+ rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
1738+ rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
1739+ rb_define_method(rb_cPathname, "[]", path_aref_m, -1);
1740+ rb_define_method(rb_cPathname, "slice", path_aref_m, -1);
1741+ rb_define_method(rb_cPathname, "<=>", path_cmp_m, 1);
1742+ }
1743+ C
1744+
1745+ parser . scan
1746+
1747+ pathname = @store . classes_hash [ 'Pathname' ]
1748+
1749+ to_path = pathname . method_list . find { |m | m . name == 'to_path' }
1750+ assert_equal "pathname.to_path -> string" , to_path . call_seq
1751+
1752+ to_s = pathname . method_list . find { |m | m . name == 'to_s' }
1753+ assert_equal "pathname.to_s -> string" , to_s . call_seq
1754+
1755+ index_expected = <<-EXPECTED . chomp
1756+ str[index] -> new_str or nil
1757+ str[start, length] -> new_str or nil
1758+ EXPECTED
1759+
1760+ index = pathname . method_list . find { |m | m . name == '[]' }
1761+ assert_equal index_expected , index . call_seq , '[]'
1762+
1763+ slice_expected = <<-EXPECTED . chomp
1764+ str.slice(index) -> new_str or nil
1765+ str.slice(start, length) -> new_str or nil
1766+ EXPECTED
1767+
1768+ slice = pathname . method_list . find { |m | m . name == 'slice' }
1769+ assert_equal slice_expected , slice . call_seq
1770+
1771+ spaceship = pathname . method_list . find { |m | m . name == '<=>' }
1772+ assert_equal "string <=> other_string -> -1, 0, +1 or nil" ,
1773+ spaceship . call_seq
1774+ end
1775+
17021776 def test_scan_order_dependent
17031777 parser = util_parser <<-C
17041778void a(void) {
0 commit comments