Rust编写的JavaScript引擎,该项目是一个试验性质的项目。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
736 B

extern crate js;
use js::syntax::ast::keyword::Keyword;
use js::syntax::ast::punc::Punctuator;
use js::syntax::ast::token::TokenData;
use js::syntax::lexer::Lexer;
#[test]
/// Check basic variable definition tokens
fn check_variable_definition_tokens() {
let s = &String::from("let a = 'hello';");
let mut lexer = Lexer::new(s);
lexer.lex().expect("finished");
assert_eq!(lexer.tokens[0].data, TokenData::Keyword(Keyword::Let));
assert_eq!(lexer.tokens[1].data, TokenData::Identifier("a".to_string()));
assert_eq!(
lexer.tokens[2].data,
TokenData::Punctuator(Punctuator::Assign)
);
assert_eq!(
lexer.tokens[3].data,
TokenData::StringLiteral("hello".to_string())
);
}