Compare commits

..

7 Commits

Author SHA1 Message Date
Andrew Gallant
0891b4a3c0 update appveyor 2016-09-05 22:01:53 -04:00
Andrew Gallant
af48aaa647 another try 2016-09-05 21:57:57 -04:00
Andrew Gallant
ee7f300ae2 windows debug, take 1 2016-09-05 21:46:11 -04:00
Andrew Gallant
a4d8db16f7 Fix glob tests.
When matching directly with a regex, we need to make sure the path is
normalized first.
2016-09-05 21:36:19 -04:00
Andrew Gallant
3bb387abdd Fix glob problem on Windows.
We weren't actually escaping every use of the file path separator. D'oh.
2016-09-05 21:20:19 -04:00
Andrew Gallant
7f0273c347 Fix yellow color to match ack. 2016-09-05 21:19:56 -04:00
Andrew Gallant
5b42999a3d windows, take 3 2016-09-05 21:02:08 -04:00
4 changed files with 24 additions and 17 deletions

View File

@@ -32,14 +32,13 @@ build: false
# Equivalent to Travis' `script` phase
# TODO modify this phase as you see fit
test_script:
- cargo build --verbose
- cargo test
- cargo test --verbose
before_deploy:
# Generate artifacts for release
- RUSTFLAGS="-C target-feature=+ssse3" cargo build --release --features simd-accel
# TODO(burntsushi): How can we enable SSSE3 on Windows?
- cargo build --release
- mkdir staging
# TODO update this part to copy the artifacts that make sense for your project
- copy target\release\xrep.exe staging
- cd staging
# release zipfile will look like 'rust-everywhere-v1.2.3-x86_64-pc-windows-msvc'

View File

@@ -29,7 +29,6 @@ to make its way into `glob` proper.
use std::error::Error as StdError;
use std::fmt;
use std::iter;
use std::path;
use std::str;
use regex;
@@ -214,7 +213,7 @@ impl Pattern {
/// regular expression and will represent the matching semantics of this
/// glob pattern and the options given.
pub fn to_regex_with(&self, options: &MatchOptions) -> String {
let sep = path::MAIN_SEPARATOR.to_string();
let seps = regex::quote(r"/\");
let mut re = String::new();
re.push_str("(?-u)");
if options.case_insensitive {
@@ -235,26 +234,27 @@ impl Pattern {
}
Token::Any => {
if options.require_literal_separator {
re.push_str(&format!("[^{}]", regex::quote(&sep)));
re.push_str(&format!("[^{}]", seps));
} else {
re.push_str(".");
}
}
Token::ZeroOrMore => {
if options.require_literal_separator {
re.push_str(&format!("[^{}]*", regex::quote(&sep)));
re.push_str(&format!("[^{}]*", seps));
} else {
re.push_str(".*");
}
}
Token::RecursivePrefix => {
re.push_str(&format!("(?:{sep}?|.*{sep})", sep=sep));
re.push_str(&format!("(?:[{sep}]?|.*[{sep}])", sep=seps));
}
Token::RecursiveSuffix => {
re.push_str(&format!("(?:{sep}?|{sep}.*)", sep=sep));
re.push_str(&format!("(?:[{sep}]?|[{sep}].*)", sep=seps));
}
Token::RecursiveZeroOrMore => {
re.push_str(&format!("(?:{sep}|{sep}.*{sep})", sep=sep));
re.push_str(&format!("(?:[{sep}]|[{sep}].*[{sep}])",
sep=seps));
}
Token::Class { negated, ref ranges } => {
re.push('[');
@@ -414,6 +414,8 @@ impl<'a> Parser<'a> {
#[cfg(test)]
mod tests {
use std::path::Path;
use regex::bytes::Regex;
use super::{Error, Pattern, MatchOptions, SetBuilder, Token};
@@ -461,8 +463,9 @@ mod tests {
#[test]
fn $name() {
let pat = Pattern::new($pat).unwrap();
let path = &Path::new($path).to_str().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]
fn $name() {
let pat = Pattern::new($pat).unwrap();
let path = &Path::new($path).to_str().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()));
}
};
}
@@ -557,12 +564,11 @@ mod tests {
case_insensitive: true,
require_literal_separator: false,
};
const SEP: char = ::std::path::MAIN_SEPARATOR;
toregex!(re_casei, "a", "(?i)^a$", &CASEI);
toregex!(re_slash1, "?", format!("^[^{}]$", SEP), SLASHLIT);
toregex!(re_slash2, "*", format!("^[^{}]*$", SEP), SLASHLIT);
toregex!(re_slash1, "?", r"^[^/\\]$", SLASHLIT);
toregex!(re_slash2, "*", r"^[^/\\]*$", SLASHLIT);
toregex!(re1, "a", "^a$");
toregex!(re2, "?", "^.$");
@@ -638,6 +644,7 @@ mod tests {
matches!(matchslash1, "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);
matches!(matchslash4, "abc[/]def", "abc/def", SLASHLIT); // differs

View File

@@ -239,6 +239,7 @@ impl<W: Send + io::Write> Printer<W> {
fn line_number(&mut self, n: u64, sep: u8) {
if self.wtr.is_color() {
let _ = self.wtr.fg(YELLOW);
let _ = self.wtr.attr(term::Attr::Bold);
}
self.write(n.to_string().as_bytes());
if self.wtr.is_color() {

View File

@@ -37,6 +37,6 @@ pub fn stdout_is_atty() -> bool {
unsafe {
let fd = winapi::winbase::STD_OUTPUT_HANDLE;
let mut out = 0;
kernel32::GetConsoleMode(handle, &mut out) != 0
kernel32::GetConsoleMode(kernel32::GetStdHandle(fd), &mut out) != 0
}
}