Skip to content

Commit

Permalink
[#142] parse_group_by_item 테스트코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Jul 29, 2024
1 parent 907a876 commit daed7a6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ast/dml/parts/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct GroupByClause {
pub group_by_items: Vec<GroupByItem>,
}

#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct GroupByItem {
pub item: SelectColumn,
}
2 changes: 1 addition & 1 deletion src/ast/types/select_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

// [table_alias.]column_name
// SELECT시 컬럼 지정을 가리키는 값입니다.
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct SelectColumn {
pub table_name: Option<String>,
pub column_name: String,
Expand Down
50 changes: 50 additions & 0 deletions src/parser/test/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,3 +1996,53 @@ fn test_parse_order_by_item() {
}
}
}

#[test]
fn test_parse_group_by_item() {
struct TestCase {
name: String,
input: Vec<Token>,
expected: GroupByItem,
want_error: bool,
}

let test_cases = vec![
TestCase {
name: "p.id".into(),
input: vec![
Token::Identifier("p".into()),
Token::Period,
Token::Identifier("id".into()),
],
expected: GroupByItem {
item: SelectColumn::new(Some("p".into()), "id".into()),
},
want_error: false,
},
TestCase {
name: "실패: 빈 토큰".into(),
input: vec![],
expected: Default::default(),
want_error: true,
},
];

for t in test_cases {
let mut parser = Parser::new(t.input);

let got = parser.parse_group_by_item(Default::default());

assert_eq!(
got.is_err(),
t.want_error,
"{}: want_error: {}, error: {:?}",
t.name,
t.want_error,
got.err()
);

if let Ok(statements) = got {
assert_eq!(statements, t.expected, "TC: {}", t.name);
}
}
}

0 comments on commit daed7a6

Please sign in to comment.