diff --git a/src/btor2/serialize.rs b/src/btor2/serialize.rs index 66dc50c..0ff9969 100644 --- a/src/btor2/serialize.rs +++ b/src/btor2/serialize.rs @@ -3,10 +3,11 @@ // author: Kevin Laeufer use crate::ir::*; +use std::io::Write; pub fn serialize( ctx: &Context, - writer: &mut impl (std::io::Write), + writer: &mut impl Write, sys: &TransitionSystem, ) -> std::io::Result<()> { Serializer::new(ctx, writer).serialize_sys(sys) @@ -20,12 +21,12 @@ pub fn serialize_to_str(ctx: &Context, sys: &TransitionSystem) -> String { String::from_utf8(buf).expect("Failed to read string we wrote!") } -struct Serializer<'a, W: std::io::Write> { +struct Serializer<'a, W: Write> { ctx: &'a Context, writer: &'a mut W, } -impl<'a, W: std::io::Write> Serializer<'a, W> { +impl<'a, W: Write> Serializer<'a, W> { fn new(ctx: &'a Context, writer: &'a mut W) -> Self { Serializer { ctx, writer } } diff --git a/tests/btor2_test.rs b/tests/btor2_test.rs index 3f3a1e3..59244ef 100644 --- a/tests/btor2_test.rs +++ b/tests/btor2_test.rs @@ -27,9 +27,22 @@ fn parse_count2() { insta::assert_snapshot!(sys.serialize_to_str(&ctx)); } +#[test] +fn serialize_count2() { + let mut ctx = Context::default(); + let sys = btor2::parse_str(&mut ctx, COUNT_2, Some("count2")).unwrap(); + insta::assert_snapshot!(btor2::serialize_to_str(&ctx, &sys)); +} + #[test] fn parse_quiz1() { let (ctx, sys) = btor2::parse_file("inputs/Quiz1.btor").unwrap(); insta::assert_snapshot!(sys.serialize_to_str(&ctx)); +} + +#[test] +fn serialize_quiz1() { + let (ctx, sys) = btor2::parse_file("inputs/Quiz1.btor").unwrap(); + insta::assert_snapshot!(btor2::serialize_to_str(&ctx, &sys)); } \ No newline at end of file diff --git a/tests/snapshots/btor2_test__serialize_count2.snap b/tests/snapshots/btor2_test__serialize_count2.snap new file mode 100644 index 0000000..73b3e4e --- /dev/null +++ b/tests/snapshots/btor2_test__serialize_count2.snap @@ -0,0 +1,6 @@ +--- +source: tests/btor2_test.rs +expression: "btor2::serialize_to_str(&ctx, &sys)" +--- +; btor2 description of `count2` generated by patron 0.2.0 + diff --git a/tests/snapshots/btor2_test__serialize_quiz1.snap b/tests/snapshots/btor2_test__serialize_quiz1.snap new file mode 100644 index 0000000..4d6ee42 --- /dev/null +++ b/tests/snapshots/btor2_test__serialize_quiz1.snap @@ -0,0 +1,6 @@ +--- +source: tests/btor2_test.rs +expression: "btor2::serialize_to_str(&ctx, &sys)" +--- +; btor2 description of `Quiz1` generated by patron 0.2.0 +