PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jruby-1.7.3/test/externals/ruby1.9/rdoc/test_rdoc_ri_driver.rb

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Ruby | 1061 lines | 820 code | 241 blank | 0 comment | 1 complexity | 4bb7c03c22a50c5d91ef35d8dcc20d14 MD5 | raw file
  1. require 'pp'
  2. require 'rubygems'
  3. require 'minitest/autorun'
  4. require 'tmpdir'
  5. require 'fileutils'
  6. require 'stringio'
  7. require 'rdoc/ri/driver'
  8. require 'rdoc/rdoc'
  9. class TestRDocRIDriver < MiniTest::Unit::TestCase
  10. def setup
  11. @RM = RDoc::Markup
  12. @tmpdir = File.join Dir.tmpdir, "test_rdoc_ri_driver_#{$$}"
  13. @home_ri = File.join @tmpdir, 'dot_ri'
  14. FileUtils.mkdir_p @tmpdir
  15. FileUtils.mkdir_p @home_ri
  16. @orig_ri = ENV['RI']
  17. @orig_home = ENV['HOME']
  18. ENV['HOME'] = @tmpdir
  19. ENV.delete 'RI'
  20. @options = RDoc::RI::Driver.process_args []
  21. @options[:home] = @tmpdir
  22. @options[:use_stdout] = true
  23. @options[:formatter] = @RM::ToRdoc
  24. @driver = RDoc::RI::Driver.new @options
  25. end
  26. def teardown
  27. ENV['HOME'] = @orig_home
  28. ENV['RI'] = @orig_ri
  29. FileUtils.rm_rf @tmpdir
  30. end
  31. DUMMY_PAGER = ":;\n"
  32. def with_dummy_pager
  33. pager_env, ENV['RI_PAGER'] = ENV['RI_PAGER'], DUMMY_PAGER
  34. yield
  35. ensure
  36. ENV['RI_PAGER'] = pager_env
  37. end
  38. def mu_pp(obj)
  39. s = ''
  40. s = PP.pp obj, s
  41. s = s.force_encoding(Encoding.default_external) if defined? Encoding
  42. s.chomp
  43. end
  44. def test_self_dump
  45. util_store
  46. out, = capture_io do
  47. RDoc::RI::Driver.dump @store.cache_path
  48. end
  49. assert_match %r%:class_methods%, out
  50. assert_match %r%:modules%, out
  51. assert_match %r%:instance_methods%, out
  52. assert_match %r%:ancestors%, out
  53. end
  54. def test_add_also_in_empty
  55. out = @RM::Document.new
  56. @driver.add_also_in out, []
  57. assert_empty out
  58. end
  59. def test_add_also_in
  60. util_multi_store
  61. @store1.type = :system
  62. @store2.type = :home
  63. out = @RM::Document.new
  64. @driver.add_also_in out, [@store1, @store2]
  65. expected = @RM::Document.new(
  66. @RM::Rule.new(1),
  67. @RM::Paragraph.new('Also found in:'),
  68. @RM::Verbatim.new("ruby core\n",
  69. "~/.ri\n"))
  70. assert_equal expected, out
  71. end
  72. def test_add_class
  73. util_multi_store
  74. out = @RM::Document.new
  75. @driver.add_class out, 'Bar', [@cBar]
  76. expected = @RM::Document.new(
  77. @RM::Heading.new(1, 'Bar < Foo'),
  78. @RM::BlankLine.new)
  79. assert_equal expected, out
  80. end
  81. def test_add_from
  82. util_store
  83. @store.type = :system
  84. out = @RM::Document.new
  85. @driver.add_from out, @store
  86. expected = @RM::Document.new @RM::Paragraph.new("(from ruby core)")
  87. assert_equal expected, out
  88. end
  89. def test_add_includes_empty
  90. out = @RM::Document.new
  91. @driver.add_includes out, []
  92. assert_empty out
  93. end
  94. def test_add_includes_many
  95. util_store
  96. out = @RM::Document.new
  97. enum = RDoc::Include.new 'Enumerable', nil
  98. @cFoo.add_include enum
  99. @driver.add_includes out, [[[@cFooInc, enum], @store]]
  100. expected = @RM::Document.new(
  101. @RM::Rule.new(1),
  102. @RM::Heading.new(1, "Includes:"),
  103. @RM::Paragraph.new("(from #{@store.friendly_path})"),
  104. @RM::BlankLine.new,
  105. @RM::Paragraph.new("Inc"),
  106. @RM::BlankLine.new,
  107. @RM::Paragraph.new("Include thingy"),
  108. @RM::BlankLine.new,
  109. @RM::Verbatim.new("Enumerable\n"))
  110. assert_equal expected, out
  111. end
  112. def test_add_includes_many_no_doc
  113. util_store
  114. out = @RM::Document.new
  115. enum = RDoc::Include.new 'Enumerable', nil
  116. @cFoo.add_include enum
  117. @cFooInc.instance_variable_set :@comment, ''
  118. @driver.add_includes out, [[[@cFooInc, enum], @store]]
  119. expected = @RM::Document.new(
  120. @RM::Rule.new(1),
  121. @RM::Heading.new(1, "Includes:"),
  122. @RM::Paragraph.new("(from #{@store.friendly_path})"),
  123. @RM::Verbatim.new("Inc\n",
  124. "Enumerable\n"))
  125. assert_equal expected, out
  126. end
  127. def test_add_includes_one
  128. util_store
  129. out = @RM::Document.new
  130. @driver.add_includes out, [[[@cFooInc], @store]]
  131. expected = @RM::Document.new(
  132. @RM::Rule.new(1),
  133. @RM::Heading.new(1, "Includes:"),
  134. @RM::Paragraph.new("Inc (from #{@store.friendly_path})"),
  135. @RM::BlankLine.new,
  136. @RM::Paragraph.new("Include thingy"),
  137. @RM::BlankLine.new)
  138. assert_equal expected, out
  139. end
  140. def test_add_method_list
  141. out = @RM::Document.new
  142. @driver.add_method_list out, %w[new parse], 'Class methods'
  143. expected = @RM::Document.new(
  144. @RM::Heading.new(1, 'Class methods:'),
  145. @RM::BlankLine.new,
  146. @RM::Verbatim.new('new'),
  147. @RM::Verbatim.new('parse'),
  148. @RM::BlankLine.new)
  149. assert_equal expected, out
  150. end
  151. def test_add_method_list_interative
  152. @options[:interactive] = true
  153. driver = RDoc::RI::Driver.new @options
  154. out = @RM::Document.new
  155. driver.add_method_list out, %w[new parse], 'Class methods'
  156. expected = @RM::Document.new(
  157. @RM::Heading.new(1, 'Class methods:'),
  158. @RM::BlankLine.new,
  159. @RM::IndentedParagraph.new(2, 'new, parse'),
  160. @RM::BlankLine.new)
  161. assert_equal expected, out
  162. end
  163. def test_add_method_list_none
  164. out = @RM::Document.new
  165. @driver.add_method_list out, [], 'Class'
  166. assert_equal @RM::Document.new, out
  167. end
  168. def test_ancestors_of
  169. util_ancestors_store
  170. assert_equal %w[X Mixin Object Foo], @driver.ancestors_of('Foo::Bar')
  171. end
  172. def test_classes
  173. util_multi_store
  174. expected = {
  175. 'Ambiguous' => [@store1, @store2],
  176. 'Bar' => [@store2],
  177. 'Foo' => [@store1],
  178. 'Foo::Bar' => [@store1],
  179. 'Foo::Baz' => [@store1, @store2],
  180. 'Inc' => [@store1],
  181. }
  182. assert_equal expected, @driver.classes
  183. end
  184. def test_class_document
  185. util_store
  186. tl1 = RDoc::TopLevel.new 'one.rb'
  187. tl2 = RDoc::TopLevel.new 'two.rb'
  188. @cFoo.add_comment 'one', tl1
  189. @cFoo.add_comment 'two', tl2
  190. @store.save_class @cFoo
  191. found = [
  192. [@store, @store.load_class(@cFoo.full_name)]
  193. ]
  194. out = @driver.class_document @cFoo.full_name, found, [], []
  195. expected = @RM::Document.new
  196. @driver.add_class expected, 'Foo', []
  197. @driver.add_includes expected, []
  198. @driver.add_from expected, @store
  199. expected << @RM::Rule.new(1)
  200. doc = @RM::Document.new(@RM::Paragraph.new('one'))
  201. doc.file = 'one.rb'
  202. expected.push doc
  203. expected << @RM::BlankLine.new
  204. doc = @RM::Document.new(@RM::Paragraph.new('two'))
  205. doc.file = 'two.rb'
  206. expected.push doc
  207. expected << @RM::Rule.new(1)
  208. expected << @RM::Heading.new(1, 'Instance methods:')
  209. expected << @RM::BlankLine.new
  210. expected << @RM::Verbatim.new('inherit')
  211. expected << @RM::Verbatim.new('override')
  212. expected << @RM::BlankLine.new
  213. assert_equal expected, out
  214. end
  215. def test_complete
  216. store = RDoc::RI::Store.new @home_ri
  217. store.cache[:ancestors] = {
  218. 'Foo' => %w[Object],
  219. 'Foo::Bar' => %w[Object],
  220. }
  221. store.cache[:class_methods] = {
  222. 'Foo' => %w[bar]
  223. }
  224. store.cache[:instance_methods] = {
  225. 'Foo' => %w[Bar]
  226. }
  227. store.cache[:modules] = %w[
  228. Foo
  229. Foo::Bar
  230. ]
  231. @driver.stores = [store]
  232. assert_equal %w[Foo ], @driver.complete('F')
  233. assert_equal %w[ Foo::Bar], @driver.complete('Foo::B')
  234. assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
  235. assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.'
  236. assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::'
  237. assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b'
  238. end
  239. def test_complete_ancestor
  240. util_ancestors_store
  241. assert_equal %w[Foo::Bar#i_method], @driver.complete('Foo::Bar#')
  242. assert_equal %w[Foo::Bar#i_method Foo::Bar::c_method Foo::Bar::new],
  243. @driver.complete('Foo::Bar.')
  244. end
  245. def test_complete_classes
  246. util_store
  247. assert_equal %w[ ], @driver.complete('[')
  248. assert_equal %w[ ], @driver.complete('[::')
  249. assert_equal %w[Foo ], @driver.complete('F')
  250. assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::')
  251. assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B')
  252. end
  253. def test_complete_multistore
  254. util_multi_store
  255. assert_equal %w[Bar], @driver.complete('B')
  256. assert_equal %w[Foo], @driver.complete('F')
  257. assert_equal %w[Foo::Bar Foo::Baz], @driver.complete('Foo::B')
  258. end
  259. def test_display
  260. doc = @RM::Document.new(
  261. @RM::Paragraph.new('hi'))
  262. out, = capture_io do
  263. @driver.display doc
  264. end
  265. assert_equal "hi\n", out
  266. end
  267. def test_display_class
  268. util_store
  269. out, = capture_io do
  270. @driver.display_class 'Foo::Bar'
  271. end
  272. assert_match %r%^= Foo::Bar%, out
  273. assert_match %r%^\(from%, out
  274. assert_match %r%^= Class methods:%, out
  275. assert_match %r%^ new%, out
  276. assert_match %r%^= Instance methods:%, out
  277. assert_match %r%^ blah%, out
  278. assert_match %r%^= Attributes:%, out
  279. assert_match %r%^ attr_accessor attr%, out
  280. assert_equal 1, out.scan(/-\n/).length
  281. end
  282. def test_display_class_ambiguous
  283. util_multi_store
  284. out, = capture_io do
  285. @driver.display_class 'Ambiguous'
  286. end
  287. assert_match %r%^= Ambiguous < Object$%, out
  288. end
  289. def test_display_class_multi_no_doc
  290. util_multi_store
  291. out, = capture_io do
  292. @driver.display_class 'Foo::Baz'
  293. end
  294. assert_match %r%^= Foo::Baz%, out
  295. assert_match %r%-\n%, out
  296. assert_match %r%Also found in:%, out
  297. assert_match %r%#{Regexp.escape @home_ri}%, out
  298. assert_match %r%#{Regexp.escape @home_ri2}%, out
  299. end
  300. def test_display_class_superclass
  301. util_multi_store
  302. out, = capture_io do
  303. @driver.display_class 'Bar'
  304. end
  305. assert_match %r%^= Bar < Foo%, out
  306. end
  307. def test_display_class_module
  308. util_store
  309. out, = capture_io do
  310. @driver.display_class 'Inc'
  311. end
  312. assert_match %r%^= Inc$%, out
  313. end
  314. def test_display_method
  315. util_store
  316. out, = capture_io do
  317. @driver.display_method 'Foo::Bar#blah'
  318. end
  319. assert_match %r%Foo::Bar#blah%, out
  320. assert_match %r%blah.5%, out
  321. assert_match %r%blah.6%, out
  322. end
  323. def test_display_method_attribute
  324. util_store
  325. out, = capture_io do
  326. @driver.display_method 'Foo::Bar#attr'
  327. end
  328. assert_match %r%Foo::Bar#attr%, out
  329. refute_match %r%Implementation from%, out
  330. end
  331. def test_display_method_inherited
  332. util_multi_store
  333. out, = capture_io do
  334. @driver.display_method 'Bar#inherit'
  335. end
  336. assert_match %r%^= Bar#inherit%, out
  337. assert_match %r%^=== Implementation from Foo%, out
  338. end
  339. def test_display_method_overriden
  340. util_multi_store
  341. out, = capture_io do
  342. @driver.display_method 'Bar#override'
  343. end
  344. refute_match %r%must not be displayed%, out
  345. end
  346. def test_display_name_not_found_class
  347. util_store
  348. out, = capture_io do
  349. assert_equal false, @driver.display_name('Foo::B')
  350. end
  351. expected = <<-EXPECTED
  352. Foo::B not found, maybe you meant:
  353. Foo::Bar
  354. Foo::Baz
  355. EXPECTED
  356. assert_equal expected, out
  357. end
  358. def test_display_name_not_found_method
  359. util_store
  360. out, = capture_io do
  361. assert_equal false, @driver.display_name('Foo::Bar#b')
  362. end
  363. expected = <<-EXPECTED
  364. Foo::Bar#b not found, maybe you meant:
  365. Foo::Bar#blah
  366. Foo::Bar#bother
  367. EXPECTED
  368. assert_equal expected, out
  369. end
  370. def test_display_method_params
  371. util_store
  372. out, = capture_io do
  373. @driver.display_method 'Foo::Bar#bother'
  374. end
  375. assert_match %r%things.*stuff%, out
  376. end
  377. def test_expand_class
  378. util_store
  379. assert_equal 'Foo', @driver.expand_class('F')
  380. assert_equal 'Foo::Bar', @driver.expand_class('F::Bar')
  381. assert_raises RDoc::RI::Driver::NotFoundError do
  382. @driver.expand_class 'F::B'
  383. end
  384. end
  385. def test_expand_name
  386. util_store
  387. assert_equal '.b', @driver.expand_name('b')
  388. assert_equal 'Foo', @driver.expand_name('F')
  389. assert_equal 'Foo::Bar#', @driver.expand_name('F::Bar#')
  390. e = assert_raises RDoc::RI::Driver::NotFoundError do
  391. @driver.expand_name 'Z'
  392. end
  393. assert_equal 'Z', e.name
  394. end
  395. def test_find_methods
  396. util_store
  397. items = []
  398. @driver.find_methods 'Foo::Bar.' do |store, klass, ancestor, types, method|
  399. items << [store, klass, ancestor, types, method]
  400. end
  401. expected = [
  402. [@store, 'Foo::Bar', 'Foo::Bar', :both, nil],
  403. ]
  404. assert_equal expected, items
  405. end
  406. def test_find_methods_method
  407. util_store
  408. items = []
  409. @driver.find_methods '.blah' do |store, klass, ancestor, types, method|
  410. items << [store, klass, ancestor, types, method]
  411. end
  412. expected = [
  413. [@store, 'Ambiguous', 'Ambiguous', :both, 'blah'],
  414. [@store, 'Foo', 'Foo', :both, 'blah'],
  415. [@store, 'Foo::Bar', 'Foo::Bar', :both, 'blah'],
  416. [@store, 'Foo::Baz', 'Foo::Baz', :both, 'blah'],
  417. [@store, 'Inc', 'Inc', :both, 'blah'],
  418. ]
  419. assert_equal expected, items
  420. end
  421. def test_filter_methods
  422. util_multi_store
  423. name = 'Bar#override'
  424. found = @driver.load_methods_matching name
  425. sorted = @driver.filter_methods found, name
  426. expected = [[@store2, [@override]]]
  427. assert_equal expected, sorted
  428. end
  429. def test_filter_methods_not_found
  430. util_multi_store
  431. name = 'Bar#inherit'
  432. found = @driver.load_methods_matching name
  433. sorted = @driver.filter_methods found, name
  434. assert_equal found, sorted
  435. end
  436. def test_formatter
  437. tty = Object.new
  438. def tty.tty?() true; end
  439. driver = RDoc::RI::Driver.new
  440. assert_instance_of @RM::ToAnsi, driver.formatter(tty)
  441. assert_instance_of @RM::ToBs, driver.formatter(StringIO.new)
  442. driver.instance_variable_set :@paging, true
  443. assert_instance_of @RM::ToBs, driver.formatter(StringIO.new)
  444. driver.instance_variable_set :@formatter_klass, @RM::ToHtml
  445. assert_instance_of @RM::ToHtml, driver.formatter(tty)
  446. end
  447. def test_in_path_eh
  448. path = ENV['PATH']
  449. refute @driver.in_path?('/nonexistent')
  450. ENV['PATH'] = File.expand_path '..', __FILE__
  451. assert @driver.in_path?(File.basename(__FILE__))
  452. ensure
  453. ENV['PATH'] = path
  454. end
  455. def test_method_type
  456. assert_equal :both, @driver.method_type(nil)
  457. assert_equal :both, @driver.method_type('.')
  458. assert_equal :instance, @driver.method_type('#')
  459. assert_equal :class, @driver.method_type('::')
  460. end
  461. def test_name_regexp
  462. assert_equal %r%^RDoc::AnyMethod#new$%,
  463. @driver.name_regexp('RDoc::AnyMethod#new')
  464. assert_equal %r%^RDoc::AnyMethod::new$%,
  465. @driver.name_regexp('RDoc::AnyMethod::new')
  466. assert_equal %r%^RDoc::AnyMethod(#|::)new$%,
  467. @driver.name_regexp('RDoc::AnyMethod.new')
  468. assert_equal %r%^Hash(#|::)\[\]$%,
  469. @driver.name_regexp('Hash.[]')
  470. assert_equal %r%^Hash::\[\]$%,
  471. @driver.name_regexp('Hash::[]')
  472. end
  473. def test_list_known_classes
  474. util_store
  475. out, = capture_io do
  476. @driver.list_known_classes
  477. end
  478. assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
  479. end
  480. def test_list_known_classes_name
  481. util_store
  482. out, = capture_io do
  483. @driver.list_known_classes %w[F I]
  484. end
  485. assert_equal "Foo\nFoo::Bar\nFoo::Baz\nInc\n", out
  486. end
  487. def test_list_methods_matching
  488. util_store
  489. assert_equal %w[
  490. Foo::Bar#attr
  491. Foo::Bar#blah
  492. Foo::Bar#bother
  493. Foo::Bar::new
  494. ],
  495. @driver.list_methods_matching('Foo::Bar.').sort
  496. end
  497. def test_list_methods_matching_inherit
  498. util_multi_store
  499. assert_equal %w[
  500. Bar#baz
  501. Bar#inherit
  502. Bar#override
  503. ],
  504. @driver.list_methods_matching('Bar.').sort
  505. end
  506. def test_list_methods_matching_regexp
  507. util_store
  508. index = RDoc::AnyMethod.new nil, '[]'
  509. index.record_location @top_level
  510. @cFoo.add_method index
  511. @store.save_method @cFoo, index
  512. c_index = RDoc::AnyMethod.new nil, '[]'
  513. c_index.singleton = true
  514. c_index.record_location @top_level
  515. @cFoo.add_method c_index
  516. @store.save_method @cFoo, c_index
  517. @store.save_cache
  518. assert_equal %w[Foo#[]], @driver.list_methods_matching('Foo#[]')
  519. assert_equal %w[Foo::[]], @driver.list_methods_matching('Foo::[]')
  520. end
  521. def test_load_method
  522. util_store
  523. method = @driver.load_method(@store, :instance_methods, 'Foo', '#',
  524. 'inherit')
  525. assert_equal @inherit, method
  526. end
  527. def test_load_method_inherited
  528. util_multi_store
  529. method = @driver.load_method(@store2, :instance_methods, 'Bar', '#',
  530. 'inherit')
  531. assert_equal nil, method
  532. end
  533. def test_load_methods_matching
  534. util_store
  535. expected = [[@store, [@inherit]]]
  536. assert_equal expected, @driver.load_methods_matching('Foo#inherit')
  537. expected = [[@store, [@blah]]]
  538. assert_equal expected, @driver.load_methods_matching('.blah')
  539. assert_empty @driver.load_methods_matching('.b')
  540. end
  541. def test_load_methods_matching_inherited
  542. util_multi_store
  543. expected = [[@store1, [@inherit]]]
  544. assert_equal expected, @driver.load_methods_matching('Bar#inherit')
  545. end
  546. def _test_page # this test doesn't do anything anymore :(
  547. @driver.use_stdout = false
  548. with_dummy_pager do
  549. @driver.page do |io|
  550. skip "couldn't find a standard pager" if io == $stdout
  551. assert @driver.paging?
  552. end
  553. end
  554. refute @driver.paging?
  555. end
  556. def test_page_stdout
  557. @driver.use_stdout = true
  558. @driver.page do |io|
  559. assert_equal $stdout, io
  560. end
  561. refute @driver.paging?
  562. end
  563. def test_parse_name_method
  564. klass, type, meth = @driver.parse_name 'foo'
  565. assert_equal '', klass, 'foo class'
  566. assert_equal '.', type, 'foo type'
  567. assert_equal 'foo', meth, 'foo method'
  568. klass, type, meth = @driver.parse_name '#foo'
  569. assert_equal '', klass, '#foo class'
  570. assert_equal '#', type, '#foo type'
  571. assert_equal 'foo', meth, '#foo method'
  572. klass, type, meth = @driver.parse_name '::foo'
  573. assert_equal '', klass, '::foo class'
  574. assert_equal '::', type, '::foo type'
  575. assert_equal 'foo', meth, '::foo method'
  576. end
  577. def test_parse_name_single_class
  578. klass, type, meth = @driver.parse_name 'Foo'
  579. assert_equal 'Foo', klass, 'Foo class'
  580. assert_equal nil, type, 'Foo type'
  581. assert_equal nil, meth, 'Foo method'
  582. klass, type, meth = @driver.parse_name 'Foo#'
  583. assert_equal 'Foo', klass, 'Foo# class'
  584. assert_equal '#', type, 'Foo# type'
  585. assert_equal nil, meth, 'Foo# method'
  586. klass, type, meth = @driver.parse_name 'Foo::'
  587. assert_equal 'Foo', klass, 'Foo:: class'
  588. assert_equal '::', type, 'Foo:: type'
  589. assert_equal nil, meth, 'Foo:: method'
  590. klass, type, meth = @driver.parse_name 'Foo.'
  591. assert_equal 'Foo', klass, 'Foo. class'
  592. assert_equal '.', type, 'Foo. type'
  593. assert_equal nil, meth, 'Foo. method'
  594. klass, type, meth = @driver.parse_name 'Foo#Bar'
  595. assert_equal 'Foo', klass, 'Foo#Bar class'
  596. assert_equal '#', type, 'Foo#Bar type'
  597. assert_equal 'Bar', meth, 'Foo#Bar method'
  598. klass, type, meth = @driver.parse_name 'Foo.Bar'
  599. assert_equal 'Foo', klass, 'Foo.Bar class'
  600. assert_equal '.', type, 'Foo.Bar type'
  601. assert_equal 'Bar', meth, 'Foo.Bar method'
  602. klass, type, meth = @driver.parse_name 'Foo::bar'
  603. assert_equal 'Foo', klass, 'Foo::bar class'
  604. assert_equal '::', type, 'Foo::bar type'
  605. assert_equal 'bar', meth, 'Foo::bar method'
  606. end
  607. def test_parse_name_namespace
  608. klass, type, meth = @driver.parse_name 'Foo::Bar'
  609. assert_equal 'Foo::Bar', klass, 'Foo::Bar class'
  610. assert_equal nil, type, 'Foo::Bar type'
  611. assert_equal nil, meth, 'Foo::Bar method'
  612. klass, type, meth = @driver.parse_name 'Foo::Bar#'
  613. assert_equal 'Foo::Bar', klass, 'Foo::Bar# class'
  614. assert_equal '#', type, 'Foo::Bar# type'
  615. assert_equal nil, meth, 'Foo::Bar# method'
  616. klass, type, meth = @driver.parse_name 'Foo::Bar#baz'
  617. assert_equal 'Foo::Bar', klass, 'Foo::Bar#baz class'
  618. assert_equal '#', type, 'Foo::Bar#baz type'
  619. assert_equal 'baz', meth, 'Foo::Bar#baz method'
  620. end
  621. def test_parse_name_special
  622. specials = %w[
  623. %
  624. &
  625. *
  626. +
  627. +@
  628. -
  629. -@
  630. /
  631. <
  632. <<
  633. <=
  634. <=>
  635. ==
  636. ===
  637. =>
  638. =~
  639. >
  640. >>
  641. []
  642. []=
  643. ^
  644. `
  645. |
  646. ~
  647. ~@
  648. ]
  649. specials.each do |special|
  650. parsed = @driver.parse_name special
  651. assert_equal ['', '.', special], parsed
  652. end
  653. end
  654. def _test_setup_pager # this test doesn't do anything anymore :(
  655. @driver.use_stdout = false
  656. pager = with_dummy_pager do @driver.setup_pager end
  657. skip "couldn't find a standard pager" unless pager
  658. assert @driver.paging?
  659. ensure
  660. pager.close if pager
  661. end
  662. def util_ancestors_store
  663. store1 = RDoc::RI::Store.new @home_ri
  664. store1.cache[:ancestors] = {
  665. 'Foo' => %w[Object],
  666. 'Foo::Bar' => %w[Foo],
  667. }
  668. store1.cache[:class_methods] = {
  669. 'Foo' => %w[c_method new],
  670. 'Foo::Bar' => %w[new],
  671. }
  672. store1.cache[:instance_methods] = {
  673. 'Foo' => %w[i_method],
  674. }
  675. store1.cache[:modules] = %w[
  676. Foo
  677. Foo::Bar
  678. ]
  679. store2 = RDoc::RI::Store.new @home_ri
  680. store2.cache[:ancestors] = {
  681. 'Foo' => %w[Mixin Object],
  682. 'Mixin' => %w[],
  683. 'Object' => %w[X Object],
  684. 'X' => %w[Object],
  685. }
  686. store2.cache[:class_methods] = {
  687. 'Foo' => %w[c_method new],
  688. 'Mixin' => %w[],
  689. 'X' => %w[],
  690. 'Object' => %w[],
  691. }
  692. store2.cache[:instance_methods] = {
  693. 'Foo' => %w[i_method],
  694. 'Mixin' => %w[],
  695. }
  696. store2.cache[:modules] = %w[
  697. Foo
  698. Mixin
  699. Object
  700. X
  701. ]
  702. @driver.stores = store1, store2
  703. end
  704. def util_multi_store
  705. util_store
  706. @store1 = @store
  707. @top_level = RDoc::TopLevel.new 'file.rb'
  708. @home_ri2 = "#{@home_ri}2"
  709. @store2 = RDoc::RI::Store.new @home_ri2
  710. # as if seen in a namespace like class Ambiguous::Other
  711. @mAmbiguous = @top_level.add_module RDoc::NormalModule, 'Ambiguous'
  712. @cFoo = @top_level.add_class RDoc::NormalClass, 'Foo'
  713. @cBar = @top_level.add_class RDoc::NormalClass, 'Bar', 'Foo'
  714. @cFoo_Baz = @cFoo.add_class RDoc::NormalClass, 'Baz'
  715. @baz = @cBar.add_method RDoc::AnyMethod.new(nil, 'baz')
  716. @baz.record_location @top_level
  717. @override = @cBar.add_method RDoc::AnyMethod.new(nil, 'override')
  718. @override.comment = 'must be displayed'
  719. @override.record_location @top_level
  720. @store2.save_class @mAmbiguous
  721. @store2.save_class @cBar
  722. @store2.save_class @cFoo_Baz
  723. @store2.save_method @cBar, @override
  724. @store2.save_method @cBar, @baz
  725. @store2.save_cache
  726. @driver.stores = [@store1, @store2]
  727. RDoc::RDoc.reset
  728. end
  729. def util_store
  730. @store = RDoc::RI::Store.new @home_ri
  731. @top_level = RDoc::TopLevel.new 'file.rb'
  732. @cFoo = @top_level.add_class RDoc::NormalClass, 'Foo'
  733. @mInc = @top_level.add_module RDoc::NormalModule, 'Inc'
  734. @cAmbiguous = @top_level.add_class RDoc::NormalClass, 'Ambiguous'
  735. doc = @RM::Document.new @RM::Paragraph.new('Include thingy')
  736. @cFooInc = @cFoo.add_include RDoc::Include.new('Inc', doc)
  737. @cFooInc.record_location @top_level
  738. @cFoo_Bar = @cFoo.add_class RDoc::NormalClass, 'Bar'
  739. @blah = @cFoo_Bar.add_method RDoc::AnyMethod.new(nil, 'blah')
  740. @blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
  741. @blah.record_location @top_level
  742. @bother = @cFoo_Bar.add_method RDoc::AnyMethod.new(nil, 'bother')
  743. @bother.block_params = "stuff"
  744. @bother.params = "(things)"
  745. @bother.record_location @top_level
  746. @new = @cFoo_Bar.add_method RDoc::AnyMethod.new nil, 'new'
  747. @new.record_location @top_level
  748. @new.singleton = true
  749. @attr = @cFoo_Bar.add_attribute RDoc::Attr.new nil, 'attr', 'RW', ''
  750. @attr.record_location @top_level
  751. @cFoo_Baz = @cFoo.add_class RDoc::NormalClass, 'Baz'
  752. @cFoo_Baz.record_location @top_level
  753. @inherit = @cFoo.add_method RDoc::AnyMethod.new(nil, 'inherit')
  754. @inherit.record_location @top_level
  755. # overriden by Bar in multi_store
  756. @overriden = @cFoo.add_method RDoc::AnyMethod.new(nil, 'override')
  757. @overriden.comment = 'must not be displayed'
  758. @overriden.record_location @top_level
  759. @store.save_class @cFoo
  760. @store.save_class @cFoo_Bar
  761. @store.save_class @cFoo_Baz
  762. @store.save_class @mInc
  763. @store.save_class @cAmbiguous
  764. @store.save_method @cFoo_Bar, @blah
  765. @store.save_method @cFoo_Bar, @bother
  766. @store.save_method @cFoo_Bar, @new
  767. @store.save_method @cFoo_Bar, @attr
  768. @store.save_method @cFoo, @inherit
  769. @store.save_method @cFoo, @overriden
  770. @store.save_cache
  771. @driver.stores = [@store]
  772. RDoc::RDoc.reset
  773. end
  774. end