Skip to content

Commit

Permalink
test: add tests for negate patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Feb 3, 2024
1 parent 5577e31 commit beeb76f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/utils/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,49 @@ fn parse_negate(pattern: String, enable_negate: bool) -> (String, bool) {
}
(pattern[counts..].to_string(), negate)
}

#[cfg(test)]
mod tests {
#[test]
fn test_parse_negate() {
use super::*;
struct TestCase {
input: (String, bool),
expected: (String, bool),
}

[
TestCase {
input: (String::from("foo"), true),
expected: (String::from("foo"), false),
},
TestCase {
input: (String::from("!foo"), true),
expected: (String::from("foo"), true),
},
TestCase {
input: (String::from("!!foo"), true),
expected: (String::from("foo"), false),
},
TestCase {
input: (String::from("!!!foo"), true),
expected: (String::from("foo"), true),
},
TestCase {
input: (String::from("foo!bar"), true),
expected: (String::from("foo!bar"), false),
},
TestCase {
input: (String::from("foo!!!!!!!!!!bar"), true),
expected: (String::from("foo!!!!!!!!!!bar"), false),
},
]
.iter()
.for_each(|case| {
assert_eq!(
parse_negate(case.input.0.clone(), case.input.1),
case.expected
);
});
}
}

0 comments on commit beeb76f

Please sign in to comment.