diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Regex/Engine/Default.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Regex/Engine/Default.enso index 5aa71d5a15383..a4efbc93e7fae 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Regex/Engine/Default.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Regex/Engine/Default.enso @@ -559,11 +559,8 @@ type Pattern internal_matcher = this.build_matcher input start end internal_matcher.replaceAll replacement Mode.Full -> - ## TODO this is inconsistent with other modes - will not allow - capture group references in replacement. It should be revised - with: https://www.pivotaltracker.com/story/show/181524498 case this.match input mode=Mode.Full of - Match _ _ _ _ -> replacement + Match _ _ _ _ -> this.replace input replacement Mode.First Nothing -> input Matching_Mode.Last -> all_matches = this.match input diff --git a/test/Tests/src/Data/Text/Default_Regex_Engine_Spec.enso b/test/Tests/src/Data/Text/Default_Regex_Engine_Spec.enso index f7dbfc54b71b4..bed293507d40b 100644 --- a/test/Tests/src/Data/Text/Default_Regex_Engine_Spec.enso +++ b/test/Tests/src/Data/Text/Default_Regex_Engine_Spec.enso @@ -400,6 +400,11 @@ spec = match = pattern.replace input "REPLACED" mode=Mode.Full match . should_equal "REPLACED" + Test.specify "should correctly replace entire input in Full mode even if partial matches are possible" <| + pattern = engine.compile "(aa)+" [] + pattern.replace "aaa" "REPLACED" mode=Mode.Full . should_equal "aaa" + pattern.replace "aaaa" "REPLACED" mode=Mode.Full . should_equal "REPLACED" + Test.specify "should return the input for a full replace if the pattern doesn't match the entire input" <| pattern = engine.compile "(..)" [] input = "aa ab" @@ -438,9 +443,7 @@ spec = pattern.replace "foo bar, baz" "[${capture}]" mode=Mode.First . should_equal "[foo] bar, baz" pattern.replace "foo bar, baz" "[${capture}]" mode=Matching_Mode.Last . should_equal "foo bar, [baz]" - ## TODO this should be revised with: - https://www.pivotaltracker.com/story/show/181524498 - Test.specify "should handle capture groups in replacement in All mode" pending="Regex needs revision." <| + Test.specify "should handle capture groups in replacement in All mode" <| pattern = engine.compile "([a-z]+)" [] pattern.replace "foo bar, baz" "[$1]" mode=Mode.Full . should_equal "foo bar, baz" pattern.replace "foo" "[$1]" mode=Mode.Full . should_equal "[foo]"