Skip to content

Commit

Permalink
Apply pretty_assertions::assert_eq! to core/ ast_builder unit tests (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
panarch committed Aug 6, 2023
1 parent 89d2440 commit d316ceb
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 60 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ features = ["v4", "js"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.uuid]
version = "1"
features = ["v4"]

[dev-dependencies]
pretty_assertions = "1"
8 changes: 6 additions & 2 deletions core/src/ast_builder/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ impl<'a> TryFrom<AssignmentNode<'a>> for Assignment {

#[cfg(test)]
mod tests {
use crate::{
ast_builder::AssignmentNode, parse_sql::parse_assignment, translate::translate_assignment,
use {
crate::{
ast_builder::AssignmentNode, parse_sql::parse_assignment,
translate::translate_assignment,
},
pretty_assertions::assert_eq,
};

fn test(actual: AssignmentNode, expected: &str) {
Expand Down
1 change: 1 addition & 0 deletions core/src/ast_builder/expr_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod tests {
ast::Expr, ast_builder::col, parse_sql::parse_comma_separated_exprs, result::Result,
translate::translate_expr,
},
pretty_assertions::assert_eq,
};

fn test(actual: ExprList, expected: &str) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/ast_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn test(actual: crate::result::Result<crate::ast::Statement>, expected: &str) {

let parsed = &parse(expected).expect(expected)[0];
let expected = translate(parsed);
assert_eq!(actual, expected);
pretty_assertions::assert_eq!(actual, expected);
}

#[cfg(test)]
Expand All @@ -100,7 +100,7 @@ fn test_expr(actual: crate::ast_builder::ExprNode, expected: &str) {

let parsed = &parse_expr(expected).expect(expected);
let expected = translate_expr(parsed);
assert_eq!(actual.try_into(), expected);
pretty_assertions::assert_eq!(actual.try_into(), expected);
}

#[cfg(test)]
Expand All @@ -109,5 +109,5 @@ fn test_query(actual: crate::ast_builder::QueryNode, expected: &str) {

let parsed = &parse_query(expected).expect(expected);
let expected = translate_query(parsed);
assert_eq!(actual.try_into(), expected);
pretty_assertions::assert_eq!(actual.try_into(), expected);
}
9 changes: 6 additions & 3 deletions core/src/ast_builder/order_by_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ impl<'a> TryFrom<OrderByExprNode<'a>> for OrderByExpr {

#[cfg(test)]
mod tests {
use crate::{
ast_builder::OrderByExprNode, parse_sql::parse_order_by_expr,
translate::translate_order_by_expr,
use {
crate::{
ast_builder::OrderByExprNode, parse_sql::parse_order_by_expr,
translate::translate_order_by_expr,
},
pretty_assertions::assert_eq,
};

fn test(actual: OrderByExprNode, expected: &str) {
Expand Down
1 change: 1 addition & 0 deletions core/src/ast_builder/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ mod test {
test_query, SelectItemList,
},
},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ impl<'a> Prebuild<Select> for FilterNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
BinaryOperator, Expr, Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select,
SetExpr, Statement, TableFactor, TableWithJoins,
use {
crate::{
ast::{
BinaryOperator, Expr, Join, JoinConstraint, JoinExecutor, JoinOperator, Query,
Select, SetExpr, Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, expr, table, test, Build, SelectItemList},
},
ast_builder::{col, expr, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ impl<'a> Prebuild<Select> for GroupByNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, table, test, Build, SelectItemList},
},
ast_builder::{col, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/join/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ fn build_join_executor(

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableAlias, TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableAlias, TableFactor, TableWithJoins,
},
ast_builder::{col, expr, table, Build, SelectItemList},
},
ast_builder::{col, expr, table, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/join/join_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ impl<'a> Prebuild<Select> for JoinConstraintNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, table, test, Build, SelectItemList},
},
ast_builder::{col, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
5 changes: 4 additions & 1 deletion core/src/ast_builder/select/join/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ impl<'a> Prebuild<Select> for JoinNode<'a> {

#[cfg(test)]
mod tests {
use crate::ast_builder::{table, test, Build};
use {
crate::ast_builder::{table, test, Build},
pretty_assertions::assert_eq,
};

#[test]
fn inner_join() {
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ impl<'a> Prebuild<Query> for LimitNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, num, table, test, Build, SelectItemList},
},
ast_builder::{col, num, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ impl<'a> Prebuild<Query> for OffsetNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, num, table, test, Build, SelectItemList},
},
ast_builder::{col, num, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/order_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ impl<'a> Prebuild<Query> for OrderByNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, table, test, Build, ExprNode, OrderByExprList, SelectItemList},
},
ast_builder::{col, table, test, Build, ExprNode, OrderByExprList, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ impl<'a> Prebuild<Select> for ProjectNode<'a> {

#[cfg(test)]
mod tests {
use crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr, Statement,
TableFactor, TableWithJoins,
use {
crate::{
ast::{
Join, JoinConstraint, JoinExecutor, JoinOperator, Query, Select, SetExpr,
Statement, TableFactor, TableWithJoins,
},
ast_builder::{col, table, test, Build, SelectItemList},
},
ast_builder::{col, table, test, Build, SelectItemList},
pretty_assertions::assert_eq,
};

#[test]
Expand Down
13 changes: 8 additions & 5 deletions core/src/ast_builder/select_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ impl<'a> TryFrom<SelectItemNode<'a>> for SelectItem {

#[cfg(test)]
mod tests {
use crate::{
ast::SelectItem,
ast_builder::{col, SelectItemNode},
parse_sql::parse_select_item,
translate::translate_select_item,
use {
crate::{
ast::SelectItem,
ast_builder::{col, SelectItemNode},
parse_sql::parse_select_item,
translate::translate_select_item,
},
pretty_assertions::assert_eq,
};

fn test(actual: SelectItemNode, expected: &str) {
Expand Down
15 changes: 9 additions & 6 deletions core/src/ast_builder/select_item_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ impl<'a> TryFrom<SelectItemList<'a>> for Vec<SelectItem> {

#[cfg(test)]
mod tests {
use crate::{
ast::SelectItem,
ast_builder::{col, expr, SelectItemList},
parse_sql::parse_select_items,
result::Result,
translate::translate_select_item,
use {
crate::{
ast::SelectItem,
ast_builder::{col, expr, SelectItemList},
parse_sql::parse_select_items,
result::Result,
translate::translate_select_item,
},
pretty_assertions::assert_eq,
};

fn test(actual: SelectItemList, expected: &str) {
Expand Down

0 comments on commit d316ceb

Please sign in to comment.