Ad
  • Custom User Avatar

    I close the issue because I posted the solution and did not wait for feedback for several weeks.

  • Custom User Avatar

    I close the issue because I posted the solution and did not wait for feedback for several weeks.

  • Custom User Avatar

    I close the issue because I posted the solution and did not wait for feedback for several weeks.

  • Custom User Avatar

    What is the status of this issue?

  • Custom User Avatar

    What is the status of this issue?

  • Custom User Avatar

    @voile

    Invalid regex handling is not specified, e.g ?invalid, *invalid and +invalid. They don't even satisfy the grammar provided by the kata description, and still expects some matches, so what is expected?

    OK, now expressions like /?invalid/, /*invalid/ and /+invalid/ invalid and must raise error.
    I've changed description.

  • Custom User Avatar

    Changed to:

    "[0-9]{3} USD"

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    Why?

    (abc)+ expects ["abc", "abcabc", "abcabcabc"]

    a+ expects ["a", "aa", "aaa"]

    Am I right?
    Why is it wrong with numbers?

  • Custom User Avatar

    Changed to:

    • generator must have #each method which return Enumerator of strings (order doesn't matter)
  • Custom User Avatar
  • Custom User Avatar

    /(?<word>[a-z]+)|(?<number>\d+)/

    Alternation are only supported within a group!

    Notably, groups aren't dropped from the result just because they don't participate in the match, but the kata expects them to be dropped, which screws over whoever using these groups, as now the index of the group can change.

    I've added tests for this cases.

            describe "named groups" do
              describe "names and alternation" do
                include_examples "#scan", "signed", {
                  regexps: [
                    "(?<word>[a-z]+)",
                    "(?<number>\\d+)",
                    "((?<word>[a-z]+)|(?<number>\\d+))"
                  ],
                  cases: {
                    "abc 123" => {
                      "(?<word>[a-z]+)" => [["abc", 0..2, [], {"word"=>0..2}]],
                      "(?<number>\\d+)" => [["123", 4..6, [], {"number"=>4..6}]],
                      "((?<word>[a-z]+)|(?<number>\\d+))" => [
                        ["abc", 0..2, [0..2], {"word"=>0..2}],
                        ["123", 4..6, [4..6], {"number"=>4..6}]
                      ],
                    }
                  }
                }
              end
    
              describe "nested groups" do
                include_examples "#scan", "signed", {
                  regexps: [
                    "(\\d+)([a-z]+(\\d+))?",
                    "(?<first>\\d+)(?<second>[a-z]+(?<third>\\d+))?",
                  ],
                  cases: {
                    "1 1b 1bc2" => {
                      "(?<first>\\d+)(?<second>[a-z]+(?<third>\\d+))?" => [
                        ["1", 0..0, [], {"first"=>0..0}],
                        ["1", 2..2, [], {"first"=>2..2}],
                        ["1bc2", 5..8, [], {"first"=>5..5, "second"=>6..8, "third"=>8..8}]
                      ],
                      "(\\d+)([a-z]+(\\d+))?" => [
                        ["1", 0..0, [0..0], {}],
                        ["1", 2..2, [2..2], {}],
                        ["1bc2", 5..8, [5..5, 6..8, 8..8], {}]
                      ],
                    }
                  }
                }
              end
            end
    

    For expression (\d+)([a-z]+(\d+))? expected groups with overlapsed ranges - [5..5, 6..8, 8..8].
    For named groups with alternations expected hash - {"first"=>5..5, "second"=>6..8, "third"=>8..8}

  • Custom User Avatar

    The order of the results returned by scan isn't specified.

    I've added this line to description

    the order of the matches doesn't matter as long as they don't violate the principles described below

  • Custom User Avatar

    Yes, agree.
    I've fixed solution and test cases.

  • Loading more items...