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 ? "
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", 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 "
Hi there, I am mostly text!
\n", @doc.to_html
+ assert_equal("
Hi there, I am mostly text!
\n", @doc.to_html)
end
def test_html_renderer
renderer = HtmlRenderer.new
result = renderer.render(@doc)
- assert_equal "
Hi there, I am mostly text!
\n", result
+ assert_equal("
Hi there, I am mostly text!
\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 "
Hi world, I am mostly text!
\n", result
+ assert_equal("
Hi world, I am mostly text!
\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 "
Hi there, I am mostly text!
\n", @doc.to_html
+ assert_equal("
Hi there, I am mostly text!
\n", @doc.to_html)
end
def test_inspect
@@ -84,6 +84,6 @@ def test_inspect
end
def test_pretty_print
- assert_match(/#'
+ assert_includes(out, '
')
end
md = <<~MD
@@ -21,7 +21,7 @@ module Foo
MD
CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out|
- assert_includes out, '
'
+ assert_includes(out, '
')
end
md = <<~MD
@@ -31,7 +31,7 @@ module Foo
MD
CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out|
- assert_includes out, %(
)
+ assert_includes(out, %(
))
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('(a a ){65_000}b( a a){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 abc')],
- 'nested brackets' =>
- ["#{'[' * 50_000}a#{']' * 50_000}",
- Regexp.compile('\[{50000}a\]{50000}')],
- 'nested block quotes' =>
- ["#{'> ' * 50_000}a",
- Regexp.compile('(