Add constructors for Value type enum variants

This commit is contained in:
bad 2022-04-05 23:12:13 +02:00
parent 2c2cb00e2e
commit df22460010
2 changed files with 25 additions and 4 deletions

View File

@ -23,3 +23,27 @@ impl From<astnode::Literal> for Value {
)
}
}
impl Value {
pub fn int(i: i32) -> Value {
Value::Primitive(Primitive::Int(i))
}
pub fn float(f: f32) -> Value {
Value::Primitive(Primitive::Float(f))
}
pub fn bool(b: bool) -> Value {
Value::Primitive(Primitive::Bool(b))
}
pub fn null() -> Value {
Value::Primitive(Primitive::Null)
}
}
impl Default for Value {
fn default() -> Self {
Self::null()
}
}

View File

@ -12,8 +12,5 @@ fn test_one_equality() {
}
fn run_check_result_eq_bool(code: &str, value: bool) {
assert_eq!(
run(code).unwrap(),
types::Value::Primitive(types::Primitive::Bool(value))
)
assert_eq!(run(code).unwrap(), types::Value::bool(value))
}