Skip to content

Commit

Permalink
Merge pull request #35 from coco33920/symbolic
Browse files Browse the repository at this point in the history
Coverage
  • Loading branch information
vanilla-extracts authored Dec 3, 2023
2 parents 616c548 + b9370d6 commit bad9bee
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 65 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: coverage

on: [push]
jobs:
test:
name: coverage
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Generate code coverage
run: |
cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
186 changes: 186 additions & 0 deletions src/lexing/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,189 @@ impl Token {
}
}
}
#[cfg(test)]
mod test {
use super::{Token, TokenType};

#[test]
fn test_token_type_operators_plus() {
let expected = TokenType::PLUS;
let value = Token::OPE(super::Operator::PLUS).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_minus() {
let expected = TokenType::MINUS;
let value = Token::OPE(super::Operator::MINUS).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_mult() {
let expected = TokenType::MULTIPLICATION;
let value = Token::OPE(super::Operator::MULTIPLICATION).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_divide() {
let expected = TokenType::DIVIDE;
let value = Token::OPE(super::Operator::DIVIDE).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_expo() {
let expected = TokenType::EXPO;
let value = Token::OPE(super::Operator::EXPO).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_equality() {
let expected = TokenType::EQUALITY;
let value = Token::OPE(super::Operator::EQUALITY).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_greater() {
let expected = TokenType::GREATER;
let value = Token::OPE(super::Operator::GreaterThan).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_lesser() {
let expected = TokenType::LESSER;
let value = Token::OPE(super::Operator::LesserThan).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_greaterq() {
let expected = TokenType::GREATEREQ;
let value = Token::OPE(super::Operator::GreaterOrEqual).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_lesserq() {
let expected = TokenType::LESSEREQ;
let value = Token::OPE(super::Operator::LesserOrEqual).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_and() {
let expected = TokenType::AND;
let value = Token::OPE(super::Operator::And).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_or() {
let expected = TokenType::OR;
let value = Token::OPE(super::Operator::Or).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_operators_not() {
let expected = TokenType::NOT;
let value = Token::OPE(super::Operator::NOT).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_identifier() {
let expected = TokenType::IDENTIFIER;
let value = Token::IDENTIFIER("s".to_string()).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_int() {
let expected = TokenType::INT;
let value = Token::INT(0).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_float() {
let expected = TokenType::FLOAT;
let value = Token::FLOAT(0.0).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_equal() {
let expected = TokenType::EQUAL;
let value = Token::EQUAL.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_lpar() {
let expected = TokenType::LPAR;
let value = Token::LPAR.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_rpar() {
let expected = TokenType::RPAR;
let value = Token::RPAR.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_bool() {
let expected = TokenType::BOOL;
let value = Token::BOOL(false).to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_null() {
let expected = TokenType::Null;
let value = Token::Null.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_comma() {
let expected = TokenType::COMMA;
let value = Token::COMMA.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_rbracket() {
let expected = TokenType::RBRACKET;
let value = Token::RBRACKET.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_lbracket() {
let expected = TokenType::LBRACKET;
let value = Token::LBRACKET.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_whitespace() {
let expected = TokenType::WHITESPACE;
let value = Token::WHITESPACE.to_token_type();
assert_eq!(value, expected);
}

#[test]
fn test_token_type_quote() {
let expected = TokenType::QUOTE;
let value = Token::QUOTE.to_token_type();
assert_eq!(value, expected);
}
}
65 changes: 0 additions & 65 deletions src/parsing/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,36 +255,6 @@ impl Ast {
right: Box::from(Nil),
}
}
pub fn insert_left(self, node: Ast) -> Self {
match &self {
Nil => node,
Node {
value,
left: _left,
right,
} => Node {
value: value.clone(),
left: Box::from(node),
right: right.clone(),
},
_ => node,
}
}
pub fn insert_right(self, node: Ast) -> Self {
match &self {
Nil => node,
Node {
value,
left,
right: _right,
} => Node {
value: value.clone(),
left: left.clone(),
right: Box::from(node),
},
_ => node,
}
}
}

impl Parameters {
Expand Down Expand Up @@ -322,39 +292,4 @@ mod test {
let result = Ast::new(Parameters::Int(2));
assert_eq!(result, expected)
}

#[test]
pub fn test_insert_left() {
let expected = Ast::Node {
value: Parameters::Int(2),
left: Box::from(Ast::new(Parameters::Int(2))),
right: Box::from(Ast::Nil),
};
let result = Ast::new(Parameters::Int(2)).insert_left(Ast::new(Parameters::Int(2)));
assert_eq!(result, expected)
}

#[test]
pub fn test_insert_right() {
let expected = Ast::Node {
value: Parameters::Int(2),
left: Box::from(Ast::Nil),
right: Box::from(Ast::new(Parameters::Int(2))),
};
let result = Ast::new(Parameters::Int(2)).insert_right(Ast::new(Parameters::Int(2)));
assert_eq!(result, expected)
}

#[test]
pub fn test_insert_both() {
let expected = Ast::Node {
value: Parameters::Int(2),
left: Box::from(Ast::new(Parameters::Int(2))),
right: Box::from(Ast::new(Parameters::Int(2))),
};
let result = Ast::new(Parameters::Int(2))
.insert_right(Ast::new(Parameters::Int(2)))
.insert_left(Ast::new(Parameters::Int(2)));
assert_eq!(result, expected);
}
}

0 comments on commit bad9bee

Please sign in to comment.