Sha256: 906705b093556d7ee680d2566ece38437cec5fd63b51558bfd4b0147b652c433

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require 'test_helper'
require 'tempfile'

class RedcarpetBinTest < Redcarpet::TestCase
  def setup
    @fixture_file = Tempfile.new('bin')
    @fixture_path = @fixture_file.path

    @fixture_file.write "A ==simple== fixture file -- with " \
                        "a [link](https://github.com)."
    @fixture_file.rewind
  end

  def teardown
    @fixture_file.unlink
  end

  def test_vanilla_bin
    run_bin(@fixture_path)

    expected = "<p>A ==simple== fixture file -- with " \
               "a <a href=\"https://github.com\">link</a>.</p>\n"

    assert_equal expected, @output
  end

  def test_enabling_a_parse_option
    run_bin("--parse", "highlight", @fixture_path)

    assert_output "<mark>"
    refute_output "=="
  end

  def test_enabling_a_render_option
    run_bin("--render", "no-links", @fixture_path)

    assert_output "[link]"
    refute_output "</a>"
  end

  def test_enabling_smarty_pants
    run_bin("--smarty", @fixture_path)

    assert_output "&ndash"
    refute_output "--"
  end

  def test_version_option
    run_bin("--version")
    assert_output "Redcarpet #{Redcarpet::VERSION}"
  end

  def test_legacy_option_parsing
    run_bin("--parse-highlight", "--render-no-links", @fixture_path)

    assert_output "<mark>"
    refute_output "=="

    assert_output "[link]"
    refute_output "</a>"
  end

  private

  def run_bin(*args)
    bin_path = File.expand_path('../../bin/redcarpet', __FILE__)

    IO.popen("#{bin_path} #{args.join(" ")}") do |stream|
      @output = stream.read
    end
  end

  def assert_output(pattern)
    assert_match pattern, @output
  end

  def refute_output(pattern)
    refute_match Regexp.new(pattern), @output
  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/redcarpet-3.3.4/test/redcarpet_bin_test.rb
tdiary-5.0.2 vendor/bundle/gems/redcarpet-3.3.4/test/redcarpet_bin_test.rb
tdiary-5.0.1 vendor/bundle/gems/redcarpet-3.3.4/test/redcarpet_bin_test.rb
redcarpet-3.3.4 test/redcarpet_bin_test.rb
redcarpet-3.3.3 test/redcarpet_bin_test.rb
tight-redcarpet-3.3.2t test/redcarpet_bin_test.rb
redcarpet-3.3.2 test/redcarpet_bin_test.rb
redcarpet-3.3.1 test/redcarpet_bin_test.rb
redcarpet-3.3.0 test/redcarpet_bin_test.rb