1
0

Fix errors

This commit is contained in:
Jeff 2023-10-05 08:42:23 -04:00
parent 1cfa809340
commit f30dfe6431
2 changed files with 8 additions and 2 deletions

View File

@ -521,7 +521,7 @@ mod tests {
map.set_value("foo".to_string(), Value::String("bar".to_string())) map.set_value("foo".to_string(), Value::String("bar".to_string()))
.unwrap(); .unwrap();
assert_eq!(eval("map { x = 1 foo = 'bar' }"), vec![Ok(Value::Map(map))]); assert_eq!(eval("{ x = 1 foo = 'bar' }"), vec![Ok(Value::Map(map))]);
} }
#[test] #[test]

View File

@ -67,7 +67,7 @@ impl Value {
Ok(Value::Float(raw_value)) Ok(Value::Float(raw_value))
} }
"string" => { "string" => {
let byte_range_without_quotes = child.start_byte() - 1..child.end_byte(); let byte_range_without_quotes = child.start_byte() + 1..child.end_byte() - 1;
let text = &source[byte_range_without_quotes]; let text = &source[byte_range_without_quotes];
Ok(Value::String(text.to_string())) Ok(Value::String(text.to_string()))
@ -438,11 +438,16 @@ impl Eq for Value {}
impl PartialEq for Value { impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
match (self, other) { match (self, other) {
(Value::Integer(left), Value::Integer(right)) => left == right,
(Value::Float(left), Value::Float(right)) => left == right,
(Value::Boolean(left), Value::Boolean(right)) => left == right,
(Value::String(left), Value::String(right)) => left == right,
(Value::List(left), Value::List(right)) => left == right, (Value::List(left), Value::List(right)) => left == right,
(Value::Map(left), Value::Map(right)) => left == right, (Value::Map(left), Value::Map(right)) => left == right,
(Value::Table(left), Value::Table(right)) => left == right, (Value::Table(left), Value::Table(right)) => left == right,
(Value::Time(left), Value::Time(right)) => left == right, (Value::Time(left), Value::Time(right)) => left == right,
(Value::Function(left), Value::Function(right)) => left == right, (Value::Function(left), Value::Function(right)) => left == right,
(Value::Empty, Value::Empty) => true,
_ => false, _ => false,
} }
} }
@ -475,6 +480,7 @@ impl Ord for Value {
(Value::Function(_), _) => Ordering::Greater, (Value::Function(_), _) => Ordering::Greater,
(Value::Time(left), Value::Time(right)) => left.cmp(right), (Value::Time(left), Value::Time(right)) => left.cmp(right),
(Value::Time(_), _) => Ordering::Greater, (Value::Time(_), _) => Ordering::Greater,
(Value::Empty, Value::Empty) => Ordering::Equal,
(Value::Empty, _) => Ordering::Less, (Value::Empty, _) => Ordering::Less,
} }
} }