Skip to content

Commit

Permalink
test(interface-types) Fix one bug and write the test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Feb 17, 2020
1 parent e7b56d8 commit b33bec1
Show file tree
Hide file tree
Showing 3 changed files with 424 additions and 24 deletions.
45 changes: 26 additions & 19 deletions lib/interface-types/src/decoders/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ fn forwards<'input, E: ParseError<&'input [u8]>>(
Ok((input, forwards))
}

/// Parse complete interfaces.
fn interfaces<'input, E: ParseError<&'input [u8]>>(
bytes: &'input [u8],
) -> IResult<&'input [u8], Interfaces, E> {
let mut input = bytes;

consume!((input, exports) = exports(input)?);
consume!((input, types) = types(input)?);
consume!((input, imports) = imports(input)?);
consume!((input, adapters) = adapters(input)?);
consume!((input, forwards) = forwards(input)?);

Ok((
input,
Interfaces {
exports,
types,
imports,
adapters,
forwards,
},
))
}

/// Parse a sequence of bytes, expecting it to be a valid WIT binary
/// representation, into an `ast::Interfaces`.
///
Expand Down Expand Up @@ -500,24 +524,7 @@ fn forwards<'input, E: ParseError<&'input [u8]>>(
pub fn parse<'input, E: ParseError<&'input [u8]>>(
bytes: &'input [u8],
) -> IResult<&'input [u8], Interfaces, E> {
let mut input = bytes;

consume!((input, exports) = exports(input)?);
consume!((input, types) = types(input)?);
consume!((input, imports) = imports(input)?);
consume!((input, adapters) = adapters(input)?);
consume!((input, forwards) = forwards(input)?);

Ok((
input,
Interfaces {
exports,
types,
imports,
adapters,
forwards,
},
))
interfaces(bytes)
}

#[cfg(test)]
Expand Down Expand Up @@ -978,6 +985,6 @@ mod tests {
},
));

assert_eq!(parse::<()>(input), output);
assert_eq!(interfaces::<()>(input), output);
}
}
Loading

0 comments on commit b33bec1

Please sign in to comment.