From 638139b7daa207a1751ef98b52c61cc15fd9403a Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 26 Feb 2023 04:29:15 -0800 Subject: [PATCH] Start using rstest --- Cargo.toml | 3 +++ tests/json_parser.rs | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e7b28d6..b3061b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] arbitrary = "1.2.0" proptest = "1.0.0" + +[dev-dependencies] +rstest = "0.16.0" diff --git a/tests/json_parser.rs b/tests/json_parser.rs index 95d4972..a5fe16a 100644 --- a/tests/json_parser.rs +++ b/tests/json_parser.rs @@ -7,6 +7,8 @@ use parser_combinator::Representation; use proptest::prelude::*; +use rstest::*; + proptest! { #[test] fn doesnt_crash(s in "\\PC*") { @@ -237,12 +239,13 @@ fn parse_json_document() { assert!(parsed_json.is_ok()); } -#[test] -fn test_representations() { - assert_eq!(json_null().representation(), Representation::new("null")); - assert_eq!( - json_bool().representation(), - Representation::new("true | false") - ); - assert_eq!(json_number().representation(), Representation::new("- | ε (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+ . (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+ | ε | . (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+")); +#[rstest] +#[case(json_null().representation(), Representation::new("null"))] +#[case(json_bool().representation(), Representation::new("true | false"))] +#[case(json_number().representation(), Representation::new("- | ε (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+ . (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+ | ε | . (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | )+"))] +fn representations_test( + #[case] parser_representation: Representation, + #[case] expected: Representation, +) { + assert_eq!(parser_representation, expected); }