Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to GitHub Actions #132

Merged
merged 4 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Linting

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true
- run: bundle install
- name: Rubocop
run: bundle exec rake rubocop
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- production

jobs:
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
ruby-version: [3.0.0, 2.7.2, 2.6.6, 2.5.8]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Install dependencies
run: bundle install

- name: Run ${{ matrix.os }} tests
shell: bash
run: script/cibuild
8 changes: 1 addition & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
inherit_gem:
rubocop-standard:
- config/default.yml

Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

Naming/FileName:
Enabled: false
- config/minitest.yml

AllCops:
Exclude:
Expand Down
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions bin/commonmarker
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ doc = CommonMarker.render_doc(ARGF.read, options.active_parse_options, options.a

if options.renderer
renderer = CommonMarker::HtmlRenderer.new(extensions: options.active_extensions)
STDOUT.write(renderer.render(doc))
$stdout.write(renderer.render(doc))
else
STDOUT.write(doc.to_html(options.active_render_options, options.active_extensions))
$stdout.write(doc.to_html(options.active_render_options, options.active_extensions))
end
1 change: 1 addition & 0 deletions commonmarker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |s|

s.executables = ['commonmarker']
s.require_paths = %w[lib ext]
s.required_ruby_version = ['>= 2.4.10', '< 4.0']

s.rdoc_options += ['-x', 'ext/commonmarker/cmark/.*']

Expand Down
5 changes: 3 additions & 2 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class Render

def self.process_options(option, type)
type = Config.const_get(type.capitalize)
if option.is_a?(Symbol)
case option
when Symbol
check_option(option, type)
type.to_h[option]
elsif option.is_a?(Array)
when Array
option = [nil] if option.empty?
# neckbearding around. the map will both check the opts and then bitwise-OR it
option.map do |o|
Expand Down
2 changes: 1 addition & 1 deletion lib/commonmarker/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Node
#
# blk - A {Proc} representing the action to take for each child
def walk(&block)
return enum_for(:walk) unless block_given?
return enum_for(:walk) unless block

yield self
each do |child|
Expand Down
8 changes: 5 additions & 3 deletions lib/commonmarker/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module CommonMarker
class Renderer
attr_accessor :in_tight, :warnings, :in_plain

def initialize(options: :DEFAULT, extensions: [])
@opts = Config.process_options(options, :render)
@stream = StringIO.new(+'')
Expand All @@ -18,11 +19,12 @@ def initialize(options: :DEFAULT, extensions: [])

def out(*args)
args.each do |arg|
if arg == :children
case arg
when :children
@node.each { |child| out(child) }
elsif arg.is_a?(Array)
when Array
arg.each { |x| render(x) }
elsif arg.is_a?(Node)
when Node
render(arg)
else
@stream.write(arg)
Expand Down
5 changes: 0 additions & 5 deletions script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

set -e

if [ -d /usr/share/rbenv/shims ]; then
export PATH=/usr/share/rbenv/shims:$PATH
export RBENV_VERSION="2.1.7-github"
fi

git submodule sync
git submodule update --init
bundle
Expand Down
20 changes: 10 additions & 10 deletions test/test_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
class TestCommands < Minitest::Test
def test_basic
out = make_bin('strong.md')
assert_equal out, '<p>I am <strong>strong</strong></p>'
assert_equal('<p>I am <strong>strong</strong></p>', out)
end

def test_does_not_have_extensions
out = make_bin('table.md')
assert out.include?('| a')
refute out.include?('<p><del>hi</del>')
refute out.include?('<table> <tr> <th> a </th> <td> c </td>')
assert_includes out, '| a'
refute_includes out, '<p><del>hi</del>'
refute_includes out, '<table> <tr> <th> a </th> <td> c </td>'
end

def test_understands_extensions
out = make_bin('table.md', '--extension=table')
refute out.include?('| a')
refute out.include?('<p><del>hi</del>')
%w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert out.include?(html) }
refute_includes out, '| a'
refute_includes out, '<p><del>hi</del>'
%w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
end

def test_understands_multiple_extensions
out = make_bin('table.md', '--extension=table,strikethrough')
refute out.include?('| a')
assert out.include?('<p><del>hi</del>')
%w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert out.include?(html) }
refute_includes out, '| a'
assert_includes out, '<p><del>hi</del>'
%w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
end
end
4 changes: 2 additions & 2 deletions test/test_commonmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_to_commonmark
compare = render_doc(@markdown).to_commonmark

