Skip to content

Commit

Permalink
chore: Migrate to the new testing style for structure rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu authored and benfdking committed Aug 1, 2024
1 parent cb7b72e commit 0bdf342
Show file tree
Hide file tree
Showing 8 changed files with 806 additions and 1,061 deletions.
89 changes: 0 additions & 89 deletions crates/lib/src/rules/structure/ST01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,92 +85,3 @@ FROM foo
SegmentSeekerCrawler::new(const { SyntaxSet::new(&[SyntaxKind::CaseExpression]) }).into()
}
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;

use crate::api::simple::fix;
use crate::core::rules::base::{Erased, ErasedRule};
use crate::rules::structure::ST01::RuleST01;

fn rules() -> Vec<ErasedRule> {
vec![RuleST01.erased()]
}

#[test]
fn redundant_else_null() {
let fail_str = "
select
case name
when 'cat' then 'meow'
when 'dog' then 'woof'
else null
end
from x";

let fix_str = "
select
case name
when 'cat' then 'meow'
when 'dog' then 'woof'
end
from x";

let fixed = fix(fail_str, rules());
assert_eq!(fix_str, fixed);
}

#[test]
fn alternate_case_when_syntax() {
let fail_str = "
select
case name
when 'cat' then 'meow'
when 'dog' then 'woof'
else null
end
from x";

let fix_str = "
select
case name
when 'cat' then 'meow'
when 'dog' then 'woof'
end
from x";

let fixed = fix(fail_str, rules());
assert_eq!(fix_str, fixed);
}

#[test]
fn alternate_case_when_syntax_boolean() {
let pass_str = "
select
case name
when 'cat' then true
when 'dog' then true
else name is null
end
from x";

let fixed = fix(pass_str, rules());
assert_eq!(pass_str, fixed);
}

#[test]
fn else_expression() {
let pass_str = "
select
case name
when 'cat' then 'meow'
when 'dog' then 'woof'
else iff(wing_type is not null, 'tweet', 'invalid')
end
from x";

let fixed = fix(pass_str, rules());
assert_eq!(pass_str, fixed);
}
}
Loading

0 comments on commit 0bdf342

Please sign in to comment.