Class: NamedCapturesTest

Inherits:
Test::Unit::TestCase show all
Defined in:
lib/quality_extensions/regexp/named_captures.rb

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_changed, #assert_exception, #assert_includes, #assert_user_error, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Test::Unit::TestCase

Instance Method Details

#test_escaped_brackets_are_ignoredObject



79
80
81
# File 'lib/quality_extensions/regexp/named_captures.rb', line 79

def test_escaped_brackets_are_ignored
  assert /\(\)\(\)/.capture_names.empty?
end

#test_named_capturesObject



89
90
91
92
# File 'lib/quality_extensions/regexp/named_captures.rb', line 89

def test_named_captures
  assert_equal [nil, :foo, nil], /()()(?#:foo)()/.capture_names
  assert_equal [nil, :bar, nil], /((())(?#:bar))/.capture_names
end

#test_normal_comments_are_ignoredObject



82
83
84
# File 'lib/quality_extensions/regexp/named_captures.rb', line 82

def test_normal_comments_are_ignored
  assert /(?#a comment)/.capture_names.empty?
end

#test_typical_usageObject



93
94
95
96
97
98
# File 'lib/quality_extensions/regexp/named_captures.rb', line 93

def test_typical_usage
  date = /(\d+)(?#:day)\/(\d+)(?#:month)\/(\d+)(?#:year)/.match('03/12/2006')
  assert_equal 3, date.day.to_i
  assert_equal 12, date.month.to_i
  assert_equal 2006, date.year.to_i
end

#test_unnamed_captures_are_nilObject



85
86
87
88
# File 'lib/quality_extensions/regexp/named_captures.rb', line 85

def test_unnamed_captures_are_nil
  assert_equal Array.new(4), /()()()()/.capture_names
  assert_equal Array.new(4), /(((())))/.capture_names
end