move tests

This commit is contained in:
William Woodruff 2025-07-16 21:50:45 -04:00
parent abf1e67c27
commit bf2945ee45
No known key found for this signature in database
3 changed files with 40 additions and 35 deletions

View file

@ -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),
};
}
}
}

View file

@ -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),
}
}
}
}

View file

@ -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),
}
}
}
}