Sha256: fbd2a25a0b46527f4744e20f50dd7fcbd67fe1093f529216d5943cca1d9f8065

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

$:.unshift(File.dirname(__FILE__)) unless
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'lines'

module RubyDocTest
  class SpecialDirective < Lines
    NAMES = ["doctest:", "!!!", "doctest_require:"]
    NAMES_FOR_RX = NAMES.map{ |n| Regexp.escape(n) }.join("|")
    
    # === Test
    #
    # doctest: The name of the directive should be detected in the first line
    # >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"])
    # >> s.name
    # => "doctest:"
    def name
      if m = lines.first.match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})/)
        m[1]
      end
    end
    
    # === Test
    #
    # doctest: The value of the directive should be detected in the first line
    # >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"])
    # >> s.value
    # => "Testing Stuff"
    #
    # >> s = RubyDocTest::SpecialDirective.new(["  # doctest: Testing Stuff", "  # Other Stuff"])
    # >> s.value
    # => "Testing Stuff"
    #
    # doctest: Multiple lines for the directive value should work as well
    # >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "  On Two Lines"])
    # >> s.value
    # => "Testing Stuff\nOn Two Lines"
    def value
      if m = lines.join("\n").match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})(.*)/m)
        m[2].strip
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 4 rubygems

Version Path
matthewrudy-rubydoctest-1.0.1 lib/special_directive.rb
tablatom-rubydoctest-1.0.0 lib/special_directive.rb
rdp-rubydoctest-1.0.1 lib/special_directive.rb
rubydoctest-1.0.0 lib/special_directive.rb