Skip to content

Commit

Permalink
Fix linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed May 30, 2020
1 parent 91ec65b commit 98b4cba
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 90 deletions.
113 changes: 54 additions & 59 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,65 +172,60 @@ pub enum Token<'a> {
ExprEnd,
}

mod test {
use super::Token;
use logos::Logos;

#[test]
fn lex_numbers() {
let tokens: Vec<_> = Token::lexer("1 42 -100 3.14 -77.77").collect();
assert_eq!(
tokens,
&[
Token::IntegerNum(1),
Token::IntegerNum(42),
Token::Minus,
Token::IntegerNum(100),
Token::FloatNum(3.14),
Token::Minus,
Token::FloatNum(77.77),
]
);
}
#[test]
fn lex_numbers() {
let tokens: Vec<_> = Token::lexer("1 42 -100 3.14 -77.77").collect();
assert_eq!(
tokens,
&[
Token::IntegerNum(1),
Token::IntegerNum(42),
Token::Minus,
Token::IntegerNum(100),
Token::FloatNum(3.14),
Token::Minus,
Token::FloatNum(77.77),
]
);
}

#[test]
fn lex_strings() {
let tokens: Vec<_> = Token::lexer("\"some string\" \"\"").collect();
assert_eq!(
tokens,
&[
Token::String(std::borrow::Cow::Borrowed("some string")),
Token::String(std::borrow::Cow::Borrowed("")),
]
);
}
#[test]
fn lex_strings() {
let tokens: Vec<_> = Token::lexer("\"some string\" \"\"").collect();
assert_eq!(
tokens,
&[
Token::String(std::borrow::Cow::Borrowed("some string")),
Token::String(std::borrow::Cow::Borrowed("")),
]
);
}

#[test]
fn lex_math() {
let tokens: Vec<_> = Token::lexer("(2 + 3 * (5 - 1) + 2 ** 3 / 16) % 5").collect();
assert_eq!(
tokens,
&[
Token::LBracket,
Token::IntegerNum(2),
Token::Plus,
Token::IntegerNum(3),
Token::Mul,
Token::LBracket,
Token::IntegerNum(5),
Token::Minus,
Token::IntegerNum(1),
Token::RBracket,
Token::Plus,
Token::IntegerNum(2),
Token::MulMul,
Token::IntegerNum(3),
Token::Div,
Token::IntegerNum(16),
Token::RBracket,
Token::Percent,
Token::IntegerNum(5),
]
);
}
#[test]
fn lex_math() {
let tokens: Vec<_> = Token::lexer("(2 + 3 * (5 - 1) + 2 ** 3 / 16) % 5").collect();
assert_eq!(
tokens,
&[
Token::LBracket,
Token::IntegerNum(2),
Token::Plus,
Token::IntegerNum(3),
Token::Mul,
Token::LBracket,
Token::IntegerNum(5),
Token::Minus,
Token::IntegerNum(1),
Token::RBracket,
Token::Plus,
Token::IntegerNum(2),
Token::MulMul,
Token::IntegerNum(3),
Token::Div,
Token::IntegerNum(16),
Token::RBracket,
Token::Percent,
Token::IntegerNum(5),
]
);
}
2 changes: 1 addition & 1 deletion src/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a> Statement<'a> {
pub fn add_else_branch(&mut self, branch: Statement<'a>) {
match self {
Statement::If(statement) => statement.add_else_branch(branch),
Statement::Else(statement) => todo!(),
Statement::Else(_statement) => todo!(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/template_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ pub struct TemplateEnv {
}

impl TemplateEnv {
pub fn add_global(&mut self, name: String, val: Value) {
todo!("Unimplemented")
pub fn add_global(&mut self, _name: String, _val: Value) {
todo!()
}

pub fn remove_global(&mut self, name: String, val: Value) {
todo!("Unimplemented")
pub fn remove_global(&mut self, _name: String, _val: Value) {
todo!()
}

pub fn set_settings(&mut self, settings: Settings) {
Expand Down
48 changes: 22 additions & 26 deletions src/value/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,26 @@ impl BitOr for Value {
}
}

mod test {
use super::Value;

#[test]
fn operations() {
let two = Value::String("2".to_owned());
let three = Value::Double(3.0);
let four = Value::Double(4.0);
let five = Value::Integer(5);

assert_eq!(three.clone() * five.clone(), Value::Double(15.0));
assert_eq!(five.clone() * four.clone(), Value::Double(20.0));
assert_eq!(three.clone() * four.clone(), Value::Double(12.0));
assert_eq!(three.clone() + four.clone(), Value::Double(7.0));
assert_eq!(three.clone() / four.clone(), Value::Double(0.75));
assert_eq!(five.clone() / four.clone(), Value::Double(1.25));
assert_eq!(three.clone() / five.clone(), Value::Double(0.6));
assert_eq!(two.clone() * three.clone(), Value::String("222".to_owned()));
assert_eq!(five.clone() - three.clone(), Value::Double(2.0));
assert_eq!(-four.clone(), Value::Double(-4.0));
assert_eq!(!Value::Boolean(true), Value::Boolean(false));
assert_eq!(five.clone() % three.clone(), Value::Double(2.0));
assert_eq!(four.clone() % three.clone(), Value::Double(1.0));
assert_eq!(five.pow(three.clone()), Value::Double(125.0));
assert_eq!(four.pow(three.clone()), Value::Double(64.0));
}
#[test]
fn operations() {
let two = Value::String("2".to_owned());
let three = Value::Double(3.0);
let four = Value::Double(4.0);
let five = Value::Integer(5);

assert_eq!(three.clone() * five.clone(), Value::Double(15.0));
assert_eq!(five.clone() * four.clone(), Value::Double(20.0));
assert_eq!(three.clone() * four.clone(), Value::Double(12.0));
assert_eq!(three.clone() + four.clone(), Value::Double(7.0));
assert_eq!(three.clone() / four.clone(), Value::Double(0.75));
assert_eq!(five.clone() / four.clone(), Value::Double(1.25));
assert_eq!(three.clone() / five.clone(), Value::Double(0.6));
assert_eq!(two.clone() * three.clone(), Value::String("222".to_owned()));
assert_eq!(five.clone() - three.clone(), Value::Double(2.0));
assert_eq!(-four.clone(), Value::Double(-4.0));
assert_eq!(!Value::Boolean(true), Value::Boolean(false));
assert_eq!(five.clone() % three.clone(), Value::Double(2.0));
assert_eq!(four.clone() % three.clone(), Value::Double(1.0));
assert_eq!(five.pow(three.clone()), Value::Double(125.0));
assert_eq!(four.pow(three.clone()), Value::Double(64.0));
}

0 comments on commit 98b4cba

Please sign in to comment.