Mercurial > public > mercurial-scm > hg-stable
diff contrib/merge-lists/tests/test-merge-lists.rs @ 49076:b999edb15f8c
merge-lists: make it possible to specify pattern to match
The `merge-lists` tool doesn't know anything about Python other than
its regex that attempts to match import lines. Let's make it possible
to pass in a custom regex so it's easy to use the tool for e.g. C/C++
`#include` lines or Rust `use` lines (given the limited).
Differential Revision: https://phab.mercurial-scm.org/D12392
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 18 Mar 2022 12:23:47 -0700 |
parents | 681b25ea579e |
children |
line wrap: on
line diff
--- a/contrib/merge-lists/tests/test-merge-lists.rs Fri Mar 04 16:12:56 2022 -0800 +++ b/contrib/merge-lists/tests/test-merge-lists.rs Fri Mar 18 12:23:47 2022 -0700 @@ -1,7 +1,8 @@ use similar::DiffableStr; +use std::ffi::OsStr; use tempdir::TempDir; -fn run_test(input: &str) -> String { +fn run_test(arg: &str, input: &str) -> String { let mut cmd = assert_cmd::Command::cargo_bin("merge-lists").unwrap(); let temp_dir = TempDir::new("test").unwrap(); let base_path = temp_dir.path().join("base"); @@ -16,6 +17,7 @@ std::fs::write(&local_path, split.next().unwrap()).unwrap(); std::fs::write(&other_path, split.next().unwrap()).unwrap(); cmd.args(&[ + OsStr::new(arg), local_path.as_os_str(), base_path.as_os_str(), other_path.as_os_str(), @@ -38,6 +40,7 @@ #[test] fn test_merge_lists_basic() { let output = run_test( + "--python-imports", r" base: import lib1 @@ -72,6 +75,7 @@ // Test some "from x import y" statements and some non-import conflicts // (unresolvable) let output = run_test( + "--python-imports", r" base: from . import x @@ -116,6 +120,7 @@ // Test that nothing is done if the elements in the conflicting hunks are // not sorted let output = run_test( + "--python-imports", r" base: import x @@ -154,3 +159,46 @@ 3+3 "###); } + +#[test] +fn test_custom_regex() { + // Test merging of all lines (by matching anything) + let output = run_test( + "--pattern=.*", + r" +base: +aardvark +baboon +camel + +local: +aardvark +camel +eagle + +other: +aardvark +camel +deer +", + ); + insta::assert_snapshot!(output, @r###" + base: + aardvark + camel + deer + eagle + + local: + aardvark + camel + deer + eagle + + other: + aardvark + camel + deer + eagle + "###); +}