Skip to content

Commit

Permalink
Dev #90
Browse files Browse the repository at this point in the history
  • Loading branch information
vulogov committed Sep 25, 2024
1 parent 74037d3 commit 2c451b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ fn value_float_conversion(t: u16, ot: u16, val: f64) -> Result<Value, Box<dyn st
let mut buffer = dtoa::Buffer::new();
return Result::Ok(Value::from_string(buffer.format(val).to_string()));
}
TEXTBUFFER => {
let mut buffer = dtoa::Buffer::new();
return Result::Ok(Value::text_buffer(buffer.format(val).to_string()));
}
LIST => {
return Result::Ok(Value::from(vec![Value::from(val as f64).unwrap()]).unwrap());
}
Expand Down Expand Up @@ -66,6 +70,10 @@ fn value_integer_conversion(
let mut buffer = itoa::Buffer::new();
return Result::Ok(Value::from_string(buffer.format(val).to_string()));
}
TEXTBUFFER => {
let mut buffer = itoa::Buffer::new();
return Result::Ok(Value::text_buffer(buffer.format(val).to_string()));
}
LIST => {
return Result::Ok(Value::from(vec![Value::from(val as i64).unwrap()]).unwrap());
}
Expand Down Expand Up @@ -145,6 +153,9 @@ fn value_bool_conversion(t: u16, ot: u16, val: bool) -> Result<Value, Box<dyn st
STRING => {
return Result::Ok(Value::from_string(format!("{}", val)));
}
TEXTBUFFER => {
return Result::Ok(Value::text_buffer(format!("{}", val)));
}
LIST => {
return Result::Ok(Value::from(vec![Value::from_bool(val)]).unwrap());
}
Expand Down
5 changes: 5 additions & 0 deletions tests/conv-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ mod tests {
assert_eq!(val.cast_string().unwrap(), "42.0");
}
#[test]
fn test_conv_float_textbuffer() {
let val = Value::from(42.0 as f64).unwrap().conv(TEXTBUFFER).unwrap();
assert_eq!(val.cast_string().unwrap(), "42.0");
}
#[test]
fn test_conv_float_list_check_len() {
let val = Value::from(42.0 as f64).unwrap().conv(LIST).unwrap();
assert_eq!(val.len(), 1);
Expand Down

0 comments on commit 2c451b6

Please sign in to comment.