Skip to content

Commit

Permalink
Add test for clickhouse: tokenize == as Token::DoubleEq (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
lustefaniak authored Oct 2, 2023
1 parent e718ce6 commit 4903bd4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use crate::parser::{Parser, ParserError};
use crate::tokenizer::Tokenizer;
use crate::{ast::*, parser::ParserOptions};

#[cfg(test)]
use pretty_assertions::assert_eq;

/// Tests use the methods on this struct to invoke the parser on one or
/// multiple dialects.
pub struct TestedDialects {
Expand Down
24 changes: 23 additions & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ fn peeking_take_while(chars: &mut State, mut predicate: impl FnMut(char) -> bool
#[cfg(test)]
mod tests {
use super::*;
use crate::dialect::{GenericDialect, MsSqlDialect};
use crate::dialect::{ClickHouseDialect, GenericDialect, MsSqlDialect};

#[test]
fn tokenizer_error_impl() {
Expand Down Expand Up @@ -1414,6 +1414,28 @@ mod tests {
compare(expected, tokens);
}

#[test]
fn tokenize_clickhouse_double_equal() {
let sql = String::from("SELECT foo=='1'");
let dialect = ClickHouseDialect {};
let mut tokenizer = Tokenizer::new(&dialect, &sql);
let tokens = tokenizer.tokenize().unwrap();

let expected = vec![
Token::make_keyword("SELECT"),
Token::Whitespace(Whitespace::Space),
Token::Word(Word {
value: "foo".to_string(),
quote_style: None,
keyword: Keyword::NoKeyword,
}),
Token::DoubleEq,
Token::SingleQuotedString("1".to_string()),
];

compare(expected, tokens);
}

#[test]
fn tokenize_select_exponent() {
let sql = String::from("SELECT 1e10, 1e-10, 1e+10, 1ea, 1e-10a, 1e-10-10");
Expand Down
8 changes: 8 additions & 0 deletions tests/sqlparser_clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ fn parse_create_table() {
);
}

#[test]
fn parse_double_equal() {
clickhouse().one_statement_parses_to(
r#"SELECT foo FROM bar WHERE buz == 'buz'"#,
r#"SELECT foo FROM bar WHERE buz = 'buz'"#,
);
}

fn clickhouse() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(ClickHouseDialect {})],
Expand Down
4 changes: 2 additions & 2 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6792,10 +6792,10 @@ fn parse_time_functions() {

// Validating Parenthesis
let sql_without_parens = format!("SELECT {}", func_name);
let mut ast_without_parens = select_localtime_func_call_ast.clone();
let mut ast_without_parens = select_localtime_func_call_ast;
ast_without_parens.special = true;
assert_eq!(
&Expr::Function(ast_without_parens.clone()),
&Expr::Function(ast_without_parens),
expr_from_projection(&verified_only_select(&sql_without_parens).projection[0])
);
}
Expand Down

0 comments on commit 4903bd4

Please sign in to comment.