Skip to content

Commit

Permalink
[#142] order by 절 테스트코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Jul 29, 2024
1 parent 471cf6d commit c871b1b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ bytes = "1.2.1"
tokio-util = { version = "0.7.4", features = [ "codec" ] }
futures = "0.3.23"
chrono = "0.4.22"
bson = "2.4.0"
bson = "2.11.0"
time = "0.3.36"
colored = "2.0.0"
uuid = "1.1.2"
itertools = "0.10.5"
Expand Down
78 changes: 78 additions & 0 deletions src/parser/test/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,60 @@ fn test_select_query() {
.build(),
want_error: false,
},
TestCase {
name: r#"
SELECT
p.content as post
FROM post as p
ORDER BY p.user_id ASC;
"#
.into(),
input: vec![
Token::Select,
Token::Identifier("p".into()),
Token::Period,
Token::Identifier("content".into()),
Token::As,
Token::Identifier("post".into()),
Token::From,
Token::Identifier("post".into()),
Token::As,
Token::Identifier("p".into()),
Token::Order,
Token::By,
Token::Identifier("p".into()),
Token::Period,
Token::Identifier("user_id".into()),
Token::Asc,
Token::SemiColon,
],
expected: SelectQuery::builder()
.add_select_item(
SelectItem::builder()
.set_item(SelectColumn::new(Some("p".into()), "content".into()).into())
.set_alias("post".into())
.build(),
)
.set_from_table(TableName {
database_name: None,
table_name: "post".into(),
})
.set_from_alias("p".into())
.add_order_by(OrderByItem {
item: SelectColumn::new(Some("p".into()), "user_id".into()).into(),
order_type: OrderByType::Asc,
nulls: OrderByNulls::First,
})
.build(),
want_error: false,
},
TestCase {
name: r#"
SELECT
p.content as post
FROM post as p
ORDER BY p.user_id ASC
LIMIT 10;
"#
.into(),
input: vec![
Expand All @@ -824,6 +872,8 @@ fn test_select_query() {
Token::Period,
Token::Identifier("user_id".into()),
Token::Asc,
Token::Limit,
Token::Integer(10),
],
expected: SelectQuery::builder()
.add_select_item(
Expand All @@ -842,9 +892,37 @@ fn test_select_query() {
order_type: OrderByType::Asc,
nulls: OrderByNulls::First,
})
.set_limit(10)
.build(),
want_error: false,
},
TestCase {
name: r#"
SELECT
p.content as post
FROM post as p
ORDER BY SELECT ASC;
"#
.into(),
input: vec![
Token::Select,
Token::Identifier("p".into()),
Token::Period,
Token::Identifier("content".into()),
Token::As,
Token::Identifier("post".into()),
Token::From,
Token::Identifier("post".into()),
Token::As,
Token::Identifier("p".into()),
Token::Order,
Token::By,
Token::Select,
Token::Asc,
],
expected: Default::default(),
want_error: true,
},
TestCase {
name: r#"
SELECT
Expand Down

0 comments on commit c871b1b

Please sign in to comment.