Skip to content

Commit

Permalink
Dev #91
Browse files Browse the repository at this point in the history
  • Loading branch information
vulogov committed Sep 25, 2024
1 parent 2c451b6 commit f0db071
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn value_list_conversion(
}
return Result::Ok(Value::from_dict(res));
}
STRING => {
STRING | TEXTBUFFER => {
let mut out: String = "[".to_string();
for v in val {
match v.conv(STRING) {
Expand All @@ -223,7 +223,11 @@ fn value_list_conversion(
}
}
out = out + &"]".to_string();
return Result::Ok(Value::from_string(out));
if t == STRING {
return Result::Ok(Value::from_string(out));
} else {
return Result::Ok(Value::text_buffer(out));
}
}
_ => Err(format!("Can not convert list to {:?}", &t).into()),
}
Expand Down Expand Up @@ -280,7 +284,7 @@ fn value_queue_conversion(
}
return Result::Ok(Value::from_dict(res));
}
STRING => {
STRING | TEXTBUFFER => {
let mut out: String = format!("{}[", st).to_string();
for v in val {
match v.conv(STRING) {
Expand All @@ -293,7 +297,11 @@ fn value_queue_conversion(
}
}
out = out + &"]".to_string();
return Result::Ok(Value::from_string(out));
if t == STRING {
return Result::Ok(Value::from_string(out));
} else {
return Result::Ok(Value::text_buffer(out));
}
}
_ => Err(format!("Can not convert list to {:?}", &t).into()),
}
Expand Down Expand Up @@ -331,7 +339,7 @@ fn value_lambda_conversion(
return Result::Ok(Value::from_bool(true));
}
}
STRING => {
STRING | TEXTBUFFER => {
let mut out: String = "lambda[".to_string();
for v in val {
match v.conv(STRING) {
Expand All @@ -344,7 +352,11 @@ fn value_lambda_conversion(
}
}
out = out + &"]".to_string();
return Result::Ok(Value::from_string(out));
if t == STRING {
return Result::Ok(Value::from_string(out));
} else {
return Result::Ok(Value::text_buffer(out));
}
}
_ => Err(format!("Can not convert lambda to {:?}", &t).into()),
}
Expand Down Expand Up @@ -390,7 +402,7 @@ fn value_map_conversion(
}
return Result::Ok(Value::from_list(res));
}
STRING => {
STRING | TEXTBUFFER => {
let mut out: String = "{".to_string();
for (k, v) in val {
match v.conv(STRING) {
Expand All @@ -405,7 +417,11 @@ fn value_map_conversion(
}
}
out = out + &"}".to_string();
return Result::Ok(Value::from_string(out));
if t == STRING {
return Result::Ok(Value::from_string(out));
} else {
return Result::Ok(Value::text_buffer(out));
}
}
_ => Err(format!("Can not convert map to {:?}", &t).into()),
}
Expand Down
7 changes: 7 additions & 0 deletions tests/conv-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ mod tests {
assert_eq!(val.cast_string().unwrap(), "{ answer=42 :: }");
}
#[test]
fn test_conv_map_textbuffer() {
let val = Value::dict()
.set("answer".to_string(), Value::from(42 as i64).unwrap())
.conv(TEXTBUFFER).unwrap();
assert_eq!(val.cast_string().unwrap(), "{ answer=42 :: }");
}
#[test]
fn test_conv_map_list() {
let val = Value::dict()
.set("answer".to_string(), Value::from(42 as i64).unwrap())
Expand Down

0 comments on commit f0db071

Please sign in to comment.