Add constructors for Value type enum variants
This commit is contained in:
parent
2c2cb00e2e
commit
df22460010
2 changed files with 25 additions and 4 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue