Add full lex test for a create query

next
Sayan Nandan 2 years ago
parent 1d0f98ee8e
commit b716365c96
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -62,12 +62,25 @@ impl From<RawSlice> for Token {
}
}
#[cfg(test)]
impl From<&'static str> for Token {
fn from(sl: &'static str) -> Self {
Self::Identifier(sl.into())
}
}
impl From<u64> for Token {
fn from(num: u64) -> Self {
Self::Number(num)
}
}
impl From<Type> for Token {
fn from(ty: Type) -> Self {
Self::Keyword(Keyword::Type(ty))
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
#[repr(u8)]
/// BlueQL keywords

@ -24,38 +24,41 @@
*
*/
// lexer tests
use super::{
ast::{Compiler, FieldConfig, Statement},
lexer::{Keyword, Lexer, Token, Type, TypeExpression},
};
#[test]
fn lex_ident() {
mod lexer {
//! Lexer tests
use super::*;
#[test]
fn lex_ident() {
let src = b"mytbl";
assert_eq!(
Lexer::lex(src).unwrap(),
vec![Token::Identifier("mytbl".into())]
)
}
}
#[test]
fn lex_keyword() {
#[test]
fn lex_keyword() {
let src = b"create";
assert_eq!(
Lexer::lex(src).unwrap(),
vec![Token::Keyword(Keyword::Create)]
)
}
}
#[test]
fn lex_number() {
#[test]
fn lex_number() {
let src = b"123456";
assert_eq!(Lexer::lex(src).unwrap(), vec![Token::Number(123456)])
}
}
#[test]
fn lex_full() {
#[test]
fn lex_full() {
let src = b"create model tweet";
assert_eq!(
Lexer::lex(src).unwrap(),
@ -65,12 +68,43 @@ fn lex_full() {
Token::Identifier("tweet".into())
]
);
}
}
// AST tests
#[test]
fn lex_combined_tokens() {
let src = b"create model tweet(name: string, pic: binary, posts: list<string>)";
assert_eq!(
Lexer::lex(src).unwrap(),
vec![
Keyword::Create.into(),
Keyword::Model.into(),
"tweet".into(),
Token::OpenParen,
Token::Identifier("name".into()),
Token::Colon,
Type::String.into(),
Token::Comma,
Token::Identifier("pic".into()),
Token::Colon,
Type::Binary.into(),
Token::Comma,
Token::Identifier("posts".into()),
Token::Colon,
Type::List.into(),
Token::OpenAngular,
Type::String.into(),
Token::CloseAngular,
Token::CloseParen
]
);
}
}
#[cfg(test)]
fn setup_src_stmt() -> (Vec<u8>, Statement) {
mod ast {
//! AST tests
use super::*;
#[cfg(test)]
fn setup_src_stmt() -> (Vec<u8>, Statement) {
let src =
b"create model tweet(username: string, password: binary, posts: list<string>)".to_vec();
let stmt = Statement::CreateModel {
@ -85,9 +119,10 @@ fn setup_src_stmt() -> (Vec<u8>, Statement) {
},
};
(src, stmt)
}
#[test]
fn compile_full() {
}
#[test]
fn compile_full() {
let (src, stmt) = setup_src_stmt();
assert_eq!(Compiler::compile(&src).unwrap(), stmt)
}
}

Loading…
Cancel
Save