<commit_before>require 'helper'

describe PandocRuby do
  before do
    @file = File.join(File.dirname(__FILE__), 'files', 'test.md')
    @file2 = File.join(File.dirname(__FILE__), 'files', 'test2.md')
    @string = '# Test String'
    @converter = PandocRuby.new(@string, :t => :rst)
  end

  after do
    PandocRuby.pandoc_path = 'pandoc'
  end

  it 'calls bare pandoc when passed no options' do
    converter = PandocRuby.new(@string)
    converter.expects(:execute).with('pandoc').returns(true)
    assert converter.convert
  end

  it 'converts with altered pandoc_path' do
    path = '/usr/bin/env pandoc'
    PandocRuby.pandoc_path = path
    converter = PandocRuby.new(@string)
    converter.expects(:execute).with(path).returns(true)
    assert converter.convert
  end

  it 'converts input passed as a string' do
    assert_equal "<h1 id=\"test-string\">Test String</h1>\n",
                 PandocRuby.new(@string).to_html
  end

  it 'converts single element array input as array of file paths' do
    assert PandocRuby.new([@file]).to_html.match(/This is a Title/)
  end

  it 'converts multiple element array input as array of file paths' do
    assert PandocRuby.new([@file, @file2]).to_html.match(/This is a Title/)
    assert PandocRuby.new([@file, @file2]).to_html.match(/A Second Title/)
  end

  it 'converts multiple element array input as array of file paths to a binary output format' do
    assert PandocRuby.new([@file, @file2]).to_epub.match(/com.apple.ibooks/)
  end

  it 'accepts short options' do
    @converter.expects(:execute).with('pandoc -t rst').returns(true)
    assert @converter.convert
  end

  it 'accepts long options' do
    converter = PandocRuby.new(@string, :to => :rst)
    converter.expects(:execute).with('pandoc --to rst').returns(true)
    assert converter.convert
  end

  it 'accepts a variety of options in initializer' do
    converter = PandocRuby.new(@string, :s, {
      :f => :markdown, :to => :rst
    }, 'no-wrap')
    converter \
      .expects(:execute) \
      .with('pandoc -s -f markdown --to rst --no-wrap') \
      .returns(true)
    assert converter.convert
  end

  it 'accepts a variety of options in convert' do
    converter = PandocRuby.new(@string)
    converter \
      .expects(:execute) \
      .with('pandoc -s -f markdown --to rst --no-wrap') \
      .returns(true)
    assert converter.convert(:s, { :f => :markdown, :to => :rst }, 'no-wrap')
  end

  it 'converts underscore symbol args to hyphenated long options' do
    converter = PandocRuby.new(@string, {
      :email_obfuscation => :javascript
    }, :table_of_contents)
    converter \
      .expects(:execute) \
      .with('pandoc --email-obfuscation javascript --table-of-contents') \
      .returns(true)
    assert converter.convert
  end

  it 'uses second arg as option' do
    converter = PandocRuby.new(@string, 'toc')
    converter.expects(:execute).with('pandoc --toc').returns(true)
    assert converter.convert
  end

  it 'passes command line options without modification' do
    converter = PandocRuby.new(@string, '+RTS', '-M512M', '-RTS')
    converter.expects(:execute).with('pandoc +RTS -M512M -RTS').returns(true)
    assert converter.convert
  end

  it 'supports reader extensions' do
    assert_equal(
      PandocRuby.convert(
        "Line 1\n# Heading",
        :from => 'markdown_strict',
        :to   => 'html'
      ),
      "<p>Line 1</p>\n<h1>Heading</h1>\n"
    )
    assert_equal(
      PandocRuby.convert(
        "Line 1\n# Heading",
        :from => 'markdown_strict+blank_before_header',
        :to   => 'html'
      ),
      "<p>Line 1 # Heading</p>\n"
    )
  end

  it 'supports writer extensions' do
    assert_equal(
      PandocRuby.convert(
        "<sub>example</sub>\n",
        :from => 'html',
        :to   => 'markdown'
      ),
      "~example~\n"<commit_msg>Improve command line option test.<commit_after>require 'helper'

describe PandocRuby do
  before do
    @file = File.join(File.dirname(__FILE__), 'files', 'test.md')
    @file2 = File.join(File.dirname(__FILE__), 'files', 'test2.md')
    @string = '# Test String'
    @converter = PandocRuby.new(@string, :t => :rst)
  end

  after do
    PandocRuby.pandoc_path = 'pandoc'
  end

  it 'calls bare pandoc when passed no options' do
    converter = PandocRuby.new(@string)
    converter.expects(:execute).with('pandoc').returns(true)
    assert converter.convert
  end

  it 'converts with altered pandoc_path' do
    path = '/usr/bin/env pandoc'
    PandocRuby.pandoc_path = path
    converter = PandocRuby.new(@string)
    converter.expects(:execute).with(path).returns(true)
    assert converter.convert
  end

  it 'converts input passed as a string' do
    assert_equal "<h1 id=\"test-string\">Test String</h1>\n",
                 PandocRuby.new(@string).to_html
  end

  it 'converts single element array input as array of file paths' do
    assert PandocRuby.new([@file]).to_html.match(/This is a Title/)
  end

  it 'converts multiple element array input as array of file paths' do
    assert PandocRuby.new([@file, @file2]).to_html.match(/This is a Title/)
    assert PandocRuby.new([@file, @file2]).to_html.match(/A Second Title/)
  end

  it 'converts multiple element array input as array of file paths to a binary output format' do
    assert PandocRuby.new([@file, @file2]).to_epub.match(/com.apple.ibooks/)
  end

  it 'accepts short options' do
    @converter.expects(:execute).with('pandoc -t rst').returns(true)
    assert @converter.convert
  end

  it 'accepts long options' do
    converter = PandocRuby.new(@string, :to => :rst)
    converter.expects(:execute).with('pandoc --to rst').returns(true)
    assert converter.convert
  end

  it 'accepts a variety of options in initializer' do
    converter = PandocRuby.new(@string, :s, {
      :f => :markdown, :to => :rst
    }, 'no-wrap')
    converter \
      .expects(:execute) \
      .with('pandoc -s -f markdown --to rst --no-wrap') \
      .returns(true)
    assert converter.convert
  end

  it 'accepts a variety of options in convert' do
    converter = PandocRuby.new(@string)
    converter \
      .expects(:execute) \
      .with('pandoc -s -f markdown --to rst --no-wrap') \
      .returns(true)
    assert converter.convert(:s, { :f => :markdown, :to => :rst }, 'no-wrap')
  end

  it 'converts underscore symbol args to hyphenated long options' do
    converter = PandocRuby.new(@string, {
      :email_obfuscation => :javascript
    }, :table_of_contents)
    converter \
      .expects(:execute) \
      .with('pandoc --email-obfuscation javascript --table-of-contents') \
      .returns(true)
    assert converter.convert
  end

  it 'uses second arg as option' do
    converter = PandocRuby.new(@string, 'toc')
    converter.expects(:execute).with('pandoc --toc').returns(true)
    assert converter.convert
  end

  it 'passes command line options without modification' do
    converter = PandocRuby.new(
      @string,
      '+RTS', '-M512M', '-RTS', '--to=markdown', '--no-wrap'
    )
    converter.expects(:execute).with(
      'pandoc +RTS -M512M -RTS --to=markdown --no-wrap'
    ).returns(true)
    assert converter.convert
  end

  it 'supports reader extensions' do
    assert_equal(
      PandocRuby.convert(
        "Line 1\n# Heading",
        :from => 'markdown_strict',
        :to   => 'html'
      ),
      "<p>Line 1</p>\n<h1>Heading</h1>\n"
    )
    assert_equal(
      PandocRuby.convert(
        "Line 1\n# Heading",
        :from => 'markdown_strict+blank_before_header',
        :to   => 'html'
      ),
      "<p>Line 1 # Heading</p>\n"
    )
  end

  it 'supports writer extensions' do
    assert_equal(
      PandocRuby.convert(
        "<sub>example</sub>\n",
        :from => 'html',
        :to   => 'markdown'
      ),
      "~example~\n"
{'fraction_non_alphanumeric': 0.13767930327868852, 'fraction_numerical': 0.004866803278688525, 'mean_word_length': 2.843011811023622, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1845577', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2599, 'n_words': 658}