Skip to content

Commit

Permalink
[#145] parse_insert_columns 테스트코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Jul 31, 2024
1 parent 7eb0f50 commit 5516e1e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/parser/test/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,62 @@ fn test_insert_query() {
}
}
}

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

let test_cases = vec![
TestCase {
name: "a, b, c)".into(),
input: vec![
Token::Identifier("a".into()),
Token::Comma,
Token::Identifier("b".into()),
Token::Comma,
Token::Identifier("c".into()),
Token::RightParentheses,
],
expected: vec!["a".into(), "b".into(), "c".into()],
want_error: false,
},
TestCase {
name: "a, b, SELECT)".into(),
input: vec![
Token::Identifier("a".into()),
Token::Comma,
Token::Identifier("b".into()),
Token::Comma,
Token::Select,
Token::RightParentheses,
],
expected: vec![],
want_error: true,
},

];

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

let got = parser.parse_insert_columns(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 5516e1e

Please sign in to comment.