multiline.rs
This file
Path
tests/multiline.rs
121 lines · 3.9 KiB · Rust
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 5f5da48 point at it.
globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 1–121why, one step back1use crate::hay::SHERLOCK;2use crate::util::{Dir, TestCommand};34// This tests that multiline matches that span multiple lines, but where5// multiple matches may begin and end on the same line work correctly.6rgtest!(overlap1, |dir: Dir, mut cmd: TestCommand| {7 dir.create("test", "xxx\nabc\ndefxxxabc\ndefxxx\nxxx");8 cmd.arg("-n").arg("-U").arg("abc\ndef").arg("test");9 eqnice!("2:abc\n3:defxxxabc\n4:defxxx\n", cmd.stdout());10});1112// Like overlap1, but tests the case where one match ends at precisely the same13// location at which the next match begins.14rgtest!(overlap2, |dir: Dir, mut cmd: TestCommand| {15 dir.create("test", "xxx\nabc\ndefabc\ndefxxx\nxxx");16 cmd.arg("-n").arg("-U").arg("abc\ndef").arg("test");17 eqnice!("2:abc\n3:defabc\n4:defxxx\n", cmd.stdout());18});1920// Tests that even in a multiline search, a '.' does not match a newline.21rgtest!(dot_no_newline, |dir: Dir, mut cmd: TestCommand| {22 dir.create("sherlock", SHERLOCK);23 cmd.args(&["-n", "-U", "of this world.+detective work", "sherlock"]);24 cmd.assert_err();25});2627// Tests that the --multiline-dotall flag causes '.' to match a newline.28rgtest!(dot_all, |dir: Dir, mut cmd: TestCommand| {29 dir.create("sherlock", SHERLOCK);30 cmd.args(&[31 "-n",32 "-U",33 "--multiline-dotall",34 "of this world.+detective work",35 "sherlock",36 ]);3738 let expected = "\391:For the Doctor Watsons of this world, as opposed to the Sherlock402:Holmeses, success in the province of detective work must always41";42 eqnice!(expected, cmd.stdout());43});4445// Tests that --only-matching works in multiline mode.46rgtest!(only_matching, |dir: Dir, mut cmd: TestCommand| {47 dir.create("sherlock", SHERLOCK);48 cmd.args(&[49 "-n",50 "-U",51 "--only-matching",52 r"Watson|Sherlock\p{Any}+?Holmes",53 "sherlock",54 ]);5556 let expected = "\571:Watson581:Sherlock592:Holmes603:Sherlock Holmes615:Watson62";63 eqnice!(expected, cmd.stdout());64});6566// Tests that --vimgrep works in multiline mode.67//68// In particular, we test that only the first line of each match is printed,69// even when a match spans multiple lines.70//71// See: https://github.com/BurntSushi/ripgrep/issues/186672rgtest!(vimgrep, |dir: Dir, mut cmd: TestCommand| {73 dir.create("sherlock", SHERLOCK);74 cmd.args(&[75 "-n",76 "-U",77 "--vimgrep",78 r"Watson|Sherlock\p{Any}+?Holmes",79 "sherlock",80 ]);8182 let expected = "\83sherlock:1:16:For the Doctor Watsons of this world, as opposed to the Sherlock84sherlock:1:57:For the Doctor Watsons of this world, as opposed to the Sherlock85sherlock:3:49:be, to a very large extent, the result of luck. Sherlock Holmes86sherlock:5:12:but Doctor Watson has to have it taken out for him and dusted,87";88 eqnice!(expected, cmd.stdout());89});9091// Tests that multiline search works when reading from stdin. This is an92// important test because multiline search must read the entire contents of93// what it is searching into memory before executing the search.94rgtest!(stdin, |_: Dir, mut cmd: TestCommand| {95 cmd.args(&["-n", "-U", r"of this world\p{Any}+?detective work"]);96 let expected = "\971:For the Doctor Watsons of this world, as opposed to the Sherlock982:Holmeses, success in the province of detective work must always99";100 eqnice!(expected, cmd.pipe(SHERLOCK.as_bytes()));101});102103// Test that multiline search and contextual matches work.104rgtest!(context, |dir: Dir, mut cmd: TestCommand| {105 dir.create("sherlock", SHERLOCK);106 cmd.args(&[107 "-n",108 "-U",109 "-C1",110 r"detective work\p{Any}+?result of luck",111 "sherlock",112 ]);113114 let expected = "\1151-For the Doctor Watsons of this world, as opposed to the Sherlock1162:Holmeses, success in the province of detective work must always1173:be, to a very large extent, the result of luck. Sherlock Holmes1184-can extract a clew from a wisp of straw or a flake of cigar ash;119";120 eqnice!(expected, cmd.stdout());121});