-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6381f44
commit 3a96692
Showing
5 changed files
with
172 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
open Core | ||
|
||
open Matchers | ||
open Rewriter | ||
|
||
let configuration = Configuration.create ~match_kind:Fuzzy () | ||
|
||
let run_all ?(configuration = configuration) source match_template rewrite_template = | ||
Generic.all ~configuration ~template:match_template ~source | ||
|> function | ||
| [] -> print_string "No matches." | ||
| results -> | ||
Option.value_exn (Rewrite.all ~source ~rewrite_template results) | ||
|> (fun { rewritten_source; _ } -> rewritten_source) | ||
|> print_string | ||
|
||
let%expect_test "non_space" = | ||
let run = run_all in | ||
let source = {| foo. foo.bar.quux derp|} in | ||
let match_template = {|:[x.]|} in | ||
let rewrite_template = {|{:[x]}|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {| {foo.} {foo.bar.quux} {derp}|}] | ||
|
||
let%expect_test "only_space" = | ||
let run = run_all in | ||
let source = {| foo. foo.bar.quux derp|} in | ||
let match_template = {|:[ x]|} in | ||
let rewrite_template = {|{:[x]}|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {|{ }foo.{ }foo.bar.quux{ }derp|}] | ||
|
||
let%expect_test "up_to_newline" = | ||
let run = run_all in | ||
let source = | ||
{| | ||
foo. | ||
foo.bar.quux | ||
derp | ||
|} in | ||
let match_template = {|:[x\n]|} in | ||
let rewrite_template = {|{:[x]}|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {| | ||
{foo.} | ||
{foo.bar.quux} | ||
{derp} | ||
|}] | ||
|
||
let%expect_test "leading_indentation" = | ||
let run = run_all in | ||
let source = | ||
{| | ||
foo. bar bazz | ||
foo.bar.quux | ||
derp | ||
|} in | ||
let match_template = {|:[ leading_indentation]:[rest\n]|} in | ||
let rewrite_template = {|{:[leading_indentation]}:[rest]|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {| | ||
{ }foo. bar bazz | ||
{ }foo.bar.quux | ||
{ }derp | ||
|}] | ||
|
||
let%expect_test "non_space_partial_match" = | ||
let run = run_all in | ||
let source = {| foo. foo.bar.quux derp|} in | ||
let match_template = {|foo.:[x.]ux|} in | ||
let rewrite_template = {|{:[x]}|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {| foo. {bar.qu} derp|}] | ||
|
||
let%expect_test "alphanum_partial_match" = | ||
let run = run_all in | ||
let source = {| foo. foo.bar.quux derp|} in | ||
let match_template = {|foo.b:[x]r.quux|} in | ||
let rewrite_template = {|{:[x]}|} in | ||
run source match_template rewrite_template; | ||
[%expect_exact {| foo. {a} derp|}] |
This file was deleted.
Oops, something went wrong.