Skip to content

Commit

Permalink
auto-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mlwilkerson committed Nov 18, 2019
1 parent 6d02e6d commit 6c83d3a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 111 deletions.
10 changes: 5 additions & 5 deletions lumen_runtime/src/otp/erlang/iolist_size_1.rs
Expand Up @@ -19,7 +19,7 @@ pub fn native(process: &Process, iolist_or_binary: Term) -> exception::Result {
let mut stack: Vec<Term> = vec![iolist_or_binary];
match size(process, &mut stack, 0) {
Ok(size) => Ok(process.integer(size).unwrap()),
Err(bad) => Err(bad)
Err(bad) => Err(bad),
}
}

Expand Down Expand Up @@ -48,11 +48,11 @@ fn size(process: &Process, vec: &mut Vec<Term>, acc: usize) -> Result<usize, Exc

TypedTerm::List(boxed_cons) => {
if boxed_cons.tail.is_smallint() {
Err(badarg!().into())
Err(badarg!().into())
} else {
vec.push(boxed_cons.tail);
vec.push(boxed_cons.head);
size(process, vec, acc)
vec.push(boxed_cons.tail);
vec.push(boxed_cons.head);
size(process, vec, acc)
}
}

Expand Down
55 changes: 28 additions & 27 deletions lumen_runtime/src/otp/erlang/iolist_size_1/test.rs
Expand Up @@ -77,16 +77,17 @@ fn with_binary_returns_size() {
#[test]
fn with_subbinary_in_list_returns_size() {
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();
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_size_1::native(process, iolist),
Expand All @@ -98,13 +99,15 @@ fn with_subbinary_in_list_returns_size() {
#[test]
fn with_subbinary_returns_size() {
with_process(|process| {
let iolist = process.subbinary_from_original(
process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
1,
0,
3,
0
).unwrap();
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_size_1::native(process, iolist),
Expand All @@ -116,11 +119,12 @@ fn with_subbinary_returns_size() {
#[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();
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_size_1::native(process, iolist),
Expand All @@ -133,14 +137,11 @@ fn with_improper_list_smallint_tail_errors_badarg() {
#[test]
fn with_atom_in_iolist_errors_badarg() {
with_process(|process| {
let iolist = process.list_from_slice(&[
atom_unchecked("foo")
],
).unwrap();
let iolist = process.list_from_slice(&[atom_unchecked("foo")]).unwrap();

assert_eq!(
otp::erlang::iolist_size_1::native(process, iolist),
Err(badarg!().into())
)
});
}
}
69 changes: 36 additions & 33 deletions lumen_runtime/src/otp/erlang/iolist_to_binary_1/test.rs
Expand Up @@ -60,16 +60,17 @@ fn with_binary_returns_binary() {
#[test]
fn with_subbinary_in_list_returns_binary() {
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();
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_binary_1::native(process, iolist),
Expand All @@ -81,13 +82,15 @@ fn with_subbinary_in_list_returns_binary() {
#[test]
fn with_subbinary_returns_binary() {
with_process(|process| {
let iolist = process.subbinary_from_original(
process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
1,
0,
3,
0
).unwrap();
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_binary_1::native(process, iolist),
Expand All @@ -99,17 +102,20 @@ fn with_subbinary_returns_binary() {
#[test]
fn with_improper_list_smallint_tail_errors_badarg() {
with_process(|process| {
let iolist = process.improper_list_from_slice(&[
process.subbinary_from_original(
process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
1,
0,
3,
0
).unwrap()
],
process.integer(42).unwrap()
).unwrap();
let iolist = process
.improper_list_from_slice(
&[process
.subbinary_from_original(
process.binary_from_bytes(&[1, 2, 3, 4, 5]).unwrap(),
1,
0,
3,
0,
)
.unwrap()],
process.integer(42).unwrap(),
)
.unwrap();

assert_eq!(
otp::erlang::iolist_to_binary_1::native(process, iolist),
Expand All @@ -122,14 +128,11 @@ fn with_improper_list_smallint_tail_errors_badarg() {
#[test]
fn with_atom_in_iolist_errors_badarg() {
with_process(|process| {
let iolist = process.list_from_slice(&[
atom_unchecked("foo")
],
).unwrap();
let iolist = process.list_from_slice(&[atom_unchecked("foo")]).unwrap();

assert_eq!(
otp::erlang::iolist_to_binary_1::native(process, iolist),
Err(badarg!().into())
)
});
}
}
34 changes: 17 additions & 17 deletions lumen_runtime/src/otp/erlang/iolist_to_iovec_1.rs
Expand Up @@ -21,26 +21,26 @@ pub fn native(process: &Process, iolist_or_binary: Term) -> exception::Result {
} else {
match iolist_or_binary.to_typed_term().unwrap() {
TypedTerm::List(boxed_cons) => {
let mut binaries: Vec<Term> = Vec::new();

for item in boxed_cons.into_iter() {
let term: Term = match item {
Ok(term) => term,
_ => return Err(badarg!().into())
};
let mut binaries: Vec<Term> = Vec::new();

if term.is_binary() {
binaries.push(term);
} else {
match otp::erlang::list_to_binary_1::native(process, term) {
Ok(term) => binaries.push(term),
_ => return Err(badarg!().into())
}
for item in boxed_cons.into_iter() {
let term: Term = match item {
Ok(term) => term,
_ => return Err(badarg!().into()),
};

if term.is_binary() {
binaries.push(term);
} else {
match otp::erlang::list_to_binary_1::native(process, term) {
Ok(term) => binaries.push(term),
_ => return Err(badarg!().into()),
}
}
}
}

binaries
},
binaries
}
_ => return Err(badarg!().into()),
}
};
Expand Down
63 changes: 34 additions & 29 deletions lumen_runtime/src/otp/erlang/iolist_to_iovec_1/test.rs
Expand Up @@ -66,50 +66,58 @@ 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();
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())
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();
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())
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();
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),
Expand All @@ -122,14 +130,11 @@ fn with_improper_list_smallint_tail_errors_badarg() {
#[test]
fn with_atom_in_iolist_errors_badarg() {
with_process(|process| {
let iolist = process.list_from_slice(&[
atom_unchecked("foo")
],
).unwrap();
let iolist = process.list_from_slice(&[atom_unchecked("foo")]).unwrap();

assert_eq!(
otp::erlang::iolist_to_iovec_1::native(process, iolist),
Err(badarg!().into())
)
});
}
}

0 comments on commit 6c83d3a

Please sign in to comment.