From 9086c6f5a2ac3e09c358d05700bfbcb18378bdf6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 13 Mar 2012 21:29:28 -0400 Subject: [PATCH] merge all auto_serialize tests into one --- src/test/auxiliary/auto_serialize_lib.rs | 32 -------- src/test/run-pass/auto_serialize.rs | 98 ++++++++++++++++++++++++ src/test/run-pass/auto_serialize_enum.rs | 26 ------- src/test/run-pass/auto_serialize_gen.rs | 25 ------ src/test/run-pass/auto_serialize_link.rs | 28 ------- src/test/run-pass/auto_serialize_rec.rs | 20 ----- src/test/run-pass/auto_serialize_vec.rs | 20 ----- 7 files changed, 98 insertions(+), 151 deletions(-) delete mode 100644 src/test/auxiliary/auto_serialize_lib.rs create mode 100644 src/test/run-pass/auto_serialize.rs delete mode 100644 src/test/run-pass/auto_serialize_enum.rs delete mode 100644 src/test/run-pass/auto_serialize_gen.rs delete mode 100644 src/test/run-pass/auto_serialize_link.rs delete mode 100644 src/test/run-pass/auto_serialize_rec.rs delete mode 100644 src/test/run-pass/auto_serialize_vec.rs diff --git a/src/test/auxiliary/auto_serialize_lib.rs b/src/test/auxiliary/auto_serialize_lib.rs deleted file mode 100644 index 419985ef731..00000000000 --- a/src/test/auxiliary/auto_serialize_lib.rs +++ /dev/null @@ -1,32 +0,0 @@ -#[link(name="auto_serialize_lib", vers="0.0")]; - -use std; -import std::ebml; -import io::writer; - -fn test_ser_and_deser(a1: A, - expected: str, - ebml_ser_fn: fn(ebml::writer, A), - ebml_deser_fn: fn(ebml::ebml_deserializer) -> A, - io_ser_fn: fn(io::writer, A)) { - - // check the pretty printer: - io_ser_fn(io::stdout(), a1); - let s = io::with_str_writer {|w| io_ser_fn(w, a1) }; - #debug["s == %?", s]; - assert s == expected; - - // check the EBML serializer: - let buf = io::mem_buffer(); - let w = ebml::writer(buf as io::writer); - ebml_ser_fn(w, a1); - let d = ebml::new_doc(@io::mem_buffer_buf(buf)); - let a2 = ebml_deser_fn(ebml::ebml_deserializer(d)); - io::print("\na1 = "); - io_ser_fn(io::stdout(), a1); - io::print("\na2 = "); - io_ser_fn(io::stdout(), a2); - io::print("\n"); - assert a1 == a2; - -} diff --git a/src/test/run-pass/auto_serialize.rs b/src/test/run-pass/auto_serialize.rs new file mode 100644 index 00000000000..d2d7eaa5ac4 --- /dev/null +++ b/src/test/run-pass/auto_serialize.rs @@ -0,0 +1,98 @@ +use std; + +// These tests used to be separate files, but I wanted to refactor all +// the common code. + +import std::ebml; +import io::writer; +import std::prettyprint::serializer; +import std::ebml::serializer; +import std::ebml::deserializer; + +fn test_ser_and_deser(a1: A, + expected: str, + ebml_ser_fn: fn(ebml::writer, A), + ebml_deser_fn: fn(ebml::ebml_deserializer) -> A, + io_ser_fn: fn(io::writer, A)) { + + // check the pretty printer: + io_ser_fn(io::stdout(), a1); + let s = io::with_str_writer {|w| io_ser_fn(w, a1) }; + #debug["s == %?", s]; + assert s == expected; + + // check the EBML serializer: + let buf = io::mem_buffer(); + let w = ebml::writer(buf as io::writer); + ebml_ser_fn(w, a1); + let d = ebml::new_doc(@io::mem_buffer_buf(buf)); + let a2 = ebml_deser_fn(ebml::ebml_deserializer(d)); + io::print("\na1 = "); + io_ser_fn(io::stdout(), a1); + io::print("\na2 = "); + io_ser_fn(io::stdout(), a2); + io::print("\n"); + assert a1 == a2; + +} + +#[auto_serialize] +enum expr { + val(uint), + plus(@expr, @expr), + minus(@expr, @expr) +} + + +#[auto_serialize] +type spanned = {lo: uint, hi: uint, node: T}; + +#[auto_serialize] +type spanned_uint = spanned; + +#[auto_serialize] +type some_rec = {v: uint_vec}; + +#[auto_serialize] +enum an_enum = some_rec; + +#[auto_serialize] +type uint_vec = [uint]; + +#[auto_serialize] +type point = {x: uint, y: uint}; + +fn main() { + + test_ser_and_deser(plus(@minus(@val(3u), @val(10u)), + @plus(@val(22u), @val(5u))), + "plus(@minus(@val(3u), @val(10u)), \ + @plus(@val(22u), @val(5u)))", + expr::serialize(_, _), + expr::deserialize(_), + expr::serialize(_, _)); + + test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, + "{lo: 0u, hi: 5u, node: 22u}", + spanned_uint::serialize(_, _), + spanned_uint::deserialize(_), + spanned_uint::serialize(_, _)); + + test_ser_and_deser(an_enum({v: [1u, 2u, 3u]}), + "an_enum({v: [1u, 2u, 3u]})", + an_enum::serialize(_, _), + an_enum::deserialize(_), + an_enum::serialize(_, _)); + + test_ser_and_deser({x: 3u, y: 5u}, + "{x: 3u, y: 5u}", + point::serialize(_, _), + point::deserialize(_), + point::serialize(_, _)); + + test_ser_and_deser([1u, 2u, 3u], + "[1u, 2u, 3u]", + uint_vec::serialize(_, _), + uint_vec::deserialize(_), + uint_vec::serialize(_, _)); +} \ No newline at end of file diff --git a/src/test/run-pass/auto_serialize_enum.rs b/src/test/run-pass/auto_serialize_enum.rs deleted file mode 100644 index 8bb9e02e0f2..00000000000 --- a/src/test/run-pass/auto_serialize_enum.rs +++ /dev/null @@ -1,26 +0,0 @@ -// aux-build:auto_serialize_lib.rs -// xfail-fast:aux-build currently incompatible - -use std; -use auto_serialize_lib; -import std::prettyprint::serializer; -import std::ebml::serializer; -import std::ebml::deserializer; -import auto_serialize_lib::*; - -#[auto_serialize] -enum expr { - val(uint), - plus(@expr, @expr), - minus(@expr, @expr) -} - -fn main() { - test_ser_and_deser(plus(@minus(@val(3u), @val(10u)), - @plus(@val(22u), @val(5u))), - "plus(@minus(@val(3u), @val(10u)), \ - @plus(@val(22u), @val(5u)))", - expr::serialize(_, _), - expr::deserialize(_), - expr::serialize(_, _)); -} \ No newline at end of file diff --git a/src/test/run-pass/auto_serialize_gen.rs b/src/test/run-pass/auto_serialize_gen.rs deleted file mode 100644 index b4cf5417b3b..00000000000 --- a/src/test/run-pass/auto_serialize_gen.rs +++ /dev/null @@ -1,25 +0,0 @@ -// aux-build:auto_serialize_lib.rs -// xfail-fast:aux-build currently incompatible - -use std; -use auto_serialize_lib; -import std::prettyprint::serializer; -import std::ebml::serializer; -import std::ebml::deserializer; -import auto_serialize_lib::*; - -// Test where we link various types used by name. - -#[auto_serialize] -type spanned = {lo: uint, hi: uint, node: T}; - -#[auto_serialize] -type spanned_uint = spanned; - -fn main() { - test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, - "{lo: 0u, hi: 5u, node: 22u}", - spanned_uint::serialize(_, _), - spanned_uint::deserialize(_), - spanned_uint::serialize(_, _)); -} \ No newline at end of file diff --git a/src/test/run-pass/auto_serialize_link.rs b/src/test/run-pass/auto_serialize_link.rs deleted file mode 100644 index 5f3cd8f7aa6..00000000000 --- a/src/test/run-pass/auto_serialize_link.rs +++ /dev/null @@ -1,28 +0,0 @@ -// aux-build:auto_serialize_lib.rs -// xfail-fast:aux-build currently incompatible - -use std; -use auto_serialize_lib; -import std::prettyprint::serializer; -import std::ebml::serializer; -import std::ebml::deserializer; -import auto_serialize_lib::*; - -// Test where we link various types used by name. - -#[auto_serialize] -type uint_vec = [uint]; - -#[auto_serialize] -type some_rec = {v: uint_vec}; - -#[auto_serialize] -enum an_enum = some_rec; - -fn main() { - test_ser_and_deser(an_enum({v: [1u, 2u, 3u]}), - "an_enum({v: [1u, 2u, 3u]})", - an_enum::serialize(_, _), - an_enum::deserialize(_), - an_enum::serialize(_, _)); -} \ No newline at end of file diff --git a/src/test/run-pass/auto_serialize_rec.rs b/src/test/run-pass/auto_serialize_rec.rs deleted file mode 100644 index a16396ce3d0..00000000000 --- a/src/test/run-pass/auto_serialize_rec.rs +++ /dev/null @@ -1,20 +0,0 @@ -// aux-build:auto_serialize_lib.rs -// xfail-fast:aux-build currently incompatible - -use std; -use auto_serialize_lib; -import std::prettyprint::serializer; -import std::ebml::serializer; -import std::ebml::deserializer; -import auto_serialize_lib::*; - -#[auto_serialize] -type point = {x: uint, y: uint}; - -fn main() { - test_ser_and_deser({x: 3u, y: 5u}, - "{x: 3u, y: 5u}", - point::serialize(_, _), - point::deserialize(_), - point::serialize(_, _)); -} \ No newline at end of file diff --git a/src/test/run-pass/auto_serialize_vec.rs b/src/test/run-pass/auto_serialize_vec.rs deleted file mode 100644 index 24fa76d5316..00000000000 --- a/src/test/run-pass/auto_serialize_vec.rs +++ /dev/null @@ -1,20 +0,0 @@ -// aux-build:auto_serialize_lib.rs -// xfail-fast:aux-build currently incompatible - -use std; -use auto_serialize_lib; -import std::prettyprint::serializer; -import std::ebml::serializer; -import std::ebml::deserializer; -import auto_serialize_lib::*; - -#[auto_serialize] -type uint_vec = [uint]; - -fn main() { - test_ser_and_deser([1u, 2u, 3u], - "[1u, 2u, 3u]", - uint_vec::serialize(_, _), - uint_vec::deserialize(_), - uint_vec::serialize(_, _)); -} \ No newline at end of file