Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xxhZs committed Jun 14, 2024
1 parent 2a1d9bf commit 5dd77bf
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions src/sqlparser/tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,17 +2688,23 @@ fn parse_ctes() {

fn assert_ctes_in_select(expected: &[&str], sel: &Query) {
for (i, exp) in expected.iter().enumerate() {
let Cte { alias, query, .. } = &sel.with.as_ref().unwrap().cte_tables[i];
assert_eq!(*exp, query.as_ref().unwrap().to_string());
assert_eq!(
if i == 0 {
Ident::new_unchecked("a")
} else {
Ident::new_unchecked("b")
},
alias.name
);
assert!(alias.columns.is_empty());
let Cte {
alias, cte_inner, ..
} = &sel.with.as_ref().unwrap().cte_tables[i];
if let CteInner::Query(query) = cte_inner {
assert_eq!(*exp, query.to_string());
assert_eq!(
if i == 0 {
Ident::new_unchecked("a")
} else {
Ident::new_unchecked("b")
},
alias.name
);
assert!(alias.columns.is_empty());
} else {
panic!("expected CteInner::Query")
}
}
}

Expand Down Expand Up @@ -2731,13 +2737,11 @@ fn parse_ctes() {
// CTE in a CTE...
let sql = &format!("WITH outer_cte AS ({}) SELECT * FROM outer_cte", with);
let select = verified_query(sql);
assert_ctes_in_select(
&cte_sqls,
only(&select.with.unwrap().cte_tables)
.query
.as_ref()
.unwrap(),
);
if let CteInner::Query(query) = &only(&select.with.unwrap().cte_tables).cte_inner {
assert_ctes_in_select(&cte_sqls, query);
} else {
panic!("expected CteInner::Query")
}
}

#[test]
Expand All @@ -2750,18 +2754,21 @@ fn parse_change_log_ctes() {

fn assert_change_log_ctes(expected: &[&str], sel: &Query) {
for (i, exp) in expected.iter().enumerate() {
let Cte { alias, query, from } = &sel.with.as_ref().unwrap().cte_tables[i];
assert!(query.is_none());
assert_eq!(*exp, from.as_ref().unwrap().to_string());
assert_eq!(
if i == 0 {
Ident::new_unchecked("a")
} else {
Ident::new_unchecked("b")
},
alias.name
);
assert!(alias.columns.is_empty());
let Cte { alias, cte_inner } = &sel.with.as_ref().unwrap().cte_tables[i];
if let CteInner::ChangeLog(from) = cte_inner {
assert_eq!(*exp, from.to_string());
assert_eq!(
if i == 0 {
Ident::new_unchecked("a")
} else {
Ident::new_unchecked("b")
},
alias.name
);
assert!(alias.columns.is_empty());
} else {
panic!("expected CteInner::ChangeLog")
}
}
}

Expand Down Expand Up @@ -2794,13 +2801,11 @@ fn parse_change_log_ctes() {
// CTE in a CTE...
let sql = &format!("WITH outer_cte AS ({}) SELECT * FROM outer_cte", with);
let select = verified_query(sql);
assert_change_log_ctes(
&cte_sqls,
only(&select.with.unwrap().cte_tables)
.query
.as_ref()
.unwrap(),
);
if let CteInner::Query(query) = &only(&select.with.unwrap().cte_tables).cte_inner {
assert_change_log_ctes(&cte_sqls, query);
} else {
panic!("expected CteInner::Query")
}
}

#[test]
Expand Down Expand Up @@ -2854,8 +2859,7 @@ fn parse_recursive_cte() {
name: Ident::new_unchecked("nums"),
columns: vec![Ident::new_unchecked("val")],
},
query: Some(cte_query),
from: None,
cte_inner: CteInner::Query(cte_query),
};
assert_eq!(with.cte_tables.first().unwrap(), &expected);
}
Expand Down

0 comments on commit 5dd77bf

Please sign in to comment.