mirror of
https://github.com/zizmorcore/zizmor.git
synced 2025-12-23 08:47:33 +00:00
move tests
This commit is contained in:
parent
abf1e67c27
commit
bf2945ee45
3 changed files with 40 additions and 35 deletions
|
|
@ -1355,4 +1355,24 @@ mod tests {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fragment_from_expr() {
|
||||
for (expr, expected) in &[
|
||||
("foo==bar", "foo==bar"),
|
||||
("foo == bar", "foo == bar"),
|
||||
("foo == bar", r"foo == bar"),
|
||||
("foo(bar)", "foo(bar)"),
|
||||
("foo(bar, baz)", "foo(bar, baz)"),
|
||||
("foo (bar, baz)", "foo (bar, baz)"),
|
||||
("a . b . c . d", "a . b . c . d"),
|
||||
("true \n && \n false", r"true\s+\&\&\s+false"),
|
||||
] {
|
||||
let expr = Expr::parse(expr).unwrap();
|
||||
match subfeature::Fragment::from(&expr) {
|
||||
subfeature::Fragment::Raw(actual) => assert_eq!(actual, *expected),
|
||||
subfeature::Fragment::Regex(actual) => assert_eq!(actual.as_str(), *expected),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,3 +166,23 @@ impl<'a> Subfeature<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::Fragment;
|
||||
|
||||
#[test]
|
||||
fn test_fragment_from_context() {
|
||||
for (ctx, expected) in &[
|
||||
("foo.bar", "foo.bar"),
|
||||
("foo . bar", "foo . bar"),
|
||||
("foo['bar']", "foo['bar']"),
|
||||
("foo [\n'bar'\n]", r"foo\s+\[\s+'bar'\s+\]"),
|
||||
] {
|
||||
match Fragment::from(*ctx) {
|
||||
Fragment::Raw(actual) => assert_eq!(actual, *expected),
|
||||
Fragment::Regex(actual) => assert_eq!(actual.as_str(), *expected),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -454,39 +454,4 @@ mod tests {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fragment_from_expr() {
|
||||
for (expr, expected) in &[
|
||||
("foo==bar", "foo==bar"),
|
||||
("foo == bar", "foo == bar"),
|
||||
("foo == bar", r"foo == bar"),
|
||||
("foo(bar)", "foo(bar)"),
|
||||
("foo(bar, baz)", "foo(bar, baz)"),
|
||||
("foo (bar, baz)", "foo (bar, baz)"),
|
||||
("a . b . c . d", "a . b . c . d"),
|
||||
("true \n && \n false", r"true\s+\&\&\s+false"),
|
||||
] {
|
||||
let expr = Expr::parse(expr).unwrap();
|
||||
match Fragment::from(&expr) {
|
||||
Fragment::Raw(actual) => assert_eq!(actual, *expected),
|
||||
Fragment::Regex(actual) => assert_eq!(actual.as_str(), *expected),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fragment_from_context() {
|
||||
for (ctx, expected) in &[
|
||||
("foo.bar", "foo.bar"),
|
||||
("foo . bar", "foo . bar"),
|
||||
("foo['bar']", "foo['bar']"),
|
||||
("foo [\n'bar'\n]", r"foo\s+\[\s+'bar'\s+\]"),
|
||||
] {
|
||||
match Fragment::from(*ctx) {
|
||||
Fragment::Raw(actual) => assert_eq!(actual, *expected),
|
||||
Fragment::Regex(actual) => assert_eq!(actual.as_str(), *expected),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue