aharpervc commented on code in PR #1809: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1809#discussion_r2050966075
########## tests/sqlparser_mssql.rs: ########## @@ -2053,3 +2054,171 @@ fn parse_drop_trigger() { } ); } + +#[test] +fn parse_mssql_go_keyword() { + let single_go_keyword = "USE some_database;\nGO"; + let stmts = ms().parse_sql_statements(single_go_keyword).unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: None }),); + + let go_with_count = "SELECT 1;\nGO 5"; + let stmts = ms().parse_sql_statements(go_with_count).unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: Some(5) })); + + let go_statement_delimiter = "SELECT 1\nGO"; + let stmts = ms().parse_sql_statements(go_statement_delimiter).unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: None })); + + let bare_go = "GO"; + let stmts = ms().parse_sql_statements(bare_go).unwrap(); + assert_eq!(stmts.len(), 1); + assert_eq!(stmts[0], Statement::Go(GoStatement { count: None })); + + let go_then_statements = "/* whitespace */ GO\nRAISERROR('This is a test', 16, 1);"; + let stmts = ms().parse_sql_statements(go_then_statements).unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[0], Statement::Go(GoStatement { count: None })); + assert_eq!( + stmts[1], + Statement::RaisError { + message: Box::new(Expr::Value( + (Value::SingleQuotedString("This is a test".to_string())).with_empty_span() + )), + severity: Box::new(Expr::Value(number("16").with_empty_span())), + state: Box::new(Expr::Value(number("1").with_empty_span())), + arguments: vec![], + options: vec![], + } + ); + + let multiple_gos = "SELECT 1;\nGO 5\nSELECT 2;\n GO"; + let stmts = ms().parse_sql_statements(multiple_gos).unwrap(); + assert_eq!(stmts.len(), 4); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: Some(5) })); + assert_eq!(stmts[3], Statement::Go(GoStatement { count: None })); + + let single_line_comment_preceding_go = "USE some_database; -- okay\nGO"; + let stmts = ms() + .parse_sql_statements(single_line_comment_preceding_go) + .unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: None })); + + let multi_line_comment_preceding_go = "USE some_database; /* okay */\nGO"; + let stmts = ms() + .parse_sql_statements(multi_line_comment_preceding_go) + .unwrap(); + assert_eq!(stmts.len(), 2); + assert_eq!(stmts[1], Statement::Go(GoStatement { count: None })); + + let comment_following_go = "USE some_database;\nGO -- okay"; Review Comment: Done 👍 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org