mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
value: start adding tests for overloaded ops
This commit is contained in:
parent
e0378e24a2
commit
3eb8429ab6
@ -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)));
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum TypeError {
|
||||
UnsupportedOperandTypes {
|
||||
lhs: String,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use indexmap::IndexMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum PhpValue {
|
||||
Int(i64),
|
||||
Float(f64),
|
||||
|
Loading…
Reference in New Issue
Block a user