Class: RubyDocTest::SpecialDirective

Inherits:
Lines
  • Object
show all
Defined in:
lib/special_directive.rb

Constant Summary collapse

NAMES =
["doctest:", "!!!", "doctest_require:"]
NAMES_FOR_RX =
NAMES.map{ |n| Regexp.escape(n) }.join("|")

Instance Method Summary collapse

Methods inherited from Lines

#initialize, #inspect, #line_number, #lines, #range

Constructor Details

This class inherits a constructor from RubyDocTest::Lines

Instance Method Details

#nameObject

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:”



17
18
19
20
21
# File 'lib/special_directive.rb', line 17

def name
  if m = lines.first.match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})/)
    m[1]
  end
end

#valueObject

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 StuffnOn Two Lines”



38
39
40
41
42
# File 'lib/special_directive.rb', line 38

def value
  if m = lines.join("\n").match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})(.*)/m)
    m[2].strip
  end
end