From f0db071606f589f939c9978ebb1e8843e948a57c Mon Sep 17 00:00:00 2001 From: Vladimir Ulogov Date: Wed, 25 Sep 2024 16:36:38 -0600 Subject: [PATCH] Dev #91 --- src/conv.rs | 32 ++++++++++++++++++++++++-------- tests/conv-test.rs | 7 +++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/conv.rs b/src/conv.rs index 3980d06..4535d63 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -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) { @@ -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()), } @@ -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) { @@ -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()), } @@ -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) { @@ -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()), } @@ -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) { @@ -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()), } diff --git a/tests/conv-test.rs b/tests/conv-test.rs index 2190970..d026101 100644 --- a/tests/conv-test.rs +++ b/tests/conv-test.rs @@ -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())