Pass assignment test
This commit is contained in:
parent
0ed30c7220
commit
459acb2d63
@ -32,35 +32,36 @@ impl<'src> AbstractTree for Assignment<'src> {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(self, _context: &Context) -> Result<Value, RuntimeError> {
|
fn run(self, context: &Context) -> Result<Value, RuntimeError> {
|
||||||
todo!()
|
let value = self.statement.run(context)?;
|
||||||
// let value = self.statement.run(context)?;
|
|
||||||
|
|
||||||
// context.set(self.identifier, value)?;
|
context.set(self.identifier, value)?;
|
||||||
|
|
||||||
// Ok(Value::none())
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// use super::*;
|
use crate::abstract_tree::{Expression, ValueNode};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn assign_value() {
|
fn assign_value() {
|
||||||
todo!()
|
let context = Context::new();
|
||||||
// let context = Context::new();
|
|
||||||
|
|
||||||
// Assignment::new(
|
Assignment::new(
|
||||||
// Identifier::new("foobar"),
|
Identifier::new("foobar"),
|
||||||
// Statement::Value(Value::integer(42)),
|
None,
|
||||||
// )
|
Statement::Expression(Expression::Value(ValueNode::Integer(42))),
|
||||||
// .run(&context)
|
)
|
||||||
// .unwrap();
|
.run(&context)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// context.get(&Identifier::new("foobar")).unwrap(),
|
context.get(&Identifier::new("foobar")),
|
||||||
// Some(Value::integer(42))
|
Ok(Some(Value::integer(42)))
|
||||||
// )
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,10 @@ impl Identifier {
|
|||||||
pub fn new<T: ToString>(string: T) -> Self {
|
pub fn new<T: ToString>(string: T) -> Self {
|
||||||
Identifier(Arc::new(string.to_string()))
|
Identifier(Arc::new(string.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
self.0.as_str()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AbstractTree for Identifier {
|
impl AbstractTree for Identifier {
|
||||||
|
@ -26,7 +26,7 @@ impl<'src> AbstractTree for Statement<'src> {
|
|||||||
match self {
|
match self {
|
||||||
Statement::Assignment(assignment) => assignment.run(_context),
|
Statement::Assignment(assignment) => assignment.run(_context),
|
||||||
Statement::Block(_) => todo!(),
|
Statement::Block(_) => todo!(),
|
||||||
Statement::Expression(_) => todo!(),
|
Statement::Expression(expression) => expression.run(_context),
|
||||||
Statement::Loop(_) => todo!(),
|
Statement::Loop(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,13 @@ impl<'src> AbstractTree for ValueNode<'src> {
|
|||||||
}
|
}
|
||||||
ValueNode::Range(range) => Value::range(range),
|
ValueNode::Range(range) => Value::range(range),
|
||||||
ValueNode::String(string) => Value::string(string),
|
ValueNode::String(string) => Value::string(string),
|
||||||
ValueNode::Enum(name, variant) => Value::r#enum(name, variant),
|
ValueNode::Enum(name, variant) => {
|
||||||
|
if name.as_str() == "Option" && variant.as_str() == "None" {
|
||||||
|
Value::none()
|
||||||
|
} else {
|
||||||
|
Value::r#enum(name, variant)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(value)
|
Ok(value)
|
||||||
|
10
src/value.rs
10
src/value.rs
@ -17,6 +17,16 @@ impl Value {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn none() -> Self {
|
||||||
|
NONE.get_or_init(|| {
|
||||||
|
Value(Arc::new(ValueInner::Enum(
|
||||||
|
Identifier::new("Option"),
|
||||||
|
Identifier::new("None"),
|
||||||
|
)))
|
||||||
|
})
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn boolean(boolean: bool) -> Self {
|
pub fn boolean(boolean: bool) -> Self {
|
||||||
Value(Arc::new(ValueInner::Boolean(boolean)))
|
Value(Arc::new(ValueInner::Boolean(boolean)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user