Skip to content

Commit

Permalink
clickhouse: tokenize == as Token::DoubleEq
Browse files Browse the repository at this point in the history
  • Loading branch information
lustefaniak committed Sep 24, 2023
1 parent 7723ea5 commit 340dbaf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ use crate::parser::{Parser, ParserError};
use crate::tokenizer::Tokenizer;

Check failure on line 31 in src/test_utils.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/test_utils.rs
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)]

Check failure on line 1368 in src/tokenizer.rs

View workflow job for this annotation

GitHub Actions / codestyle

Diff in /home/runner/work/sqlparser-rs/sqlparser-rs/src/tokenizer.rs
mod tests {
use super::*;
use crate::dialect::{GenericDialect, MsSqlDialect};
use crate::dialect::{GenericDialect, MsSqlDialect, ClickHouseDialect};

#[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

0 comments on commit 340dbaf

Please sign in to comment.