Browse Source

first test added

pull/1/head
Jason Williams 6 years ago
parent
commit
9a50cc11c4
  1. 15
      .vscode/tasks.json
  2. 3
      src/bin/bin.rs
  3. 1
      test.js
  4. 1
      tests/js/defineVar.js
  5. 23
      tests/lexer_test.rs

15
.vscode/tasks.json vendored

@ -17,6 +17,21 @@
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
} }
},
{
"type": "cargo",
"label": "cargo Test",
"command": "cargo",
"args": [
"test"
],
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "test",
"isDefault": true
}
} }
] ]
} }

3
src/bin/bin.rs

@ -3,9 +3,8 @@ use js::syntax::lexer::Lexer;
use std::fs::read_to_string; use std::fs::read_to_string;
pub fn main() { pub fn main() {
let buffer = read_to_string("test.js").unwrap(); let buffer = read_to_string("tests/js/defineVar.js").unwrap();
let mut lexer = Lexer::new(&buffer); let mut lexer = Lexer::new(&buffer);
lexer.lex().expect("finished"); lexer.lex().expect("finished");
println!("{:?}", lexer.tokens); println!("{:?}", lexer.tokens);
println!("Hello World");
} }

1
test.js

@ -1 +0,0 @@
let a = (2 * 2);

1
tests/js/defineVar.js

@ -0,0 +1 @@
console.log("hello world");

23
tests/lexer_test.rs

@ -0,0 +1,23 @@
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())
);
}
Loading…
Cancel
Save