From e493ffc6fb50386352b372a988ab7c1e11c5dc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 21 Nov 2024 20:41:56 +0100 Subject: [PATCH] parsers: add xso test module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Separate from the macro_tests module because it doesn't actually test macros, it uses it as a convenience. Signed-off-by: Maxime “pep” Buquet --- parsers/src/util/mod.rs | 2 ++ parsers/src/util/xso_tests.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 parsers/src/util/xso_tests.rs diff --git a/parsers/src/util/mod.rs b/parsers/src/util/mod.rs index 20591702..8b07cfbd 100644 --- a/parsers/src/util/mod.rs +++ b/parsers/src/util/mod.rs @@ -10,3 +10,5 @@ mod macros; #[cfg(test)] mod macro_tests; +#[cfg(test)] +mod xso_tests; diff --git a/parsers/src/util/xso_tests.rs b/parsers/src/util/xso_tests.rs new file mode 100644 index 00000000..e6de7f61 --- /dev/null +++ b/parsers/src/util/xso_tests.rs @@ -0,0 +1,28 @@ +// Copyright (c) 2024 Maxime “pep” Buquet +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +use xso::{AsXml, FromXml, PrintRawXml}; + +static NS1: &str = "urn:example:ns1"; + +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = NS1, name = "text")] +struct TextString { + #[xml(text)] + text: String, +} + +#[test] +fn printrawxml() { + let text = TextString { + text: String::from("hello world"), + }; + let display = format!("{}", PrintRawXml(&text)); + assert_eq!( + display, + "b\"hello world\"" + ); +}