diff --git a/src/parser/test/ddl.rs b/src/parser/test/ddl.rs index 3aa9862..e593381 100644 --- a/src/parser/test/ddl.rs +++ b/src/parser/test/ddl.rs @@ -740,3 +740,56 @@ fn test_handle_alter_table_query() { } } } + +#[test] +fn test_handle_drop_table_query() { + struct TestCase { + name: String, + input: Vec, + expected: SQLStatement, + want_error: bool, + } + + let test_cases = vec![ + TestCase { + name: "DROP TABLE foo".into(), + input: vec![Token::Identifier("foo".to_owned())], + expected: DropTableQuery::builder() + .set_table(TableName::new(None, "foo".to_owned())) + .build() + .into(), + want_error: false, + }, + TestCase { + name: "오류: DROP TABLE foo DROP".into(), + input: vec![Token::Identifier("foo".to_owned()), Token::Drop], + expected: Default::default(), + want_error: true, + }, + 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.handle_drop_table_query(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.into(), "TC: {}", t.name); + } + } +}