# frozen_string_literal: true require_relative 'helper' class TestRDocGeneratorDarkfish < RDoc::TestCase def setup super @lib_dir = "#{@pwd}/lib" $LOAD_PATH.unshift @lib_dir # ensure we load from this RDoc @options = RDoc::Options.new @options.option_parser = OptionParser.new @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}" FileUtils.mkdir_p @tmpdir Dir.chdir @tmpdir @options.op_dir = @tmpdir @options.generator = RDoc::Generator::Darkfish $LOAD_PATH.each do |path| darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/' next unless File.directory? darkfish_dir @options.template_dir = darkfish_dir break end @rdoc.options = @options @g = @options.generator.new @store, @options @rdoc.generator = @g @top_level = @store.add_file 'file.rb' @top_level.parser = RDoc::Parser::Ruby @klass = @top_level.add_class RDoc::NormalClass, 'Klass' @alias_constant = RDoc::Constant.new 'A', nil, '' @alias_constant.record_location @top_level @top_level.add_constant @alias_constant @klass.add_module_alias @klass, @klass.name, @alias_constant, @top_level @meth = RDoc::AnyMethod.new nil, 'method' @meth_bang = RDoc::AnyMethod.new nil, 'method!' @meth_with_html_tag_yield = RDoc::AnyMethod.new nil, 'method_with_html_tag_yield' @meth_with_html_tag_yield.block_params = '%<>, yield_arg' @attr = RDoc::Attr.new nil, 'attr', 'RW', '' @klass.add_method @meth @klass.add_method @meth_bang @klass.add_method @meth_with_html_tag_yield @klass.add_attribute @attr @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored' @ignored.ignore @store.complete :private @object = @store.find_class_or_module 'Object' @klass_alias = @store.find_class_or_module 'Klass::A' end def teardown super $LOAD_PATH.shift Dir.chdir @pwd FileUtils.rm_rf @tmpdir end def test_generate top_level = @store.add_file 'file.rb' top_level.add_class @klass.class, @klass.name @klass.add_class RDoc::NormalClass, 'Inner' @klass.add_comment <<~RDOC, top_level = Heading 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod == Heading 1.1 tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, === Heading 1.1.1 quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo ==== Heading 1.1.1.1 consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse == Heading 1.2 cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat == Heading 1.3 non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. === Heading 1.3.1 etc etc... RDOC @g.generate assert_file 'index.html' assert_file 'Object.html' assert_file 'Klass.html' assert_file 'Klass/Inner.html' assert_file 'table_of_contents.html' assert_file 'js/search_index.js' assert_hard_link 'css/rdoc.css' assert_hard_link 'css/fonts.css' assert_hard_link 'fonts/SourceCodePro-Bold.ttf' assert_hard_link 'fonts/SourceCodePro-Regular.ttf' encoding = Regexp.escape Encoding::UTF_8.name assert_match %r%%, File.binread('index.html') assert_match %r%%, File.binread('Object.html') refute_match(/Ignored/, File.binread('index.html')) summary = File.binread('index.html')[%r[.*]m] assert_match(%r[Klass/Inner\.html".*>Inner<], summary) klass = File.binread('Klass.html') klassnav = klass[%r[