mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-17 20:50:16 +00:00
Add test for clickhouse: tokenize ==
as Token::DoubleEq (#981)
This commit is contained in:
parent
e718ce6c42
commit
4903bd4b8b
4 changed files with 36 additions and 3 deletions
|
@ -31,6 +31,9 @@ use crate::parser::{Parser, ParserError};
|
||||||
use crate::tokenizer::Tokenizer;
|
use crate::tokenizer::Tokenizer;
|
||||||
use crate::{ast::*, parser::ParserOptions};
|
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
|
/// Tests use the methods on this struct to invoke the parser on one or
|
||||||
/// multiple dialects.
|
/// multiple dialects.
|
||||||
pub struct TestedDialects {
|
pub struct TestedDialects {
|
||||||
|
|
|
@ -1368,7 +1368,7 @@ fn peeking_take_while(chars: &mut State, mut predicate: impl FnMut(char) -> bool
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::dialect::{GenericDialect, MsSqlDialect};
|
use crate::dialect::{ClickHouseDialect, GenericDialect, MsSqlDialect};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tokenizer_error_impl() {
|
fn tokenizer_error_impl() {
|
||||||
|
@ -1414,6 +1414,28 @@ mod tests {
|
||||||
compare(expected, tokens);
|
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]
|
#[test]
|
||||||
fn tokenize_select_exponent() {
|
fn tokenize_select_exponent() {
|
||||||
let sql = String::from("SELECT 1e10, 1e-10, 1e+10, 1ea, 1e-10a, 1e-10-10");
|
let sql = String::from("SELECT 1e10, 1e-10, 1e+10, 1ea, 1e-10a, 1e-10-10");
|
||||||
|
|
|
@ -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 {
|
fn clickhouse() -> TestedDialects {
|
||||||
TestedDialects {
|
TestedDialects {
|
||||||
dialects: vec![Box::new(ClickHouseDialect {})],
|
dialects: vec![Box::new(ClickHouseDialect {})],
|
||||||
|
|
|
@ -6792,10 +6792,10 @@ fn parse_time_functions() {
|
||||||
|
|
||||||
// Validating Parenthesis
|
// Validating Parenthesis
|
||||||
let sql_without_parens = format!("SELECT {}", func_name);
|
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;
|
ast_without_parens.special = true;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&Expr::Function(ast_without_parens.clone()),
|
&Expr::Function(ast_without_parens),
|
||||||
expr_from_projection(&verified_only_select(&sql_without_parens).projection[0])
|
expr_from_projection(&verified_only_select(&sql_without_parens).projection[0])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue