Sha256: 75b04208fda367484b4b79bdfddd2a96163341e2bf607bed4bda1d363cbc7eba

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# $Id: test-regexp.rb 173 2006-08-21 09:19:04Z bitherder $

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'test/unit'
require 'core_ext/regexp'
  
class TestString < Test::Unit::TestCase
  def testOneLine
    match = "/^(\s+)$/".to_regexp.match(" \n ")
    assert_equal(" ", match[1])
  end

  def testMultiLine
    text_in = " \n \n"
    expected_match = " \n \n"
    regex_from_string = '/^(\s+)$/m'.to_regexp
    
    assert_equal(Regexp::MULTILINE, regex_from_string.options)
    assert_equal('^(\s+)$', regex_from_string.source)
    
    plain_regex = /^(\s+)$/m

    assert_equal(Regexp::MULTILINE, plain_regex.options)
    assert_equal('^(\s+)$', plain_regex.source)
    
    match_from_string = regex_from_string.match(text_in)
    match_from_regex = /^(\s+)$/m.match(text_in)
    
    assert_equal(expected_match, match_from_regex[1])
    assert_equal(expected_match, match_from_string[1])
  end
  
  def testWhitespaceAtEndOfLine
    regexp = '/^(#{1,6})\s*([^#\s][^#]*?)(?:\s*\#+)?\s*?$/'.to_regexp
    match = regexp.match "## header\n\nSome text."
    
    assert_equal("##", match[1])
    assert_equal("header", match[2])
    assert_equal("## header", match[0])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tartan-0.2.1 test/test-regexp.rb
tartan-0.2.0 test/test-regexp.rb
tartan-0.1.1 test/test-regexp.rb