4 require 'rdoc/parsers/parse_c'
9 public :do_classes, :do_constants
12 class TestRdocC_Parser < Test::Unit::TestCase
15 @tempfile = Tempfile.new self.class.name
16 filename = @tempfile.path
18 @top_level = RDoc::TopLevel.new filename
20 @options = RDoc::Options.new Hash.new
21 @stats = RDoc::Stats.new
23 @progress = StringIO.new
30 def test_do_classes_boot_class
32 /* Document-class: Foo
33 * this is the Foo boot class
35 VALUE cFoo = boot_defclass("Foo", 0);
38 klass = util_get_class content, 'cFoo'
39 assert_equal " this is the Foo boot class\n ", klass.comment
42 def test_do_classes_class
44 /* Document-class: Foo
45 * this is the Foo class
47 VALUE cFoo = rb_define_class("Foo", rb_cObject);
50 klass = util_get_class content, 'cFoo'
51 assert_equal " this is the Foo class\n ", klass.comment
54 def test_do_classes_class_under
56 /* Document-class: Kernel::Foo
57 * this is the Foo class under Kernel
59 VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
62 klass = util_get_class content, 'cFoo'
63 assert_equal " this is the Foo class under Kernel\n ", klass.comment
66 def test_do_classes_module
68 /* Document-module: Foo
69 * this is the Foo module
71 VALUE mFoo = rb_define_module("Foo");
74 klass = util_get_class content, 'mFoo'
75 assert_equal " this is the Foo module\n ", klass.comment
78 def test_do_classes_module_under
80 /* Document-module: Kernel::Foo
81 * this is the Foo module under Kernel
83 VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
86 klass = util_get_class content, 'mFoo'
87 assert_equal " this is the Foo module under Kernel\n ", klass.comment
95 VALUE cFoo = rb_define_class("Foo", rb_cObject);
97 /* 300: The highest possible score in bowling */
98 rb_define_const(cFoo, "PERFECT", INT2FIX(300));
100 /* Huzzah!: What you cheer when you roll a perfect game */
101 rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
103 /* TEST\:TEST: Checking to see if escaped semicolon works */
104 rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
106 /* \\: The file separator on MS Windows */
107 rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
109 /* /: The file separator on Unix */
110 rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
112 /* C:\\Program Files\\Stuff: A directory on MS Windows */
113 rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
115 /* Default definition */
116 rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
118 rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
121 * Multiline comment goes here because this comment spans multiple lines.
122 * Multiline comment goes here because this comment spans multiple lines.
124 rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
127 * 1: Multiline comment goes here because this comment spans multiple lines.
128 * Multiline comment goes here because this comment spans multiple lines.
130 rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
132 /* Multiline comment goes here because this comment spans multiple lines.
133 * Multiline comment goes here because this comment spans multiple lines.
135 rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
140 parser = util_parser content
145 klass = parser.classes['cFoo']
148 constants = klass.constants
149 assert !klass.constants.empty?
151 constants = constants.map { |c| [c.name, c.value, c.comment] }
153 assert_equal ['PERFECT', '300',
154 "\n The highest possible score in bowling \n "],
156 assert_equal ['CHEER', 'Huzzah!',
157 "\n What you cheer when you roll a perfect game \n "],
159 assert_equal ['TEST', 'TEST:TEST',
160 "\n Checking to see if escaped semicolon works \n "],
162 assert_equal ['MSEPARATOR', '\\',
163 "\n The file separator on MS Windows \n "],
165 assert_equal ['SEPARATOR', '/',
166 "\n The file separator on Unix \n "],
168 assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
169 "\n A directory on MS Windows \n "],
171 assert_equal ['NOSEMI', 'INT2FIX(99)',
172 "\n Default definition \n "],
174 assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
177 comment = <<-EOF.chomp
180 Multiline comment goes here because this comment spans multiple lines.
181 Multiline comment goes here because this comment spans multiple lines.
185 assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
186 assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
188 comment = <<-EOF.chomp
190 Multiline comment goes here because this comment spans multiple lines.
191 Multiline comment goes here because this comment spans multiple lines.
195 assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
197 assert constants.empty?, constants.inspect
200 def test_find_class_comment_init
203 * a comment for class Foo
207 VALUE foo = rb_define_class("Foo", rb_cObject);
211 klass = util_get_class content, 'foo'
213 assert_equal " \n a comment for class Foo\n \n", klass.comment
216 def test_find_class_comment_define_class
219 * a comment for class Foo
221 VALUE foo = rb_define_class("Foo", rb_cObject);
224 klass = util_get_class content, 'foo'
226 assert_equal " \n a comment for class Foo\n ", klass.comment
229 def test_find_class_comment_define_class_Init_Foo
232 * a comment for class Foo on Init
237 * a comment for class Foo on rb_define_class
239 VALUE foo = rb_define_class("Foo", rb_cObject);
243 klass = util_get_class content, 'foo'
245 assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
248 def util_get_class(content, name)
249 parser = util_parser content
254 def util_parser(content)
255 parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
256 parser.progress = @progress