Add Blob::write for strings.

This commit is contained in:
Stephen Chung
2021-12-18 23:03:35 +08:00
parent e507dcfcb4
commit 123012404b
2 changed files with 68 additions and 14 deletions

View File

@@ -169,6 +169,16 @@ fn test_blobs_parse() -> Result<(), Box<EvalAltResult>> {
vec![0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90]
);
assert_eq!(
engine.eval::<Blob>(r#"let x = blob(16, 0); write(x, 0, 14, "hello, world!"); x"#)?,
"hello, world!\0\0\0".as_bytes()
);
assert_eq!(
engine.eval::<Blob>(r#"let x = blob(10, 0); write(x, 3, 5, "hello, world!"); x"#)?,
"\0\0\0hello\0\0".as_bytes()
);
Ok(())
}
@@ -238,5 +248,15 @@ fn test_blobs_parse() -> Result<(), Box<EvalAltResult>> {
0x1cf588
);
assert_eq!(
engine.eval::<Blob>(r#"let x = blob(16, 0); write(x, 0, 14, "hello, world!"); x"#)?,
"hello, world!\0\0\0".as_bytes()
);
assert_eq!(
engine.eval::<Blob>(r#"let x = blob(10, 0); write(x, 3, 5, "hello, world!"); x"#)?,
"\0\0\0hello\0\0".as_bytes()
);
Ok(())
}