diff --git a/Gemfile b/Gemfile index 9d9521fd..36ca595a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,11 @@ # frozen_string_literal: true -source 'https://rubygems.org/' +source "https://rubygems.org/" gemspec group :benchmark do - gem 'benchmark-ips' - gem 'kramdown' - gem 'redcarpet' + gem "benchmark-ips" + gem "kramdown" + gem "redcarpet" end diff --git a/Rakefile b/Rakefile index d0143e5b..4daed669 100644 --- a/Rakefile +++ b/Rakefile @@ -1,108 +1,109 @@ # frozen_string_literal: true -require 'date' -require 'rake/clean' -require 'rake/extensiontask' -require 'digest/md5' +require "date" +require "rake/clean" +require "rake/extensiontask" +require "digest/md5" -host_os = RbConfig::CONFIG['host_os'] -require 'devkit' if host_os == 'mingw32' +host_os = RbConfig::CONFIG["host_os"] +require "devkit" if host_os == "mingw32" task default: [:test] # Gem Spec -gem_spec = Gem::Specification.load('commonmarker.gemspec') +gem_spec = Gem::Specification.load("commonmarker.gemspec") # Ruby Extension -Rake::ExtensionTask.new('commonmarker', gem_spec) do |ext| - ext.lib_dir = File.join('lib', 'commonmarker') +Rake::ExtensionTask.new("commonmarker", gem_spec) do |ext| + ext.lib_dir = File.join("lib", "commonmarker") end # Packaging -require 'bundler/gem_tasks' +require "bundler/gem_tasks" # Testing -require 'rake/testtask' +require "rake/testtask" -Rake::TestTask.new('test:unit') do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/test_*.rb' +Rake::TestTask.new("test:unit") do |t| + t.libs << "lib" + t.libs << "test" + t.pattern = "test/test_*.rb" t.verbose = true t.warning = false end -task 'test:unit' => :compile +desc "Run unit tests" +task "test:unit" => :compile -desc 'Run unit and conformance tests' -task test: %w[test:unit] +desc "Run unit and conformance tests" +task test: ["test:unit"] -require 'rubocop/rake_task' +require "rubocop/rake_task" RuboCop::RakeTask.new(:rubocop) -desc 'Run benchmarks' +desc "Run benchmarks" task :benchmark do - if ENV['FETCH_PROGIT'] - `rm -rf test/progit` - `git clone https://github.com/progit/progit.git test/progit` - langs = %w[ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw] + if ENV["FETCH_PROGIT"] + %x(rm -rf test/progit) + %x(git clone https://github.com/progit/progit.git test/progit) + langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"] langs.each do |lang| - `cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md` + %x(cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md) end end - $LOAD_PATH.unshift 'lib' - load 'test/benchmark.rb' + $LOAD_PATH.unshift("lib") + load "test/benchmark.rb" end -desc 'Match C style of cmark' +desc "Match C style of cmark" task :format do - sh 'clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h' + sh "clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h" end # Documentation -require 'rdoc/task' +require "rdoc/task" -desc 'Generate API documentation' +desc "Generate API documentation" RDoc::Task.new do |rd| - rd.rdoc_dir = 'docs' - rd.main = 'README.md' - rd.rdoc_files.include 'README.md', 'lib/**/*.rb', 'ext/commonmarker/commonmarker.c' - - rd.options << '--markup tomdoc' - rd.options << '--inline-source' - rd.options << '--line-numbers' - rd.options << '--all' - rd.options << '--fileboxes' + rd.rdoc_dir = "docs" + rd.main = "README.md" + rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/commonmarker/commonmarker.c") + + rd.options << "--markup tomdoc" + rd.options << "--inline-source" + rd.options << "--line-numbers" + rd.options << "--all" + rd.options << "--fileboxes" end -desc 'Generate the documentation and run a web server' +desc "Generate the documentation and run a web server" task serve: [:rdoc] do - require 'webrick' + require "webrick" - puts 'Navigate to http://localhost:3000 to see the docs' + puts "Navigate to http://localhost:3000 to see the docs" - server = WEBrick::HTTPServer.new Port: 3000 - server.mount '/', WEBrick::HTTPServlet::FileHandler, 'docs' - trap('INT') { server.stop } + server = WEBrick::HTTPServer.new(Port: 3000) + server.mount("/", WEBrick::HTTPServlet::FileHandler, "docs") + trap("INT") { server.stop } server.start end -desc 'Generate and publish docs to gh-pages' +desc "Generate and publish docs to gh-pages" task publish: [:rdoc] do - require 'tmpdir' - require 'shellwords' + require "tmpdir" + require "shellwords" Dir.mktmpdir do |tmp| system "mv docs/* #{tmp}" - system 'git checkout origin/gh-pages' - system 'rm -rf *' + system "git checkout origin/gh-pages" + system "rm -rf *" system "mv #{tmp}/* ." message = Shellwords.escape("Site updated at #{Time.now.utc}") - system 'git add .' + system "git add ." system "git commit -am #{message}" - system 'git push origin gh-pages --force' - system 'git checkout master' - system 'echo yolo' + system "git push origin gh-pages --force" + system "git checkout master" + system "echo yolo" end end diff --git a/commonmarker.gemspec b/commonmarker.gemspec index 36b66d6f..b2d58847 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -1,39 +1,38 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'commonmarker/version' +require "commonmarker/version" Gem::Specification.new do |s| - s.name = 'commonmarker' + s.name = "commonmarker" s.version = CommonMarker::VERSION - s.summary = 'CommonMark parser and renderer. Written in C, wrapped in Ruby.' - s.description = 'A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library.' - s.authors = ['Garen Torikian', 'Ashe Connor'] - s.homepage = 'https://github.com/gjtorikian/commonmarker' - s.license = 'MIT' + s.summary = "CommonMark parser and renderer. Written in C, wrapped in Ruby." + s.description = "A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library." + s.authors = ["Garen Torikian", "Ashe Connor"] + s.homepage = "https://github.com/gjtorikian/commonmarker" + s.license = "MIT" - s.files = %w[LICENSE.txt README.md Rakefile commonmarker.gemspec bin/commonmarker] - s.files += Dir.glob('lib/**/*.rb') - s.files += Dir.glob('ext/commonmarker/*.*') - s.test_files = Dir.glob('test/**/*').reject { |f| f == 'test/benchinput.md' || f.start_with?('test/progit/') } - s.extensions = ['ext/commonmarker/extconf.rb'] + s.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"] + s.files += Dir.glob("lib/**/*.rb") + s.files += Dir.glob("ext/commonmarker/*.*") + s.extensions = ["ext/commonmarker/extconf.rb"] - s.executables = ['commonmarker'] - s.require_paths = %w[lib ext] - s.required_ruby_version = ['>= 2.6', '< 4.0'] + s.executables = ["commonmarker"] + s.require_paths = ["lib", "ext"] + s.required_ruby_version = [">= 2.6", "< 4.0"] - s.metadata['rubygems_mfa_required'] = 'true' + s.metadata["rubygems_mfa_required"] = "true" - s.rdoc_options += ['-x', 'ext/commonmarker/cmark/.*'] + s.rdoc_options += ["-x", "ext/commonmarker/cmark/.*"] - s.add_development_dependency 'awesome_print' - s.add_development_dependency 'json', '~> 2.3' - s.add_development_dependency 'minitest', '~> 5.6' - s.add_development_dependency 'minitest-focus', '~> 1.1' - s.add_development_dependency 'rake' - s.add_development_dependency 'rake-compiler', '~> 0.9' - s.add_development_dependency 'rdoc', '~> 6.2' - s.add_development_dependency 'rubocop' - s.add_development_dependency 'rubocop-standard' + s.add_development_dependency("awesome_print") + s.add_development_dependency("json", "~> 2.3") + s.add_development_dependency("minitest", "~> 5.6") + s.add_development_dependency("minitest-focus", "~> 1.1") + s.add_development_dependency("rake") + s.add_development_dependency("rake-compiler", "~> 0.9") + s.add_development_dependency("rdoc", "~> 6.2") + s.add_development_dependency("rubocop") + s.add_development_dependency("rubocop-standard") end diff --git a/lib/commonmarker.rb b/lib/commonmarker.rb index d4efa7d3..edfc0e57 100755 --- a/lib/commonmarker.rb +++ b/lib/commonmarker.rb @@ -1,15 +1,15 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'commonmarker/commonmarker' -require 'commonmarker/config' -require 'commonmarker/node' -require 'commonmarker/renderer' -require 'commonmarker/renderer/html_renderer' -require 'commonmarker/version' +require "commonmarker/commonmarker" +require "commonmarker/config" +require "commonmarker/node" +require "commonmarker/renderer" +require "commonmarker/renderer/html_renderer" +require "commonmarker/version" begin - require 'awesome_print' + require "awesome_print" rescue LoadError; end # rubocop:disable Lint/SuppressedException module CommonMarker # Public: Parses a Markdown string into an HTML string. @@ -23,7 +23,7 @@ def self.render_html(text, options = :DEFAULT, extensions = []) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) opts = Config.process_options(options, :render) - Node.markdown_to_html(text.encode('UTF-8'), opts, extensions) + Node.markdown_to_html(text.encode("UTF-8"), opts, extensions) end # Public: Parses a Markdown string into a `document` node. @@ -37,7 +37,7 @@ def self.render_doc(text, options = :DEFAULT, extensions = []) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) opts = Config.process_options(options, :parse) - text = text.encode('UTF-8') + text = text.encode("UTF-8") Node.parse_document(text, text.bytesize, opts, extensions) end end diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index 15d05a9a..59f02790 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -13,7 +13,7 @@ module Config SMART: (1 << 10), LIBERAL_HTML_TAG: (1 << 12), FOOTNOTES: (1 << 13), - STRIKETHROUGH_DOUBLE_TILDE: (1 << 14) + STRIKETHROUGH_DOUBLE_TILDE: (1 << 14), }.freeze, render: { DEFAULT: 0, @@ -28,9 +28,9 @@ module Config FOOTNOTES: (1 << 13), STRIKETHROUGH_DOUBLE_TILDE: (1 << 14), TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15), - FULL_INFO_STRING: (1 << 16) + FULL_INFO_STRING: (1 << 16), }.freeze, - format: %i[html xml commonmark plaintext].freeze + format: [:html, :xml, :commonmark, :plaintext].freeze, }.freeze def self.process_options(option, type) diff --git a/lib/commonmarker/node.rb b/lib/commonmarker/node.rb index c4c0dcc4..ea2a1995 100644 --- a/lib/commonmarker/node.rb +++ b/lib/commonmarker/node.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'commonmarker/node/inspect' +require "commonmarker/node/inspect" module CommonMarker class Node @@ -27,7 +27,7 @@ def walk(&block) # Returns a {String}. def to_html(options = :DEFAULT, extensions = []) opts = Config.process_options(options, :render) - _render_html(opts, extensions).force_encoding('utf-8') + _render_html(opts, extensions).force_encoding("utf-8") end # Public: Convert the node to an XML string. @@ -37,7 +37,7 @@ def to_html(options = :DEFAULT, extensions = []) # Returns a {String}. def to_xml(options = :DEFAULT) opts = Config.process_options(options, :render) - _render_xml(opts).force_encoding('utf-8') + _render_xml(opts).force_encoding("utf-8") end # Public: Convert the node to a CommonMark string. @@ -48,7 +48,7 @@ def to_xml(options = :DEFAULT) # Returns a {String}. def to_commonmark(options = :DEFAULT, width = 120) opts = Config.process_options(options, :render) - _render_commonmark(opts, width).force_encoding('utf-8') + _render_commonmark(opts, width).force_encoding("utf-8") end # Public: Convert the node to a plain text string. @@ -59,7 +59,7 @@ def to_commonmark(options = :DEFAULT, width = 120) # Returns a {String}. def to_plaintext(options = :DEFAULT, width = 120) opts = Config.process_options(options, :render) - _render_plaintext(opts, width).force_encoding('utf-8') + _render_plaintext(opts, width).force_encoding("utf-8") end # Public: Iterate over the children (if any) of the current pointer. @@ -76,7 +76,7 @@ def each # Deprecated: Please use `each` instead def each_child(&block) - warn '[DEPRECATION] `each_child` is deprecated. Please use `each` instead.' + warn("[DEPRECATION] `each_child` is deprecated. Please use `each` instead.") each(&block) end end diff --git a/lib/commonmarker/node/inspect.rb b/lib/commonmarker/node/inspect.rb index 08b5c66e..f80f3db5 100644 --- a/lib/commonmarker/node/inspect.rb +++ b/lib/commonmarker/node/inspect.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'pp' +require "pp" module CommonMarker class Node @@ -8,33 +8,23 @@ module Inspect PP_INDENT_SIZE = 2 def inspect - PP.pp(self, +'', Float::INFINITY) + PP.pp(self, +"", Float::INFINITY) end # @param printer [PrettyPrint] pp def pretty_print(printer) - printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", '>') do + printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do printer.breakable - attrs = %i[ - sourcepos - string_content - url - title - header_level - list_type - list_start - list_tight - fence_info - ].map do |name| + attrs = [:sourcepos, :string_content, :url, :title, :header_level, :list_type, :list_start, :list_tight, :fence_info].map do |name| [name, __send__(name)] rescue NodeError nil end.compact printer.seplist(attrs) do |name, value| - printer.text "#{name}=" - printer.pp value + printer.text("#{name}=") + printer.pp(value) end if first_child @@ -46,8 +36,8 @@ def pretty_print(printer) children << node node = node.next end - printer.text 'children=' - printer.pp children + printer.text("children=") + printer.pp(children) end end end diff --git a/lib/commonmarker/renderer.rb b/lib/commonmarker/renderer.rb index 42e19cab..3be353e6 100644 --- a/lib/commonmarker/renderer.rb +++ b/lib/commonmarker/renderer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'set' -require 'stringio' +require "set" +require "stringio" module CommonMarker class Renderer @@ -9,9 +9,9 @@ class Renderer def initialize(options: :DEFAULT, extensions: []) @opts = Config.process_options(options, :render) - @stream = StringIO.new(+'') + @stream = StringIO.new(+"") @need_blocksep = false - @warnings = Set.new [] + @warnings = Set.new([]) @in_tight = false @in_plain = false @tagfilter = extensions.include?(:tagfilter) @@ -121,7 +121,7 @@ def tagfilter(str) end def sourcepos(node) - return '' unless option_enabled?(:SOURCEPOS) + return "" unless option_enabled?(:SOURCEPOS) s = node.sourcepos " data-sourcepos=\"#{s[:start_line]}:#{s[:start_column]}-" \ diff --git a/lib/commonmarker/renderer/html_renderer.rb b/lib/commonmarker/renderer/html_renderer.rb index 9aef413c..df10042d 100644 --- a/lib/commonmarker/renderer/html_renderer.rb +++ b/lib/commonmarker/renderer/html_renderer.rb @@ -9,8 +9,8 @@ def document(_) def header(node) block do - out('", :children, - '') + out("", :children, + "") end end @@ -19,10 +19,10 @@ def paragraph(node) out(:children) else block do - container("", '

