Sha256: 47214088336e681dbcc8a2f0a42aea4f511456c0fbc0e12579175dd57d5b9dd2

Contents?: true

Size: 1.49 KB

Versions: 27

Compression:

Stored size: 1.49 KB

Contents

# coding: utf-8
require 'commonmarker'
require 'minitest/autorun'
require 'minitest/pride'

include CommonMarker

FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')

def open_spec_file(filename)
  line_number = 0
  start_line = 0
  end_line = 0
  example_number = 0
  markdown_lines = []
  html_lines = []
  state = 0 # 0 regular text, 1 markdown example, 2 html output
  headertext = ''
  tests = []
  extensions = []

  header_re = Regexp.new('#+ ')
  filepath = File.join('ext', 'commonmarker', 'cmark', 'test', filename)

  File.readlines(filepath, encoding: "utf-8").each do |line|
    line_number += 1

    l = line.strip
    if l =~ /^`{32} example(.*)$/
      state = 1
      extensions = $1.split
    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,
        :example => example_number,
        :start_line => start_line,
        :end_line => end_line,
        :section => headertext,
        :extensions => extensions.map(&:to_sym),
      }
      start_line = 0
      markdown_lines = []
      html_lines = []
    elsif l == '.'
      state = 2
    elsif state == 1
      start_line = line_number - 1 if start_line == 0
      markdown_lines << "#{line}"
    elsif state == 2
      html_lines << "#{line}"
    elsif state == 0 && header_re.match(line)
      headertext = line.sub(header_re, '').strip
    end
  end

  tests
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
commonmarker-0.17.6 test/test_helper.rb
commonmarker-0.17.5 test/test_helper.rb
commonmarker-0.17.4 test/test_helper.rb
commonmarker-0.17.2 test/test_helper.rb
commonmarker-0.17.1 test/test_helper.rb
commonmarker-0.17.0 test/test_helper.rb
commonmarker-0.16.8 test/test_helper.rb
commonmarker-0.16.7 test/test_helper.rb
commonmarker-0.16.6 test/test_helper.rb
commonmarker-0.16.5 test/test_helper.rb
commonmarker-0.16.4 test/test_helper.rb
commonmarker-0.16.1 test/test_helper.rb
commonmarker-0.16.2 test/test_helper.rb
commonmarker-0.16.3 test/test_helper.rb
commonmarker-0.16.0 test/test_helper.rb
commonmarker-0.15.0 test/test_helper.rb
commonmarker-0.14.15 test/test_helper.rb
commonmarker-0.14.14 test/test_helper.rb
commonmarker-0.14.13 test/test_helper.rb
commonmarker-0.14.12 test/test_helper.rb