Skip to content

Commit

Permalink
feat: quote string object
Browse files Browse the repository at this point in the history
  • Loading branch information
caelansar committed Jun 26, 2024
1 parent a2dd287 commit 4d09f14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ mod test {
),
(
r#"-"str""#,
Some(Object::Error("unknown operator: -str".into())),
Some(Object::Error("unknown operator: -\"str\"".into())),
),
(
"1-true; 10",
Expand Down
7 changes: 6 additions & 1 deletion src/eval/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Display for Object {
Object::Int(i) => write!(f, "{}", i),
Object::Float(float) => write!(f, "{}", float),
Object::Bool(b) => write!(f, "{}", b),
Object::String(s) => write!(f, "{}", s),
Object::String(s) => write!(f, "\"{}\"", s),
Object::Return(r) => write!(f, "{}", r),
Object::Array(e) => write!(
f,
Expand Down Expand Up @@ -203,6 +203,7 @@ fn object_display_should_work() {
assert_eq!("true", Object::Bool(true).to_string());
assert_eq!("false", Object::Bool(false).to_string());
assert_eq!("null", Object::Null.to_string());
assert_eq!("\"aa\"", Object::String("aa".into()).to_string());
}

#[test]
Expand All @@ -211,6 +212,10 @@ fn object_arithmetic_should_work() {
Object::Error("type mismatch: 123 + 1.1".into()),
&Object::Int(123) + &Object::Float(1.1)
);
assert_eq!(
Object::Error("type mismatch: 123 + \"4\"".into()),
&Object::Int(123) + &Object::String("4".into())
);
assert_eq!(Object::Int(124), &Object::Int(123) + &Object::Int(1));
assert_eq!(
Object::String("12".into()),
Expand Down
2 changes: 1 addition & 1 deletion src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ mod test {
let no_function = "aa";
no_function()
"#,
Some(object::Object::Error("aa not a function".into())),
Some(object::Object::Error("\"aa\" not a function".into())),
),
(
r#"
Expand Down

0 comments on commit 4d09f14

Please sign in to comment.