') do + container("", "

") do out(:children) if node.parent.type == :footnote_definition && node.next.nil? - out(' ') + out(" ") out_footnote_backref end end @@ -36,16 +36,16 @@ def list(node) block do if node.list_type == :bullet_list - container("\n", '') do + container("\n", "") do out(:children) end else start = if node.list_start == 1 - "\n" - else - "
    \n" - end - container(start, '
') do + "\n" + else + "
    \n" + end + container(start, "
") do out(:children) end end @@ -57,26 +57,26 @@ def list(node) def list_item(node) block do tasklist_data = tasklist(node) - container("#{' ' if tasklist?(node)}", '') do + container("#{" " if tasklist?(node)}", "") do out(:children) end end end def tasklist(node) - return '' unless tasklist?(node) + return "" unless tasklist?(node) state = if checked?(node) - 'checked="" disabled=""' - else - 'disabled=""' - end + 'checked="" disabled=""' + else + 'disabled=""' + end ">\n", '') do + container("\n", "") do out(:children) end end @@ -93,17 +93,17 @@ def code_block(node) if option_enabled?(:GITHUB_PRE_LANG) out("') + out(">") else out("') else - out('>') + out(">") end end out(escape_html(node.string_content)) - out('') + out("") end end @@ -112,7 +112,7 @@ def html(node) if option_enabled?(:UNSAFE) out(tagfilter(node.string_content)) else - out('') + out("") end end end @@ -121,22 +121,22 @@ def inline_html(node) if option_enabled?(:UNSAFE) out(tagfilter(node.string_content)) else - out('') + out("") end end def emph(_) - out('', :children, '') + out("", :children, "") end def strong(_) - out('', :children, '') + out("", :children, "") end def link(node) - out('', :children, '') + out(">", :children, "") end def image(node) @@ -145,7 +145,7 @@ def image(node) out(' alt="', :children, '"') end out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty? - out(' />') + out(" />") end def text(node) @@ -153,9 +153,9 @@ def text(node) end def code(node) - out('') + out("") out(escape_html(node.string_content)) - out('') + out("") end def linebreak(_node) @@ -166,7 +166,7 @@ def softbreak(_) if option_enabled?(:HARDBREAKS) out("
\n") elsif option_enabled?(:NOBREAKS) - out(' ') + out(" ") else out("\n") end @@ -199,17 +199,17 @@ def table_row(node) def table_cell(node) align = case @alignments[@column_index] - when :left then ' align="left"' - when :right then ' align="right"' - when :center then ' align="center"' - else; '' - end + when :left then ' align="left"' + when :right then ' align="right"' + when :center then ' align="center"' + else; "" + end out(@in_header ? "" : "", :children, @in_header ? "\n" : "\n") @column_index += 1 end def strikethrough(_) - out('', :children, '') + out("", :children, "") end def footnote_reference(node) @@ -242,7 +242,7 @@ def out_footnote_backref end def tasklist?(node) - node.type_string == 'tasklist' + node.type_string == "tasklist" end def checked?(node) diff --git a/lib/commonmarker/version.rb b/lib/commonmarker/version.rb index c0123a52..cd93b468 100644 --- a/lib/commonmarker/version.rb +++ b/lib/commonmarker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CommonMarker - VERSION = '0.23.4' + VERSION = "0.23.4" end diff --git a/test/benchmark.rb b/test/benchmark.rb index 46849ad7..e51eda58 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -1,37 +1,37 @@ # frozen_string_literal: true -require 'benchmark/ips' -require 'commonmarker' -require 'redcarpet' -require 'kramdown' -require 'benchmark' +require "benchmark/ips" +require "commonmarker" +require "redcarpet" +require "kramdown" +require "benchmark" -benchinput = File.read('test/benchinput.md').freeze +benchinput = File.read("test/benchinput.md").freeze printf("input size = %d bytes\n\n", { bytes: benchinput.bytesize }) Benchmark.ips do |x| - x.report('redcarpet') do + x.report("redcarpet") do Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput) end - x.report('commonmarker with to_html') do + x.report("commonmarker with to_html") do CommonMarker.render_html(benchinput) end - x.report('commonmarker with to_xml') do + x.report("commonmarker with to_xml") do CommonMarker.render_html(benchinput) end - x.report('commonmarker with ruby HtmlRenderer') do + x.report("commonmarker with ruby HtmlRenderer") do CommonMarker::HtmlRenderer.new.render(CommonMarker.render_doc(benchinput)) end - x.report('commonmarker with render_doc.to_html') do + x.report("commonmarker with render_doc.to_html") do CommonMarker.render_doc(benchinput, :DEFAULT, [:autolink]).to_html(:DEFAULT, [:autolink]) end - x.report('kramdown') do + x.report("kramdown") do Kramdown::Document.new(benchinput).to_html(benchinput) end diff --git a/test/test_attributes.rb b/test/test_attributes.rb index ac7de579..e5e3c903 100644 --- a/test/test_attributes.rb +++ b/test/test_attributes.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestAttributes < Minitest::Test def setup - contents = fixtures_file('dingus.md') + contents = fixtures_file("dingus.md") @doc = CommonMarker.render_doc(contents.strip) end @@ -19,6 +19,6 @@ def test_sourcepos result = [{ start_line: 1, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 1, start_column: 1, end_line: 1, end_column: 17 }, { start_line: 1, start_column: 4, end_line: 1, end_column: 17 }, { start_line: 3, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 3, start_column: 1, end_line: 3, end_column: 55 }, { start_line: 4, start_column: 1, end_line: 4, end_column: 53 }, { start_line: 4, start_column: 2, end_line: 4, end_column: 14 }, { start_line: 4, start_column: 54, end_line: 4, end_column: 58 }, { start_line: 5, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 7, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 7, start_column: 1, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 8, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 9, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 9, start_column: 4, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 10, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }] - assert_equal result, sourcepos + assert_equal(result, sourcepos) end end diff --git a/test/test_basics.rb b/test/test_basics.rb index c291b544..70bbe76b 100644 --- a/test/test_basics.rb +++ b/test/test_basics.rb @@ -1,35 +1,35 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestBasics < Minitest::Test def setup - @doc = CommonMarker.render_doc('Hi *there*') + @doc = CommonMarker.render_doc("Hi *there*") end def test_to_html - assert_equal "

