mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-04 14:12:06 -07:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ee7f300ae2 | ||
|
a4d8db16f7 | ||
|
3bb387abdd | ||
|
7f0273c347 |
@@ -32,8 +32,8 @@ build: false
|
|||||||
# Equivalent to Travis' `script` phase
|
# Equivalent to Travis' `script` phase
|
||||||
# TODO modify this phase as you see fit
|
# TODO modify this phase as you see fit
|
||||||
test_script:
|
test_script:
|
||||||
- cargo build --verbose
|
# - cargo build --verbose
|
||||||
- cargo test
|
- cargo test matchslash2 -- --nocapture
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
# Generate artifacts for release
|
# Generate artifacts for release
|
||||||
|
18
src/glob.rs
18
src/glob.rs
@@ -214,7 +214,7 @@ impl Pattern {
|
|||||||
/// regular expression and will represent the matching semantics of this
|
/// regular expression and will represent the matching semantics of this
|
||||||
/// glob pattern and the options given.
|
/// glob pattern and the options given.
|
||||||
pub fn to_regex_with(&self, options: &MatchOptions) -> String {
|
pub fn to_regex_with(&self, options: &MatchOptions) -> String {
|
||||||
let sep = path::MAIN_SEPARATOR.to_string();
|
let sep = regex::quote(&path::MAIN_SEPARATOR.to_string());
|
||||||
let mut re = String::new();
|
let mut re = String::new();
|
||||||
re.push_str("(?-u)");
|
re.push_str("(?-u)");
|
||||||
if options.case_insensitive {
|
if options.case_insensitive {
|
||||||
@@ -235,14 +235,14 @@ impl Pattern {
|
|||||||
}
|
}
|
||||||
Token::Any => {
|
Token::Any => {
|
||||||
if options.require_literal_separator {
|
if options.require_literal_separator {
|
||||||
re.push_str(&format!("[^{}]", regex::quote(&sep)));
|
re.push_str(&format!("[^{}]", sep));
|
||||||
} else {
|
} else {
|
||||||
re.push_str(".");
|
re.push_str(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Token::ZeroOrMore => {
|
Token::ZeroOrMore => {
|
||||||
if options.require_literal_separator {
|
if options.require_literal_separator {
|
||||||
re.push_str(&format!("[^{}]*", regex::quote(&sep)));
|
re.push_str(&format!("[^{}]*", sep));
|
||||||
} else {
|
} else {
|
||||||
re.push_str(".*");
|
re.push_str(".*");
|
||||||
}
|
}
|
||||||
@@ -414,6 +414,8 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
use super::{Error, Pattern, MatchOptions, SetBuilder, Token};
|
use super::{Error, Pattern, MatchOptions, SetBuilder, Token};
|
||||||
@@ -461,8 +463,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
let pat = Pattern::new($pat).unwrap();
|
let pat = Pattern::new($pat).unwrap();
|
||||||
|
let path = &Path::new($path).to_str().unwrap();
|
||||||
let re = Regex::new(&pat.to_regex_with(&$options)).unwrap();
|
let re = Regex::new(&pat.to_regex_with(&$options)).unwrap();
|
||||||
assert!(re.is_match($path.as_bytes()));
|
assert!(re.is_match(path.as_bytes()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -475,8 +478,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn $name() {
|
fn $name() {
|
||||||
let pat = Pattern::new($pat).unwrap();
|
let pat = Pattern::new($pat).unwrap();
|
||||||
|
let path = &Path::new($path).to_str().unwrap();
|
||||||
let re = Regex::new(&pat.to_regex_with(&$options)).unwrap();
|
let re = Regex::new(&pat.to_regex_with(&$options)).unwrap();
|
||||||
assert!(!re.is_match($path.as_bytes()));
|
println!("PATTERN: {}", $pat);
|
||||||
|
println!("REGEX: {:?}", re);
|
||||||
|
println!("PATH: {}", path);
|
||||||
|
assert!(!re.is_match(path.as_bytes()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -638,6 +645,7 @@ mod tests {
|
|||||||
|
|
||||||
matches!(matchslash1, "abc/def", "abc/def", SLASHLIT);
|
matches!(matchslash1, "abc/def", "abc/def", SLASHLIT);
|
||||||
nmatches!(matchslash2, "abc?def", "abc/def", SLASHLIT);
|
nmatches!(matchslash2, "abc?def", "abc/def", SLASHLIT);
|
||||||
|
nmatches!(matchslash2_win, "abc?def", "abc\\def", SLASHLIT);
|
||||||
nmatches!(matchslash3, "abc*def", "abc/def", SLASHLIT);
|
nmatches!(matchslash3, "abc*def", "abc/def", SLASHLIT);
|
||||||
matches!(matchslash4, "abc[/]def", "abc/def", SLASHLIT); // differs
|
matches!(matchslash4, "abc[/]def", "abc/def", SLASHLIT); // differs
|
||||||
|
|
||||||
|
@@ -239,6 +239,7 @@ impl<W: Send + io::Write> Printer<W> {
|
|||||||
fn line_number(&mut self, n: u64, sep: u8) {
|
fn line_number(&mut self, n: u64, sep: u8) {
|
||||||
if self.wtr.is_color() {
|
if self.wtr.is_color() {
|
||||||
let _ = self.wtr.fg(YELLOW);
|
let _ = self.wtr.fg(YELLOW);
|
||||||
|
let _ = self.wtr.attr(term::Attr::Bold);
|
||||||
}
|
}
|
||||||
self.write(n.to_string().as_bytes());
|
self.write(n.to_string().as_bytes());
|
||||||
if self.wtr.is_color() {
|
if self.wtr.is_color() {
|
||||||
|
Reference in New Issue
Block a user