5 require 'rdoc/parser/c'
10 public :do_classes, :do_constants
13 class TestRdocParserC < Test::Unit::TestCase
16 @tempfile = Tempfile.new self.class.name
17 filename = @tempfile.path
19 @top_level = RDoc::TopLevel.new filename
21 @options = RDoc::Options.new Hash.new
22 @stats = RDoc::Stats.new
24 @progress = StringIO.new
31 def test_do_classes_boot_class
33 /* Document-class: Foo
34 * this is the Foo boot class
36 VALUE cFoo = boot_defclass("Foo", 0);
39 klass = util_get_class content, 'cFoo'
40 assert_equal " this is the Foo boot class\n ", klass.comment
43 def test_do_classes_class
45 /* Document-class: Foo
46 * this is the Foo class
48 VALUE cFoo = rb_define_class("Foo", rb_cObject);
51 klass = util_get_class content, 'cFoo'
52 assert_equal " this is the Foo class\n ", klass.comment
55 def test_do_classes_class_under
57 /* Document-class: Kernel::Foo
58 * this is the Foo class under Kernel
60 VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
63 klass = util_get_class content, 'cFoo'
64 assert_equal " this is the Foo class under Kernel\n ", klass.comment
67 def test_do_classes_module
69 /* Document-module: Foo
70 * this is the Foo module
72 VALUE mFoo = rb_define_module("Foo");
75 klass = util_get_class content, 'mFoo'
76 assert_equal " this is the Foo module\n ", klass.comment
79 def test_do_classes_module_under
81 /* Document-module: Kernel::Foo
82 * this is the Foo module under Kernel
84 VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
87 klass = util_get_class content, 'mFoo'
88 assert_equal " this is the Foo module under Kernel\n ", klass.comment
96 VALUE cFoo = rb_define_class("Foo", rb_cObject);
98 /* 300: The highest possible score in bowling */
99 rb_define_const(cFoo, "PERFECT", INT2FIX(300));
101 /* Huzzah!: What you cheer when you roll a perfect game */
102 rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
104 /* TEST\:TEST: Checking to see if escaped semicolon works */
105 rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
107 /* \\: The file separator on MS Windows */
108 rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
110 /* /: The file separator on Unix */
111 rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
113 /* C:\\Program Files\\Stuff: A directory on MS Windows */
114 rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
116 /* Default definition */
117 rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
119 rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
122 * Multiline comment goes here because this comment spans multiple lines.
123 * Multiline comment goes here because this comment spans multiple lines.
125 rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
128 * 1: Multiline comment goes here because this comment spans multiple lines.
129 * Multiline comment goes here because this comment spans multiple lines.
131 rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
133 /* Multiline comment goes here because this comment spans multiple lines.
134 * Multiline comment goes here because this comment spans multiple lines.
136 rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
141 parser = util_parser content
146 klass = parser.classes['cFoo']
149 constants = klass.constants
150 assert !klass.constants.empty?
152 constants = constants.map { |c| [c.name, c.value, c.comment] }
154 assert_equal ['PERFECT', '300',
155 "\n The highest possible score in bowling \n "],
157 assert_equal ['CHEER', 'Huzzah!',
158 "\n What you cheer when you roll a perfect game \n "],
160 assert_equal ['TEST', 'TEST:TEST',
161 "\n Checking to see if escaped semicolon works \n "],
163 assert_equal ['MSEPARATOR', '\\',
164 "\n The file separator on MS Windows \n "],
166 assert_equal ['SEPARATOR', '/',
167 "\n The file separator on Unix \n "],
169 assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
170 "\n A directory on MS Windows \n "],
172 assert_equal ['NOSEMI', 'INT2FIX(99)',
173 "\n Default definition \n "],
175 assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
178 comment = <<-EOF.chomp
181 Multiline comment goes here because this comment spans multiple lines.
182 Multiline comment goes here because this comment spans multiple lines.
186 assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
187 assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
189 comment = <<-EOF.chomp
191 Multiline comment goes here because this comment spans multiple lines.
192 Multiline comment goes here because this comment spans multiple lines.
196 assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
198 assert constants.empty?, constants.inspect
201 def test_find_class_comment_init
204 * a comment for class Foo
208 VALUE foo = rb_define_class("Foo", rb_cObject);
212 klass = util_get_class content, 'foo'
214 assert_equal " \n a comment for class Foo\n \n", klass.comment
217 def test_find_class_comment_define_class
220 * a comment for class Foo
222 VALUE foo = rb_define_class("Foo", rb_cObject);
225 klass = util_get_class content, 'foo'
227 assert_equal " \n a comment for class Foo\n ", klass.comment
230 def test_find_class_comment_define_class_Init_Foo
233 * a comment for class Foo on Init
238 * a comment for class Foo on rb_define_class
240 VALUE foo = rb_define_class("Foo", rb_cObject);
244 klass = util_get_class content, 'foo'
246 assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
249 def util_get_class(content, name)
250 parser = util_parser content
255 def util_parser(content)
256 parser = RDoc::Parser::C.new @top_level, @fn, content, @options, @stats
257 parser.progress = @progress