value: start adding tests for overloaded ops

This commit is contained in:
Ryan Chandler 2022-08-06 11:28:15 +01:00
parent e0378e24a2
commit 3eb8429ab6
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
3 changed files with 18 additions and 2 deletions

View File

@ -7,4 +7,19 @@ mod rem;
mod type_error;
pub use value::*;
pub use type_error::TypeError;
pub use type_error::TypeError;
#[cfg(test)]
mod tests {
use crate::PhpValue;
#[test]
fn values_can_be_added() {
assert_eq!(PhpValue::Int(1) + PhpValue::Int(2), Ok(PhpValue::Int(3)));
assert_eq!(PhpValue::Float(1.5) + PhpValue::Float(2.5), Ok(PhpValue::Float(4.0)));
assert_eq!(PhpValue::Float(1.5) + PhpValue::Int(1), Ok(PhpValue::Float(2.5)));
assert_eq!(PhpValue::Int(1) + PhpValue::Float(1.5), Ok(PhpValue::Float(2.5)));
assert_eq!(PhpValue::String("1".into()) + PhpValue::Int(1), Ok(PhpValue::Int(2)));
assert_eq!(PhpValue::String("1".into()) + PhpValue::Float(1.0), Ok(PhpValue::Float(2.0)));
}
}

View File

@ -1,3 +1,4 @@
#[derive(Debug, PartialEq)]
pub enum TypeError {
UnsupportedOperandTypes {
lhs: String,

View File

@ -1,6 +1,6 @@
use indexmap::IndexMap;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum PhpValue {
Int(i64),
Float(f64),