WIP: add tests for subbinary, smallint tail in improper list and atom in list for iolist_to_iovec/1
use crate::otp;
use crate::scheduler::with_process;
+use liblumen_alloc::badarg;
+use liblumen_alloc::erts::term::atom_unchecked;
#[test]
fn with_binary_returns_binary_in_list() {
@@ -60,3 +62,74 @@ fn with_mixed_iolists_returns_iovec() {
)
});
}
+
+#[test]
+fn with_subbinary_in_list_returns_list() {
+ with_process(|process| {
+ let iolist = process.list_from_slice(&[
+ process.subbinary_from_original(
+ process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
+ 1,
+ 0,
+ 3,
+ 0
+ ).unwrap()
+ ]
+ ).unwrap();
+
+ assert_eq!(
+ otp::erlang::iolist_to_iovec_1::native(process, iolist),
+ Ok(process.list_from_slice(&[process.binary_from_bytes(&[2,3,4]).unwrap()]).unwrap())
+ )
+ });
+}
+
+#[test]
+fn with_subbinary_returns_list() {
+ with_process(|process| {
+ let iolist = process.subbinary_from_original(
+ process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
+ 1,
+ 0,
+ 3,
+ 0
+ ).unwrap();
+
+ assert_eq!(
+ otp::erlang::iolist_to_iovec_1::native(process, iolist),
+ Ok(process.list_from_slice(&[process.binary_from_bytes(&[2,3,4]).unwrap()]).unwrap())
+ )
+ });
+}
+
+#[test]
+fn with_improper_list_smallint_tail_errors_badarg() {
+ with_process(|process| {
+ let iolist = process.improper_list_from_slice(&[
+ process.binary_from_bytes(&[1, 2, 3]).unwrap(),
+ ],
+ process.integer(42).unwrap()
+ ).unwrap();
+
+ assert_eq!(
+ otp::erlang::iolist_to_iovec_1::native(process, iolist),
+ Err(badarg!().into())
+ )
+ });
+}
+
+// List elements must be smallint, binary, or lists thereof
+#[test]
+fn with_atom_in_iolist_errors_badarg() {
+ with_process(|process| {
+ let iolist = process.list_from_slice(&[
+ atom_unchecked("foo")
+ ],
+ ).unwrap();
+
+ assert_eq!(
+ otp::erlang::iolist_to_iovec_1::native(process, iolist),
+ Err(badarg!().into())
+ )
+ });
+}
\ No newline at end of file
