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 28, 2024
1 parent 471cf6d commit 2311daf
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/parser/test/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,59 @@ 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,
],
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 +871,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 +891,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 2311daf

Please sign in to comment.