assert_equal \
render_doc(@markdown).to_html.gsub(/ +/, ' ').gsub(HTML_COMMENT, ''),
render_doc(compare).to_html.gsub(/ +/, ' ').gsub(HTML_COMMENT, '')
render_doc(@markdown).to_html.squeeze(' ').gsub(HTML_COMMENT, ''),
render_doc(compare).to_html.squeeze(' ').gsub(HTML_COMMENT, '')
end
end
58 changes: 29 additions & 29 deletions test/test_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,114 +17,114 @@ def setup
end

def test_get_type
assert_equal @doc.type, :document
assert_equal(:document, @doc.type)
end

def test_get_type_string
assert_equal @doc.type_string, 'document'
assert_equal('document', @doc.type_string)
end

def test_get_first_child
assert_equal @first_child.type, :paragraph
assert_equal(:paragraph, @first_child.type)
end

def test_get_next
assert_equal @first_child.first_child.next.type, :emph
assert_equal(:emph, @first_child.first_child.next.type)
end

def test_insert_before
paragraph = Node.new(:paragraph)
assert_equal @first_child.insert_before(paragraph), true
assert(@first_child.insert_before(paragraph))
assert_match "<p></p>\n<p>Hi <em>there</em>.", @doc.to_html
end

def test_insert_after
paragraph = Node.new(:paragraph)
assert_equal @first_child.insert_after(paragraph), true
assert(@first_child.insert_after(paragraph))
assert_match "<strong>many nodes</strong>!</p>\n<p></p>\n", @doc.to_html
end

def test_prepend_child
code = Node.new(:code)
assert_equal @first_child.prepend_child(code), true
assert(@first_child.prepend_child(code))
assert_match '<p><code></code>Hi <em>there</em>.', @doc.to_html
end

def test_append_child
strong = Node.new(:strong)
assert_equal @first_child.append_child(strong), true
assert(@first_child.append_child(strong))
assert_match "!<strong></strong></p>\n", @doc.to_html
end

def test_get_last_child
assert_equal @last_child.type, :paragraph
assert_equal(:paragraph, @last_child.type)
end

def test_get_parent
assert_equal @first_child.first_child.next.parent.type, :paragraph
assert_equal(:paragraph, @first_child.first_child.next.parent.type)
end

def test_get_previous
assert_equal @first_child.first_child.next.previous.type, :text
assert_equal(:text, @first_child.first_child.next.previous.type)
end

def test_get_url
assert_equal @link.url, 'https://www.github.com'
assert_equal('https://www.github.com', @link.url)
end

def test_set_url
assert_equal @link.url = 'https://www.mozilla.org', 'https://www.mozilla.org'
assert_equal('https://www.mozilla.org', @link.url = 'https://www.mozilla.org')
end

def test_get_title
assert_equal @image.title, 'Favicon'
assert_equal('Favicon', @image.title)
end

def test_set_title
assert_equal @image.title = 'Octocat', 'Octocat'
assert_equal('Octocat', @image.title = 'Octocat')
end

def test_get_header_level
assert_equal @header.header_level, 3
assert_equal(3, @header.header_level)
end

def test_set_header_level
assert_equal @header.header_level = 6, 6
assert_equal(6, @header.header_level = 6)
end

def test_get_list_type
assert_equal @ul_list.list_type, :bullet_list
assert_equal @ol_list.list_type, :ordered_list
assert_equal(:bullet_list, @ul_list.list_type)
assert_equal(:ordered_list, @ol_list.list_type)
end

def test_set_list_type
assert_equal @ul_list.list_type = :ordered_list, :ordered_list
assert_equal @ol_list.list_type = :bullet_list, :bullet_list
assert_equal(:ordered_list, @ul_list.list_type = :ordered_list)
assert_equal(:bullet_list, @ol_list.list_type = :bullet_list)
end

def test_get_list_start
assert_equal @ol_list.list_start, 1
assert_equal(1, @ol_list.list_start)
end

def test_set_list_start
assert_equal @ol_list.list_start = 8, 8
assert_equal(8, @ol_list.list_start = 8)
end

def test_get_list_tight
assert_equal @ul_list.list_tight, true
assert_equal @ol_list.list_tight, true
assert(@ul_list.list_tight)
assert(@ol_list.list_tight)
end

def test_set_list_tight
assert_equal @ul_list.list_tight = false, false
assert_equal @ol_list.list_tight = false, false
refute(@ul_list.list_tight = false)
refute(@ol_list.list_tight = false)
end

def test_get_fence_info
assert_equal @fence.fence_info, 'ruby'
assert_equal('ruby', @fence.fence_info)
end

def test_set_fence_info
assert_equal @fence.fence_info = 'javascript', 'javascript'
assert_equal('javascript', @fence.fence_info = 'javascript')
end
end
Loading