Hi there

\n", @doc.to_html + assert_equal("

Hi there

\n", @doc.to_html) end def test_markdown_to_html - html = CommonMarker.render_html('Hi *there*') - assert_equal "

Hi there

\n", html + html = CommonMarker.render_html("Hi *there*") + assert_equal("

Hi there

\n", html) end # basic test that just checks if every option is accepted & no errors are thrown def test_accept_every_option text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" - parse_opt = %i[SOURCEPOS UNSAFE VALIDATE_UTF8 SMART LIBERAL_HTML_TAG FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE] - render_opt = parse_opt + %i[HARDBREAKS NOBREAKS GITHUB_PRE_LANG TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING] + parse_opt = [:SOURCEPOS, :UNSAFE, :VALIDATE_UTF8, :SMART, :LIBERAL_HTML_TAG, :FOOTNOTES, :STRIKETHROUGH_DOUBLE_TILDE] + render_opt = parse_opt + [:HARDBREAKS, :NOBREAKS, :GITHUB_PRE_LANG, :TABLE_PREFER_STYLE_ATTRIBUTES, :FULL_INFO_STRING] - extensions = %i[table tasklist strikethrough autolink tagfilter] + extensions = [:table, :tasklist, :strikethrough, :autolink, :tagfilter] - assert_equal "

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html + assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html) # NOTE: how tho the doc returned has sourcepos info, by default the renderer # won't emit it. for that we need to pass in the render opt - assert_equal "

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions) + assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)) - assert_equal "

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_html(text, parse_opt, extensions) + assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_html(text, parse_opt, extensions)) end end diff --git a/test/test_commands.rb b/test/test_commands.rb index e61ffb7e..f26fe89f 100644 --- a/test/test_commands.rb +++ b/test/test_commands.rb @@ -1,72 +1,72 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestCommands < Minitest::Test def test_basic - out = make_bin('strong.md') - assert_equal('

I am strong

', out) + out = make_bin("strong.md") + assert_equal("

I am strong

", out) end def test_does_not_have_extensions - out = make_bin('table.md') - assert_includes out, '| a' - refute_includes out, '

hi' - refute_includes out, '' + out = make_bin("table.md") + assert_includes(out, "| a") + refute_includes(out, "

hi") + refute_includes(out, "

a c
") end def test_understands_extensions - out = make_bin('table.md', '--extension=table') - refute_includes out, '| a' - refute_includes out, '

hi' - %w[

a c
].each { |html| assert_includes out, html } + out = make_bin("table.md", "--extension=table") + refute_includes(out, "| a") + refute_includes(out, "

hi") + ["

a c
", "", "", ""].each { |html| assert_includes(out, html) } end def test_understands_multiple_extensions - out = make_bin('table.md', '--extension=table,strikethrough') - refute_includes out, '| a' - assert_includes out, '

hi' - %w[

", "a", "", "c", "
].each { |html| assert_includes out, html } + out = make_bin("table.md", "--extension=table,strikethrough") + refute_includes(out, "| a") + assert_includes(out, "

hi") + ["

a c
", "", "", ""].each { |html| assert_includes(out, html) } end def test_understands_html_format_with_renderer_and_extensions - out = make_bin('table.md', '--to=html --extension=table,strikethrough --html-renderer') - refute_includes out, '| a' - assert_includes out, '

hi' - %w[

", "a", "", "c", "
].each { |html| assert_includes out, html } + out = make_bin("table.md", "--to=html --extension=table,strikethrough --html-renderer") + refute_includes(out, "| a") + assert_includes(out, "

hi") + ["

a c
", "", "", ""].each { |html| assert_includes(out, html) } end def test_understands_xml_format - out = make_bin('strong.md', '--to=xml') - assert_includes out, '' - assert_includes out, 'strong' + out = make_bin("strong.md", "--to=xml") + assert_includes(out, '') + assert_includes(out, 'strong') end def test_understands_commonmark_format - out = make_bin('strong.md', '--to=commonmark') - assert_equal('I am **strong**', out) + out = make_bin("strong.md", "--to=commonmark") + assert_equal("I am **strong**", out) end def test_understands_plaintext_format - out = make_bin('strong.md', '--to=plaintext') - assert_equal('I am strong', out) + out = make_bin("strong.md", "--to=plaintext") + assert_equal("I am strong", out) end def test_aborts_invalid_format _out, err = capture_subprocess_io do - make_bin('strong.md', '--to=unknown') + make_bin("strong.md", "--to=unknown") end - assert_match "format 'unknown' not found", err + assert_match("format 'unknown' not found", err) end def test_aborts_format_and_html_renderer_combinations (CommonMarker::Config::OPTS[:format] - [:html]).each do |format| _out, err = capture_subprocess_io do - make_bin('strong.md', "--to=#{format} --html-renderer") + make_bin("strong.md", "--to=#{format} --html-renderer") end - assert_match "format '#{format}' does not support using the HtmlRenderer renderer", err + assert_match("format '#{format}' does not support using the HtmlRenderer renderer", err) end end end diff --git a/test/test_commonmark.rb b/test/test_commonmark.rb index 75980e03..0c8d00ca 100644 --- a/test/test_commonmark.rb +++ b/test/test_commonmark.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestCommonmark < Minitest::Test HTML_COMMENT = /\s?/.freeze @@ -23,14 +23,15 @@ def setup end def render_doc(doc) - CommonMarker.render_doc(doc, :DEFAULT, %i[table]) + CommonMarker.render_doc(doc, :DEFAULT, [:table]) end def test_to_commonmark compare = render_doc(@markdown).to_commonmark - assert_equal \ - render_doc(@markdown).to_html.squeeze(' ').gsub(HTML_COMMENT, ''), - render_doc(compare).to_html.squeeze(' ').gsub(HTML_COMMENT, '') + assert_equal(\ + render_doc(@markdown).to_html.squeeze(" ").gsub(HTML_COMMENT, ""), + render_doc(compare).to_html.squeeze(" ").gsub(HTML_COMMENT, "") + ) end end diff --git a/test/test_doc.rb b/test/test_doc.rb index c2a8649a..9b77a638 100644 --- a/test/test_doc.rb +++ b/test/test_doc.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestDocNode < Minitest::Test def setup - @doc = CommonMarker.render_doc('Hi *there*. This has __many nodes__!') + @doc = CommonMarker.render_doc("Hi *there*. This has __many nodes__!") @first_child = @doc.first_child @last_child = @doc.last_child - @link = CommonMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child + @link = CommonMarker.render_doc("[GitHub](https://www.github.com)").first_child.first_child @image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")') @image = @image.first_child.first_child - @header = CommonMarker.render_doc('### Header Three').first_child + @header = CommonMarker.render_doc("### Header Three").first_child @ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child @ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child @fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child @@ -21,7 +21,7 @@ def test_get_type end def test_get_type_string - assert_equal('document', @doc.type_string) + assert_equal("document", @doc.type_string) end def test_get_first_child @@ -35,25 +35,25 @@ def test_get_next def test_insert_before paragraph = Node.new(:paragraph) assert(@first_child.insert_before(paragraph)) - assert_match "

\n

Hi there.", @doc.to_html + assert_match("

\n

Hi there.", @doc.to_html) end def test_insert_after paragraph = Node.new(:paragraph) assert(@first_child.insert_after(paragraph)) - assert_match "many nodes!

\n

\n", @doc.to_html + assert_match("many nodes!

\n

\n", @doc.to_html) end def test_prepend_child code = Node.new(:code) assert(@first_child.prepend_child(code)) - assert_match '

Hi there.', @doc.to_html + assert_match("

Hi there.", @doc.to_html) end def test_append_child strong = Node.new(:strong) assert(@first_child.append_child(strong)) - assert_match "!

\n", @doc.to_html + assert_match("!

\n", @doc.to_html) end def test_get_last_child @@ -69,19 +69,19 @@ def test_get_previous end def test_get_url - assert_equal('https://www.github.com', @link.url) + assert_equal("https://www.github.com", @link.url) end def test_set_url - assert_equal('https://www.mozilla.org', @link.url = 'https://www.mozilla.org') + assert_equal("https://www.mozilla.org", @link.url = "https://www.mozilla.org") end def test_get_title - assert_equal('Favicon', @image.title) + assert_equal("Favicon", @image.title) end def test_set_title - assert_equal('Octocat', @image.title = 'Octocat') + assert_equal("Octocat", @image.title = "Octocat") end def test_get_header_level @@ -121,10 +121,10 @@ def test_set_list_tight end def test_get_fence_info - assert_equal('ruby', @fence.fence_info) + assert_equal("ruby", @fence.fence_info) end def test_set_fence_info - assert_equal('javascript', @fence.fence_info = 'javascript') + assert_equal("javascript", @fence.fence_info = "javascript") end end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index 2470bc6e..35d5c33c 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestEncoding < Minitest::Test # see http://git.io/vq4FR def test_encoding - contents = fixtures_file('curly.md') + contents = fixtures_file("curly.md") doc = CommonMarker.render_doc(contents, :SMART) render = doc.to_html - assert_equal('

This curly quote “makes commonmarker throw an exception”.

', render.rstrip) + assert_equal("

This curly quote “makes commonmarker throw an exception”.

", render.rstrip) render = doc.to_xml assert_includes(render, 'This curly quote “makes commonmarker throw an exception”.') end def test_string_content_is_utf8 - doc = CommonMarker.render_doc('Hi *there*') + doc = CommonMarker.render_doc("Hi *there*") text = doc.first_child.last_child.first_child - assert_equal('there', text.string_content) - assert_equal('UTF-8', text.string_content.encoding.name) + assert_equal("there", text.string_content) + assert_equal("UTF-8", text.string_content.encoding.name) end end diff --git a/test/test_extensions.rb b/test/test_extensions.rb index 80327a36..ced40e34 100644 --- a/test/test_extensions.rb +++ b/test/test_extensions.rb @@ -1,76 +1,76 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestExtensions < Minitest::Test def setup - @markdown = fixtures_file('table.md') + @markdown = fixtures_file("table.md") end def test_uses_specified_extensions - CommonMarker.render_html(@markdown, :DEFAULT, %i[]).tap do |out| - assert_includes out, '| a' - assert_includes out, '| x' - assert_includes out, '~~hi~~' + CommonMarker.render_html(@markdown, :DEFAULT, []).tap do |out| + assert_includes(out, "| a") + assert_includes(out, "| x") + assert_includes(out, "~~hi~~") end - CommonMarker.render_html(@markdown, :DEFAULT, %i[table]).tap do |out| - refute_includes out, '| a' - %w[
", "a", "", "c", "
x].each { |html| assert_includes out, html } - assert_includes out, '~~hi~~' + CommonMarker.render_html(@markdown, :DEFAULT, [:table]).tap do |out| + refute_includes(out, "| a") + ["
a c
", "", "", "", "x"].each { |html| assert_includes(out, html) } + assert_includes(out, "~~hi~~") end - CommonMarker.render_html(@markdown, :DEFAULT, %i[strikethrough]).tap do |out| - assert_includes out, '| a' - refute_includes out, '~~hi~~' - assert_includes out, 'hi' + CommonMarker.render_html(@markdown, :DEFAULT, [:strikethrough]).tap do |out| + assert_includes(out, "| a") + refute_includes(out, "~~hi~~") + assert_includes(out, "hi") end - doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) + doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) assert_equal("

~a~ b ~~~c~~~

\n", doc.to_html) - html = CommonMarker.render_html('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) + html = CommonMarker.render_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) assert_equal("

~a~ b ~~~c~~~

\n", html) - CommonMarker.render_html(@markdown, :DEFAULT, %i[table strikethrough]).tap do |out| - refute_includes out, '| a' - refute_includes out, '| x' - refute_includes out, '~~hi~~' + CommonMarker.render_html(@markdown, :DEFAULT, [:table, :strikethrough]).tap do |out| + refute_includes(out, "| a") + refute_includes(out, "| x") + refute_includes(out, "~~hi~~") end end def test_extensions_with_renderers - doc = CommonMarker.render_doc(@markdown, :DEFAULT, %i[table]) + doc = CommonMarker.render_doc(@markdown, :DEFAULT, [:table]) doc.to_html.tap do |out| - refute_includes out, '| a' - %w[
", "a", "", "c", "
x].each { |html| assert_includes out, html } - assert_includes out, '~~hi~~' + refute_includes(out, "| a") + ["
a c
", "", "", "", "x"].each { |html| assert_includes(out, html) } + assert_includes(out, "~~hi~~") end HtmlRenderer.new.render(doc).tap do |out| - refute_includes out, '| a' - %w[
", "a", "", "c", "
x].each { |html| assert_includes out, html } - assert_includes out, '~~hi~~' + refute_includes(out, "| a") + ["
a c
", "", "", "", "x"].each { |html| assert_includes(out, html) } + assert_includes(out, "~~hi~~") end - doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) + doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) assert_equal("

~a~ b ~~~c~~~

\n", HtmlRenderer.new.render(doc)) end def test_bad_extension_specifications - assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, 'nope') } - assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ['table']) } - assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, %i[table bad]) } + assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, "nope") } + assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ["table"]) } + assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, [:table, :bad]) } end def test_comments_are_kept_as_expected - assert_equal " <xmp>\n", - CommonMarker.render_html(" \n", :UNSAFE, %i[tagfilter]) + assert_equal("<!--hello--> <blah> &lt;xmp>\n", + CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, [:tagfilter])) end def test_table_prefer_style_attributes - assert_equal(<<~HTML, CommonMarker.render_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, %i[table])) + assert_equal(<<~HTML, CommonMarker.render_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, [:table])) <table> <thead> <tr> @@ -99,7 +99,7 @@ def test_table_prefer_style_attributes end def test_plaintext - assert_equal(<<~HTML, CommonMarker.render_doc(<<~MD, :DEFAULT, %i[table strikethrough]).to_plaintext) + assert_equal(<<~HTML, CommonMarker.render_doc(<<~MD, :DEFAULT, [:table, :strikethrough]).to_plaintext) Hello ~there~. | a | diff --git a/test/test_footnotes.rb b/test/test_footnotes.rb index c13df397..7cdfd93a 100644 --- a/test/test_footnotes.rb +++ b/test/test_footnotes.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestFootnotes < Minitest::Test def setup @@ -19,7 +19,7 @@ def test_to_html </section> HTML - assert_equal expected, @doc.to_html + assert_equal(expected, @doc.to_html) end def test_html_renderer @@ -34,7 +34,7 @@ def test_html_renderer </section> HTML - assert_equal expected, CommonMarker::HtmlRenderer.new.render(@doc) + assert_equal(expected, CommonMarker::HtmlRenderer.new.render(@doc)) end def test_render_html @@ -55,6 +55,6 @@ def test_render_html </ol> </section> HTML - assert_equal expected, CommonMarker.render_html(md, :FOOTNOTES) + assert_equal(expected, CommonMarker.render_html(md, :FOOTNOTES)) end end diff --git a/test/test_gc.rb b/test/test_gc.rb index c9919d4b..05456e45 100644 --- a/test/test_gc.rb +++ b/test/test_gc.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # rubocop:disable Lint/UselessAssignment -require 'test_helper' +require "test_helper" class TestNode < Minitest::Test # These tests are somewhat fragile. It would be better to allocate lots @@ -9,26 +9,26 @@ class TestNode < Minitest::Test # isn't valid by accident. def test_drop_parent_reference - doc = CommonMarker.render_doc('Hi *there*') + doc = CommonMarker.render_doc("Hi *there*") text = doc.first_child.last_child.first_child doc = nil GC.start # Test that doc has not been freed. - assert_equal 'there', text.string_content + assert_equal("there", text.string_content) end def test_drop_child_reference - doc = CommonMarker.render_doc('Hi *there*') + doc = CommonMarker.render_doc("Hi *there*") text = doc.first_child.last_child.first_child text = nil GC.start # Test that the cached child object is still valid. text = doc.first_child.last_child.first_child - assert_equal 'there', text.string_content + assert_equal("there", text.string_content) end def test_remove_parent - doc = CommonMarker.render_doc('Hi *there*') + doc = CommonMarker.render_doc("Hi *there*") para = doc.first_child para.delete doc = nil diff --git a/test/test_helper.rb b/test/test_helper.rb index 5963982c..498d2be1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'commonmarker' -require 'minitest/autorun' -require 'minitest/pride' -require 'minitest/focus' +require "commonmarker" +require "minitest/autorun" +require "minitest/pride" +require "minitest/focus" -include CommonMarker # rubocop:disable Style/MixinUsage +include CommonMarker -FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures') +FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") def fixtures_file(file) - File.read(File.join(FIXTURES_DIR, file), encoding: 'utf-8') + File.read(File.join(FIXTURES_DIR, file), encoding: "utf-8") end -def make_bin(file, args = '') - `ruby bin/commonmarker #{File.join(FIXTURES_DIR, file)} #{args}`.chomp +def make_bin(file, args = "") + %x(ruby bin/commonmarker #{File.join(FIXTURES_DIR, file)} #{args}).chomp end def open_spec_file(filename) @@ -25,37 +25,37 @@ def open_spec_file(filename) markdown_lines = [] html_lines = [] state = 0 # 0 regular text, 1 markdown example, 2 html output - headertext = '' + headertext = "" tests = [] extensions = [] - header_re = Regexp.new('#+ ') - filepath = File.join('ext', 'commonmarker', 'cmark-upstream', 'test', filename) + header_re = Regexp.new("#+ ") + filepath = File.join("ext", "commonmarker", "cmark-upstream", "test", filename) - File.readlines(filepath, encoding: 'utf-8').each do |line| + File.readlines(filepath, encoding: "utf-8").each do |line| line_number += 1 l = line.strip if l =~ /^`{32} example(.*)$/ state = 1 extensions = Regexp.last_match(1).split - elsif l == '`' * 32 + elsif l == "`" * 32 state = 0 example_number += 1 end_line = line_number tests << { - markdown: markdown_lines.join.tr('→', "\t"), - html: html_lines.join.tr('→', "\t").rstrip, + markdown: markdown_lines.join.tr("→", "\t"), + html: html_lines.join.tr("→", "\t").rstrip, example: example_number, start_line: start_line, end_line: end_line, section: headertext, - extensions: extensions.map(&:to_sym) + extensions: extensions.map(&:to_sym), } start_line = 0 markdown_lines = [] html_lines = [] - elsif l == '.' + elsif l == "." state = 2 elsif state == 1 start_line = line_number - 1 if start_line.zero? @@ -63,7 +63,7 @@ def open_spec_file(filename) elsif state == 2 html_lines << line.to_s elsif state.zero? && header_re.match(line) - headertext = line.sub(header_re, '').strip + headertext = line.sub(header_re, "").strip end end diff --git a/test/test_linebreaks.rb b/test/test_linebreaks.rb index bad80e20..f81b049c 100644 --- a/test/test_linebreaks.rb +++ b/test/test_linebreaks.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestLinebreaks < Minitest::Test def test_hardbreak_no_spaces doc = CommonMarker.render_doc("foo\nbaz") - assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS) + assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) end def test_hardbreak_with_spaces doc = CommonMarker.render_doc("foo \nbaz") - assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS) + assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) end end diff --git a/test/test_maliciousness.rb b/test/test_maliciousness.rb index 971ce15c..454cf50f 100644 --- a/test/test_maliciousness.rb +++ b/test/test_maliciousness.rb @@ -1,260 +1,260 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" module CommonMarker class TestMaliciousness < Minitest::Test def setup - @doc = CommonMarker.render_doc('Hi *there*') + @doc = CommonMarker.render_doc("Hi *there*") end def test_init_with_bad_type - assert_raises TypeError do + assert_raises(TypeError) do Node.new(123) end - assert_raises NodeError do + assert_raises(NodeError) do Node.new(:totes_fake) end - assert_raises TypeError do + assert_raises(TypeError) do Node.new([]) end - assert_raises TypeError do + assert_raises(TypeError) do Node.new([23]) end - assert_raises TypeError do + assert_raises(TypeError) do Node.new(nil) end end def test_rendering_with_bad_type - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html("foo \n baz", 123) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html("foo \n baz", :totes_fake) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html("foo \n baz", []) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html("foo \n baz", [23]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html("foo \n baz", nil) end - assert_raises TypeError do - CommonMarker.render_html("foo \n baz", [:SMART, 'totes_fake']) + assert_raises(TypeError) do + CommonMarker.render_html("foo \n baz", [:SMART, "totes_fake"]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html(123) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html([123]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_html(nil) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", 123) end - err = assert_raises TypeError do + err = assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", :safe) end - assert_equal('option \':safe\' does not exist for CommonMarker::Config::OPTS[:parse]', err.message) + assert_equal("option ':safe' does not exist for CommonMarker::Config::OPTS[:parse]", err.message) - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", :totes_fake) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", []) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", [23]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc("foo \n baz", nil) end - assert_raises TypeError do - CommonMarker.render_doc("foo \n baz", [:SMART, 'totes_fake']) + assert_raises(TypeError) do + CommonMarker.render_doc("foo \n baz", [:SMART, "totes_fake"]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc(123) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc([123]) end - assert_raises TypeError do + assert_raises(TypeError) do CommonMarker.render_doc(nil) end end def test_bad_set_string_content - assert_raises TypeError do + assert_raises(TypeError) do @doc.string_content = 123 end end def test_bad_walking - assert_nil @doc.parent - assert_nil @doc.previous + assert_nil(@doc.parent) + assert_nil(@doc.previous) end def test_bad_insertion code = Node.new(:code) - assert_raises NodeError do + assert_raises(NodeError) do @doc.insert_before(code) end paragraph = Node.new(:paragraph) - assert_raises NodeError do + assert_raises(NodeError) do @doc.insert_after(paragraph) end document = Node.new(:document) - assert_raises NodeError do + assert_raises(NodeError) do @doc.prepend_child(document) end - assert_raises NodeError do + assert_raises(NodeError) do @doc.append_child(document) end end def test_bad_url_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.url end end def test_bad_url_set - assert_raises NodeError do - @doc.url = '123' + assert_raises(NodeError) do + @doc.url = "123" end - link = CommonMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child - assert_raises TypeError do + link = CommonMarker.render_doc("[GitHub](https://www.github.com)").first_child.first_child + assert_raises(TypeError) do link.url = 123 end end def test_bad_title_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.title end end def test_bad_title_set - assert_raises NodeError do - @doc.title = '123' + assert_raises(NodeError) do + @doc.title = "123" end image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")') image = image.first_child.first_child - assert_raises TypeError do + assert_raises(TypeError) do image.title = 123 end end def test_bad_header_level_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.header_level end end def test_bad_header_level_set - assert_raises NodeError do + assert_raises(NodeError) do @doc.header_level = 1 end - header = CommonMarker.render_doc('### Header Three').first_child - assert_raises TypeError do - header.header_level = '123' + header = CommonMarker.render_doc("### Header Three").first_child + assert_raises(TypeError) do + header.header_level = "123" end end def test_bad_list_type_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_type end end def test_bad_list_type_set - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_type = :bullet_list end ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child - assert_raises NodeError do + assert_raises(NodeError) do ul_list.list_type = :fake end - assert_raises TypeError do + assert_raises(TypeError) do ul_list.list_type = 1234 end end def test_bad_list_start_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_start end end def test_bad_list_start_set - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_start = 12 end ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child - assert_raises TypeError do + assert_raises(TypeError) do ol_list.list_start = :fake end end def test_bad_list_tight_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_tight end end def test_bad_list_tight_set - assert_raises NodeError do + assert_raises(NodeError) do @doc.list_tight = false end end def test_bad_fence_info_get - assert_raises NodeError do + assert_raises(NodeError) do @doc.fence_info end end def test_bad_fence_info_set - assert_raises NodeError do - @doc.fence_info = 'ruby' + assert_raises(NodeError) do + @doc.fence_info = "ruby" end fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child - assert_raises TypeError do + assert_raises(TypeError) do fence.fence_info = 123 end end diff --git a/test/test_node.rb b/test/test_node.rb index a532a7bb..b21c4269 100644 --- a/test/test_node.rb +++ b/test/test_node.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestNode < Minitest::Test def setup - @doc = CommonMarker.render_doc('Hi *there*, I am mostly text!') + @doc = CommonMarker.render_doc("Hi *there*, I am mostly text!") end def test_walk @@ -12,7 +12,7 @@ def test_walk @doc.walk do |node| nodes << node.type end - assert_equal %i[document paragraph text emph text text], nodes + assert_equal([:document, :paragraph, :text, :emph, :text, :text], nodes) end def test_each @@ -20,7 +20,7 @@ def test_each @doc.first_child.each do |node| nodes << node.type end - assert_equal %i[text emph text], nodes + assert_equal([:text, :emph, :text], nodes) end def test_deprecated_each_child @@ -30,43 +30,43 @@ def test_deprecated_each_child nodes << node.type end end - assert_equal %i[text emph text], nodes + assert_equal([:text, :emph, :text], nodes) assert_match(/`each_child` is deprecated/, err) end def test_select nodes = @doc.first_child.select { |node| node.type == :text } - assert_equal CommonMarker::Node, nodes.first.class - assert_equal %i[text text], nodes.map(&:type) + assert_equal(CommonMarker::Node, nodes.first.class) + assert_equal([:text, :text], nodes.map(&:type)) end def test_map nodes = @doc.first_child.map(&:type) - assert_equal %i[text emph text], nodes + assert_equal([:text, :emph, :text], nodes) end def test_insert_illegal - assert_raises NodeError do + assert_raises(NodeError) do @doc.insert_before(@doc) end end def test_to_html - assert_equal "<p>Hi <em>there</em>, I am mostly text!</p>\n", @doc.to_html + assert_equal("<p>Hi <em>there</em>, I am mostly text!</p>\n", @doc.to_html) end def test_html_renderer renderer = HtmlRenderer.new result = renderer.render(@doc) - assert_equal "<p>Hi <em>there</em>, I am mostly text!</p>\n", result + assert_equal("<p>Hi <em>there</em>, I am mostly text!</p>\n", result) end def test_walk_and_set_string_content @doc.walk do |node| - node.string_content = 'world' if node.type == :text && node.string_content == 'there' + node.string_content = "world" if node.type == :text && node.string_content == "there" end result = HtmlRenderer.new.render(@doc) - assert_equal "<p>Hi <em>world</em>, I am mostly text!</p>\n", result + assert_equal("<p>Hi <em>world</em>, I am mostly text!</p>\n", result) end def test_walk_and_delete_node @@ -76,7 +76,7 @@ def test_walk_and_delete_node node.delete end end - assert_equal "<p>Hi there, I am mostly text!</p>\n", @doc.to_html + assert_equal("<p>Hi there, I am mostly text!</p>\n", @doc.to_html) end def test_inspect @@ -84,6 +84,6 @@ def test_inspect end def test_pretty_print - assert_match(/#<CommonMarker::Node\(document\):/, PP.pp(@doc, +'')) + assert_match(/#<CommonMarker::Node\(document\):/, PP.pp(@doc, +"")) end end diff --git a/test/test_options.rb b/test/test_options.rb index 850fface..82e8151d 100644 --- a/test/test_options.rb +++ b/test/test_options.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestExtensions < Minitest::Test def test_full_info_string @@ -11,7 +11,7 @@ module Foo MD CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes out, '<pre><code class="language-ruby">' + assert_includes(out, '<pre><code class="language-ruby">') end md = <<~MD @@ -21,7 +21,7 @@ module Foo MD CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes out, '<pre><code class="language-ruby" data-meta="my info string">' + assert_includes(out, '<pre><code class="language-ruby" data-meta="my info string">') end md = <<~MD @@ -31,7 +31,7 @@ module Foo MD CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes out, %(<pre><code class="language-ruby" data-meta="my � string">) + assert_includes(out, %(<pre><code class="language-ruby" data-meta="my � string">)) end end end diff --git a/test/test_pathological_inputs.rb b/test/test_pathological_inputs.rb index b94e4575..eb8fca3e 100644 --- a/test/test_pathological_inputs.rb +++ b/test/test_pathological_inputs.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'test_helper' -require 'minitest/benchmark' if ENV['BENCH'] +require "test_helper" +require "minitest/benchmark" if ENV["BENCH"] def markdown(str) CommonMarker.render_doc(str).to_html @@ -9,39 +9,39 @@ def markdown(str) # list of pairs consisting of input and a regex that must match the output. pathological = { - 'nested strong emph' => - ["#{'*a **a ' * 65_000}b#{' a** a*' * 65_000}", - Regexp.compile('(<em>a <strong>a ){65_000}b( a</strong> a</em>){65_000}')], - 'many emph closers with no openers' => - [('a_ ' * 65_000), - Regexp.compile('(a[_] ){64999}a_')], - 'many emph openers with no closers' => - [('_a ' * 65_000), - Regexp.compile('(_a ){64999}_a')], - 'many link closers with no openers' => - [('a]' * 65_000), - Regexp.compile('(a\]){65_000}')], - 'many link openers with no closers' => - [('[a' * 65_000), - Regexp.compile('(\[a){65_000}')], - 'mismatched openers and closers' => - [('*a_ ' * 50_000), - Regexp.compile('([*]a[_] ){49999}[*]a_')], - 'link openers and emph closers' => - [('[ a_' * 50_000), - Regexp.compile('(\[ a_){50000}')], - 'hard link/emph case' => - ['**x [a*b**c*](d)', - Regexp.compile('\\*\\*x <a href=\'d\'>a<em>b</em><em>c</em></a>')], - 'nested brackets' => - ["#{'[' * 50_000}a#{']' * 50_000}", - Regexp.compile('\[{50000}a\]{50000}')], - 'nested block quotes' => - ["#{'> ' * 50_000}a", - Regexp.compile('(<blockquote>\n){50000}')], - 'U+0000 in input' => + "nested strong emph" => + ["#{"*a **a " * 65_000}b#{" a** a*" * 65_000}", + Regexp.compile("(<em>a <strong>a ){65_000}b( a</strong> a</em>){65_000}"),], + "many emph closers with no openers" => + [("a_ " * 65_000), + Regexp.compile("(a[_] ){64999}a_"),], + "many emph openers with no closers" => + [("_a " * 65_000), + Regexp.compile("(_a ){64999}_a"),], + "many link closers with no openers" => + [("a]" * 65_000), + Regexp.compile('(a\]){65_000}'),], + "many link openers with no closers" => + [("[a" * 65_000), + Regexp.compile('(\[a){65_000}'),], + "mismatched openers and closers" => + [("*a_ " * 50_000), + Regexp.compile("([*]a[_] ){49999}[*]a_"),], + "link openers and emph closers" => + [("[ a_" * 50_000), + Regexp.compile('(\[ a_){50000}'),], + "hard link/emph case" => + ["**x [a*b**c*](d)", + Regexp.compile('\\*\\*x <a href=\'d\'>a<em>b</em><em>c</em></a>'),], + "nested brackets" => + ["#{"[" * 50_000}a#{"]" * 50_000}", + Regexp.compile('\[{50000}a\]{50000}'),], + "nested block quotes" => + ["#{"> " * 50_000}a", + Regexp.compile('(<blockquote>\n){50000}'),], + "U+0000 in input" => ['abc\u0000de\u0000', - Regexp.compile('abc\ufffd?de\ufffd?')] + Regexp.compile('abc\ufffd?de\ufffd?'),], } pathological.each_pair do |name, description| @@ -51,43 +51,43 @@ def markdown(str) end end -if ENV['BENCH'] +if ENV["BENCH"] class PathologicalInputsPerformanceTest < Minitest::Benchmark def test_bench_pathological_one - assert_performance_linear 0.99 do |n| - star = '*' * (n * 10) + assert_performance_linear(0.99) do |n| + star = "*" * (n * 10) markdown("#{star}#{star}hi#{star}#{star}") end end def test_bench_pathological_two - assert_performance_linear 0.99 do |n| - c = '`t`t`t`t`t`t' * (n * 10) + assert_performance_linear(0.99) do |n| + c = "`t`t`t`t`t`t" * (n * 10) markdown(c) end end def test_bench_pathological_three - assert_performance_linear 0.99 do |n| - markdown(" [a]: #{'A' * n}\n\n#{'[a][]' * n}\n") + assert_performance_linear(0.99) do |n| + markdown(" [a]: #{"A" * n}\n\n#{"[a][]" * n}\n") end end def test_bench_pathological_four - assert_performance_linear 0.5 do |n| - markdown("#{'[' * n}a#{']' * n}") + assert_performance_linear(0.5) do |n| + markdown("#{"[" * n}a#{"]" * n}") end end def test_bench_pathological_five - assert_performance_linear 0.99 do |n| - markdown("#{'**a *a ' * n}#{'a* a**' * n}") + assert_performance_linear(0.99) do |n| + markdown("#{"**a *a " * n}#{"a* a**" * n}") end end def test_bench_unbound_recursion - assert_performance_linear 0.99 do |n| - markdown("#{'[' * n}foo#{'](bar)' * n}") + assert_performance_linear(0.99) do |n| + markdown("#{"[" * n}foo#{"](bar)" * n}") end end end diff --git a/test/test_plaintext.rb b/test/test_plaintext.rb index cc47c680..3ac425df 100644 --- a/test/test_plaintext.rb +++ b/test/test_plaintext.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestPlaintext < Minitest::Test def setup @@ -21,13 +21,13 @@ def setup end def render_doc(doc) - CommonMarker.render_doc(doc, :DEFAULT, %i[table]) + CommonMarker.render_doc(doc, :DEFAULT, [:table]) end def test_to_commonmark compare = render_doc(@markdown).to_plaintext - assert_equal <<~PLAINTEXT, compare + assert_equal(<<~PLAINTEXT, compare) Hi there! 1. I am a numeric list. diff --git a/test/test_renderer.rb b/test/test_renderer.rb index eaec3936..d3209a29 100644 --- a/test/test_renderer.rb +++ b/test/test_renderer.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestRenderer < Minitest::Test def setup - @doc = CommonMarker.render_doc('Hi *there*') + @doc = CommonMarker.render_doc("Hi *there*") end def test_html_renderer renderer = HtmlRenderer.new result = renderer.render(@doc) - assert_equal "<p>Hi <em>there</em></p>\n", result + assert_equal("<p>Hi <em>there</em></p>\n", result) end def test_multiple_tables @@ -23,9 +23,9 @@ def test_multiple_tables | :------: | ---: | :------ | | Foo | Bar | Baz | DOC - doc = CommonMarker.render_doc(content, :DEFAULT, %i[autolink table tagfilter]) + doc = CommonMarker.render_doc(content, :DEFAULT, [:autolink, :table, :tagfilter]) results = CommonMarker::HtmlRenderer.new.render(doc) - assert_equal 2, results.scan(/<tbody>/).size + assert_equal(2, results.scan(/<tbody>/).size) end def test_escape_html_encoding @@ -41,7 +41,7 @@ def text(node) end renderer = my_renderer.new - assert_equal Encoding::UTF_8, renderer.render(@doc).encoding - assert_equal renderer.input_encoding, renderer.output_encoding + assert_equal(Encoding::UTF_8, renderer.render(@doc).encoding) + assert_equal(renderer.input_encoding, renderer.output_encoding) end end diff --git a/test/test_smartpunct.rb b/test/test_smartpunct.rb index a8a7cec1..c2e308ee 100644 --- a/test/test_smartpunct.rb +++ b/test/test_smartpunct.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class SmartPunctTest < Minitest::Test - smart_punct = open_spec_file('smart_punct.txt') + smart_punct = open_spec_file("smart_punct.txt") smart_punct.each do |testcase| doc = CommonMarker.render_doc(testcase[:markdown], :SMART) @@ -22,6 +22,6 @@ def test_smart_hardbreak_no_spaces_render_doc markdown = "\"foo\"\nbaz" result = "<p>“foo”<br />\nbaz</p>\n" doc = CommonMarker.render_doc(markdown, :SMART) - assert_equal result, doc.to_html([:HARDBREAKS]) + assert_equal(result, doc.to_html([:HARDBREAKS])) end end diff --git a/test/test_spec.rb b/test/test_spec.rb index f2d7a8f2..9ef865aa 100644 --- a/test/test_spec.rb +++ b/test/test_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' -require 'json' +require "test_helper" +require "json" class TestSpec < Minitest::Test - spec = open_spec_file('spec.txt') + spec = open_spec_file("spec.txt") spec.each do |testcase| next if testcase[:extensions].include?(:disabled) @@ -22,8 +22,8 @@ class TestSpec < Minitest::Test end define_method("test_sourcepos_example_#{testcase[:example]}") do - lhs = doc.to_html(%i[UNSAFE SOURCEPOS], testcase[:extensions]).rstrip - rhs = HtmlRenderer.new(options: %i[UNSAFE SOURCEPOS], extensions: testcase[:extensions]).render(doc).rstrip + lhs = doc.to_html([:UNSAFE, :SOURCEPOS], testcase[:extensions]).rstrip + rhs = HtmlRenderer.new(options: [:UNSAFE, :SOURCEPOS], extensions: testcase[:extensions]).render(doc).rstrip assert_equal lhs, rhs, testcase[:markdown] end end diff --git a/test/test_tasklists.rb b/test/test_tasklists.rb index f9db26a1..a135376a 100644 --- a/test/test_tasklists.rb +++ b/test/test_tasklists.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestTasklists < Minitest::Test def setup @@ -8,7 +8,7 @@ def setup - [x] Add task list - [ ] Define task list MD - @doc = CommonMarker.render_doc(text, :DEFAULT, %i[tasklist]) + @doc = CommonMarker.render_doc(text, :DEFAULT, [:tasklist]) @expected = <<~HTML <ul> <li><input type="checkbox" checked="" disabled="" /> Add task list</li> @@ -18,26 +18,26 @@ def setup end def test_to_html - assert_equal @expected, @doc.to_html + assert_equal(@expected, @doc.to_html) end def test_html_renderer - assert_equal @expected, CommonMarker::HtmlRenderer.new.render(@doc) + assert_equal(@expected, CommonMarker::HtmlRenderer.new.render(@doc)) end def test_tasklist_state list = @doc.first_child - assert_equal 'checked', list.first_child.tasklist_state - assert list.first_child.tasklist_item_checked? - assert_equal 'unchecked', list.first_child.next.tasklist_state - refute list.first_child.next.tasklist_item_checked? + assert_equal("checked", list.first_child.tasklist_state) + assert_predicate(list.first_child, :tasklist_item_checked?) + assert_equal("unchecked", list.first_child.next.tasklist_state) + refute_predicate(list.first_child.next, :tasklist_item_checked?) end def test_set_tasklist_state list = @doc.first_child list.first_child.tasklist_item_checked = false - refute list.first_child.tasklist_item_checked? + refute_predicate(list.first_child, :tasklist_item_checked?) list.first_child.next.tasklist_item_checked = true - assert list.first_child.next.tasklist_item_checked? + assert_predicate(list.first_child.next, :tasklist_item_checked?) end end diff --git a/test/test_xml.rb b/test/test_xml.rb index c22176a7..89848904 100644 --- a/test/test_xml.rb +++ b/test/test_xml.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestXml < Minitest::Test def setup @@ -27,7 +27,7 @@ def render_doc(doc) def test_to_xml compare = render_doc(@markdown).to_xml(:SOURCEPOS) - assert_equal <<~XML, compare + assert_equal(<<~XML, compare) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document SYSTEM "CommonMark.dtd"> <document sourcepos="1:1-12:13" xmlns="http://commonmark.org/xml/1.0"> @@ -94,7 +94,7 @@ def test_to_xml def test_to_xml_with_quotes compare = render_doc('"quotes" should be escaped').to_xml(:DEFAULT) - assert_equal <<~XML, compare + assert_equal(<<~XML, compare) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document SYSTEM "CommonMark.dtd"> <document xmlns="http://commonmark.org/xml/1.0">
", "a", "", "c", "