diff --git a/tests/blobs.rs b/tests/blobs.rs index f467be2c..5653e1ef 100644 --- a/tests/blobs.rs +++ b/tests/blobs.rs @@ -169,33 +169,6 @@ fn test_blobs_parse() -> Result<(), Box> { vec![0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90] ); - assert_eq!( - engine.eval::(r#"let x = blob(16, 0); write_ascii(x, 0, 14, "hello, world!"); x"#)?, - "hello, world!\0\0\0".as_bytes() - ); - - assert_eq!( - engine.eval::(r#"let x = blob(10, 0); write_ascii(x, 3..8, "hello, world!"); x"#)?, - "\0\0\0hello\0\0".as_bytes() - ); - - assert_eq!( - engine.eval::( - r#"let x = blob(10, 0); write_ascii(x, 0..9, "❤ hello, ❤ world! ❤❤❤"); x"# - )?, - " hello, \0".as_bytes() - ); - - assert_eq!( - engine.eval::(r#"let x = blob(10, 0); write_utf8(x, 3..9, "❤❤❤❤"); x"#)?, - "\0\0\0\u{2764}\u{2764}\0".as_bytes() - ); - - assert_eq!( - engine.eval::(r#"let x = blob(10, 0); write_utf8(x, 3..7, "❤❤❤❤"); x"#)?, - vec![0, 0, 0, 226, 157, 164, 226, 0, 0, 0] - ); - Ok(()) } @@ -265,15 +238,39 @@ fn test_blobs_parse() -> Result<(), Box> { 0x1cf588 ); + Ok(()) +} + +#[test] +fn test_blobs_write_string() -> Result<(), Box> { + let engine = Engine::new(); + assert_eq!( - engine.eval::(r#"let x = blob(16, 0); write(x, 0, 14, "hello, world!"); x"#)?, + engine.eval::(r#"let x = blob(16, 0); write_ascii(x, 0, 14, "hello, world!"); x"#)?, "hello, world!\0\0\0".as_bytes() ); assert_eq!( - engine.eval::(r#"let x = blob(10, 0); write(x, 3, 5, "hello, world!"); x"#)?, + engine.eval::(r#"let x = blob(10, 0); write_ascii(x, 3..8, "hello, world!"); x"#)?, "\0\0\0hello\0\0".as_bytes() ); + assert_eq!( + engine.eval::( + r#"let x = blob(10, 0); write_ascii(x, 0..9, "❤ hello, ❤ world! ❤❤❤"); x"# + )?, + " hello, \0".as_bytes() + ); + + assert_eq!( + engine.eval::(r#"let x = blob(10, 0); write_utf8(x, 3..9, "❤❤❤❤"); x"#)?, + "\0\0\0\u{2764}\u{2764}\0".as_bytes() + ); + + assert_eq!( + engine.eval::(r#"let x = blob(10, 0); write_utf8(x, 3..7, "❤❤❤❤"); x"#)?, + vec![0, 0, 0, 226, 157, 164, 226, 0, 0, 0] + ); + Ok(()) }