Skip to content

Commit

Permalink
working..
Browse files Browse the repository at this point in the history
  • Loading branch information
Danish Khan committed Mar 14, 2011
1 parent 13b8543 commit 63e82ae
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions koans/about_regular_expressions.rb
Expand Up @@ -3,32 +3,32 @@

class AboutRegularExpressions < EdgeCase::Koan
def test_a_pattern_is_a_regular_expression
assert_equal __, /pattern/.class
assert_equal Regexp, /pattern/.class
end

def test_a_regexp_can_search_a_string_for_matching_content
assert_equal __, "some matching content"[/match/]
assert_equal "match", "some matching content"[/match/]
end

def test_a_failed_match_returns_nil
assert_equal __, "some matching content"[/missing/]
assert_equal nil, "some matching content"[/missing/]
end

# ------------------------------------------------------------------

def test_question_mark_means_optional
assert_equal __, "abbcccddddeeeee"[/ab?/]
assert_equal __, "abbcccddddeeeee"[/az?/]
assert_equal "ab", "abbcccddddeeeee"[/ab?/]
assert_equal "a", "abbcccddddeeeee"[/az?/]
end

def test_plus_means_one_or_more
assert_equal __, "abbcccddddeeeee"[/bc+/]
assert_equal "bccc", "abbcccddddeeeee"[/bc+/]
end

def test_asterisk_means_zero_or_more
assert_equal __, "abbcccddddeeeee"[/ab*/]
assert_equal __, "abbcccddddeeeee"[/az*/]
assert_equal __, "abbcccddddeeeee"[/z*/]
assert_equal "abb", "abbcccddddeeeee"[/ab*/]
assert_equal "a", "abbcccddddeeeee"[/az*/]
assert_equal "", "abbcccddddeeeee"[/z*/]

# THINK ABOUT IT:
#
Expand All @@ -44,27 +44,27 @@ def test_asterisk_means_zero_or_more
# ------------------------------------------------------------------

def test_the_left_most_match_wins
assert_equal __, "abbccc az"[/az*/]
assert_equal "a", "abbccc az"[/az*/]
end

# ------------------------------------------------------------------

def test_character_classes_give_options_for_a_character
animals = ["cat", "bat", "rat", "zat"]
assert_equal __, animals.select { |a| a[/[cbr]at/] }
assert_equal ["cat", "bat", "rat"], animals.select { |a| a[/[cbr]at/] }
end

def test_slash_d_is_a_shortcut_for_a_digit_character_class
assert_equal __, "the number is 42"[/[0123456789]+/]
assert_equal __, "the number is 42"[/\d+/]
assert_equal "42", "the number is 42"[/[0123456789]+/]
assert_equal "42", "the number is 42"[/\d+/]
end

def test_character_classes_can_include_ranges
assert_equal __, "the number is 42"[/[0-9]+/]
assert_equal "42", "the number is 42"[/[0-9]+/]
end

def test_slash_s_is_a_shortcut_for_a_whitespace_character_class
assert_equal __, "space: \t\n"[/\s+/]
assert_equal " \t\n", "space: \t\n"[/\s+/]
end

def test_slash_w_is_a_shortcut_for_a_word_character_class
Expand Down

0 comments on commit 63e82ae

Please sign in to comment.