From 95552cb48f3927d7db7f06afac9130f2a601ae29 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 23 Aug 2024 09:15:35 -0500 Subject: [PATCH] test(varcon): Make it easier to update tests --- Cargo.lock | 66 +- crates/varcon-core/Cargo.toml | 3 + crates/varcon-core/src/parser.rs | 1464 +++++++++++++++++++++++++++--- 3 files changed, 1376 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7d67bd..21b48ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1134,9 +1134,9 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "snapbox" -version = "0.6.16" +version = "0.6.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "027c936207f85d10d015e21faf5c676c7e08c453ed371adf55c0874c443ca77a" +checksum = "840b73eb3148bc3cbc10ebe00ec9bc6d96033e658d022c4adcbf3f35596fd64a" dependencies = [ "anstream", "anstyle", @@ -1151,7 +1151,7 @@ dependencies = [ "tempfile", "wait-timeout", "walkdir", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1504,6 +1504,7 @@ name = "varcon-core" version = "4.0.10" dependencies = [ "enumflags2", + "snapbox", "winnow", ] @@ -1591,11 +1592,11 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.6", ] [[package]] @@ -1615,17 +1616,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -1636,9 +1638,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1648,9 +1650,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1660,9 +1662,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1672,9 +1680,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1684,9 +1692,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1696,9 +1704,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1708,9 +1716,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/crates/varcon-core/Cargo.toml b/crates/varcon-core/Cargo.toml index 9724e93..5bae14a 100644 --- a/crates/varcon-core/Cargo.toml +++ b/crates/varcon-core/Cargo.toml @@ -25,3 +25,6 @@ enumflags2 = { version = "0.7", optional = true } [lints] workspace = true + +[dev-dependencies] +snapbox = "0.6.17" diff --git a/crates/varcon-core/src/parser.rs b/crates/varcon-core/src/parser.rs index 377e997..bd4b10e 100644 --- a/crates/varcon-core/src/parser.rs +++ b/crates/varcon-core/src/parser.rs @@ -27,9 +27,13 @@ impl<'i> Iterator for ClusterIter<'i> { mod test_cluster_iter { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_single() { - let iter = ClusterIter::new( + let actual = ClusterIter::new( "# acknowledgment (level 35) A Cv: acknowledgment / Av B C: acknowledgement A Cv: acknowledgments / Av B C: acknowledgements @@ -37,12 +41,171 @@ A Cv: acknowledgment's / Av B C: acknowledgement's ", ); - assert_eq!(iter.count(), 1); + assert_data_eq!( + actual.collect::>().to_debug(), + str![[r#" +[ + Cluster { + header: Some( + "acknowledgment (level 35)", + ), + entries: [ + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgments", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgements", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + ], + notes: [], + }, +] + +"#]] + ); } #[test] fn test_multiple() { - let iter = ClusterIter::new( + let actual = ClusterIter::new( "# acknowledgment (level 35) A Cv: acknowledgment / Av B C: acknowledgement A Cv: acknowledgments / Av B C: acknowledgements @@ -55,7 +218,318 @@ A Cv: acknowledgment's / Av B C: acknowledgement's ", ); - assert_eq!(iter.count(), 2); + assert_data_eq!( + actual.collect::>().to_debug(), + str![[r#" +[ + Cluster { + header: Some( + "acknowledgment (level 35)", + ), + entries: [ + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgments", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgements", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + ], + notes: [], + }, + Cluster { + header: Some( + "acknowledgment (level 35)", + ), + entries: [ + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgments", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgements", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + ], + notes: [], + }, +] + +"#]] + ); } } @@ -106,6 +580,10 @@ impl Cluster { mod test_cluster { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_basic() { let (input, actual) = Cluster::parse_ @@ -118,13 +596,171 @@ A Cv: acknowledgment's / Av B C: acknowledgement's ", ) .unwrap(); - assert_eq!(input, "\n"); - assert_eq!( - actual.header, - Some("acknowledgment (level 35)".to_owned()) + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Cluster { + header: Some( + "acknowledgment (level 35)", + ), + entries: [ + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgments", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgements", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + ], + notes: [], +} + +"#]] ); - assert_eq!(actual.entries.len(), 3); - assert_eq!(actual.notes.len(), 0); } #[test] @@ -141,13 +777,174 @@ A B C: coloration's / B. Cv: colouration's ", ) .unwrap(); - assert_eq!(input, "\n"); - assert_eq!( - actual.header, - Some("coloration (level 50)".to_owned()) + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Cluster { + header: Some( + "coloration (level 50)", + ), + entries: [ + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "coloration", + }, + Variant { + types: [ + Type { + category: BritishIse, + tag: Some( + Eq, + ), + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "colouration", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "colorations", + }, + Variant { + types: [ + Type { + category: BritishIse, + tag: Some( + Eq, + ), + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "colourations", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "coloration's", + }, + Variant { + types: [ + Type { + category: BritishIse, + tag: Some( + Eq, + ), + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "colouration's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, + }, + ], + notes: [ + "OED has coloration as the preferred spelling and discolouration as a", + "variant for British Engl or some reason", + ], +} + +"#]] ); - assert_eq!(actual.entries.len(), 3); - assert_eq!(actual.notes.len(), 2); } } @@ -229,6 +1026,10 @@ mod test_entry { #![allow(clippy::bool_assert_comparison)] use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_variant_only() { // Having nothing after `A` causes an incomplete parse. Shouldn't be a problem for my use @@ -236,12 +1037,67 @@ mod test_entry { let (input, actual) = Entry::parse_ .parse_peek("A Cv: acknowledgment's / Av B C: acknowledgement's\n") .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 2); - assert_eq!(actual.pos, None); - assert_eq!(actual.archaic, false); - assert_eq!(actual.note, false); - assert_eq!(actual.description, None); + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "acknowledgement's", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: None, +} + +"#]] + ); } #[test] @@ -251,12 +1107,55 @@ mod test_entry { let (input, actual) = Entry::parse_ .parse_peek("A C: prize / B: prise | otherwise\n") .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 2); - assert_eq!(actual.pos, None); - assert_eq!(actual.archaic, false); - assert_eq!(actual.note, false); - assert_eq!(actual.description, Some("otherwise".to_owned())); + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "prize", + }, + Variant { + types: [ + Type { + category: BritishIse, + tag: None, + num: None, + }, + ], + word: "prise", + }, + ], + pos: None, + archaic: false, + note: false, + description: Some( + "otherwise", + ), + comment: None, +} + +"#]] + ); } #[test] @@ -266,12 +1165,69 @@ mod test_entry { let (input, actual) = Entry::parse_ .parse_peek("A B C: practice / AV Cv: practise | \n") .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 2); - assert_eq!(actual.pos, Some(Pos::Noun)); - assert_eq!(actual.archaic, false); - assert_eq!(actual.note, false); - assert_eq!(actual.description, None); + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: None, + num: None, + }, + ], + word: "practice", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Seldom, + ), + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "practise", + }, + ], + pos: Some( + Noun, + ), + archaic: false, + note: false, + description: None, + comment: None, +} + +"#]] + ); } #[test] @@ -281,12 +1237,57 @@ mod test_entry { let (input, actual) = Entry::parse_ .parse_peek("A: bark / Av B: barque | (-) ship\n") .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 2); - assert_eq!(actual.pos, None); - assert_eq!(actual.archaic, true); - assert_eq!(actual.note, false); - assert_eq!(actual.description, Some("ship".to_owned())); + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + ], + word: "bark", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Variant, + ), + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + ], + word: "barque", + }, + ], + pos: None, + archaic: true, + note: false, + description: Some( + "ship", + ), + comment: None, +} + +"#]] + ); } #[test] @@ -296,12 +1297,40 @@ mod test_entry { let (input, actual) = Entry::parse_ .parse_peek("_: cabbies | -- plural\n") .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 1); - assert_eq!(actual.pos, None); - assert_eq!(actual.archaic, false); - assert_eq!(actual.note, true); - assert_eq!(actual.description, Some("plural".to_owned())); + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: Other, + tag: None, + num: None, + }, + ], + word: "cabbies", + }, + ], + pos: None, + archaic: false, + note: true, + description: Some( + "plural", + ), + comment: None, +} + +"#]] + ); } #[test] @@ -310,15 +1339,63 @@ mod test_entry { "A B: accursed / AV B-: accurst # ODE: archaic, M-W: 'or' but can find little evidence of use\n", ) .unwrap(); - assert_eq!(input, "\n"); - assert_eq!(actual.variants.len(), 2); - assert_eq!(actual.pos, None); - assert_eq!(actual.archaic, false); - assert_eq!(actual.note, false); - assert_eq!(actual.description, None); - assert_eq!( - actual.comment, - Some("ODE: archaic, M-W: 'or' but can find little evidence of use".to_owned()) + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Entry { + variants: [ + Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: BritishIse, + tag: None, + num: None, + }, + ], + word: "accursed", + }, + Variant { + types: [ + Type { + category: American, + tag: Some( + Seldom, + ), + num: None, + }, + Type { + category: BritishIse, + tag: Some( + Possible, + ), + num: None, + }, + ], + word: "accurst", + }, + ], + pos: None, + archaic: false, + note: false, + description: None, + comment: Some( + "ODE: archaic, M-W: 'or' but can find little evidence of use", + ), +} + +"#]] ); } } @@ -354,28 +1431,39 @@ fn word(input: &mut &str) -> PResult { mod test_variant { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_valid() { // Having nothing after `A` causes an incomplete parse. Shouldn't be a problem for my use // cases. let (input, actual) = Variant::parse_.parse_peek("A Cv: acknowledgment ").unwrap(); - assert_eq!(input, " "); - assert_eq!( - actual.types, - vec![ - Type { - category: Category::American, - tag: None, - num: None, - }, - Type { - category: Category::Canadian, - tag: Some(Tag::Variant), - num: None, - } - ] + assert_data_eq!(input, str![" "]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment", +} + +"#]] ); - assert_eq!(actual.word, "acknowledgment"); } #[test] @@ -383,38 +1471,58 @@ mod test_variant { let (input, actual) = Variant::parse_ .parse_peek("A Cv: acknowledgment's / Av B C: acknowledgement's") .unwrap(); - assert_eq!(input, " / Av B C: acknowledgement's"); - assert_eq!( - actual.types, - vec![ - Type { - category: Category::American, - tag: None, - num: None, - }, - Type { - category: Category::Canadian, - tag: Some(Tag::Variant), - num: None, - } - ] + assert_data_eq!(input, str![" / Av B C: acknowledgement's"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Variant { + types: [ + Type { + category: American, + tag: None, + num: None, + }, + Type { + category: Canadian, + tag: Some( + Variant, + ), + num: None, + }, + ], + word: "acknowledgment's", +} + +"#]] ); - assert_eq!(actual.word, "acknowledgment's"); } #[test] fn test_underscore() { let (input, actual) = Variant::parse_.parse_peek("_: air_gun\n").unwrap(); - assert_eq!(input, "\n"); - assert_eq!( - actual.types, - vec![Type { - category: Category::Other, - tag: None, - num: None, - },] + assert_data_eq!( + input, + str![[r#" + + +"#]] + ); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Variant { + types: [ + Type { + category: Other, + tag: None, + num: None, + }, + ], + word: "air gun", +} + +"#]] ); - assert_eq!(actual.word, "air gun"); } } @@ -440,45 +1548,97 @@ impl Type { mod test_type { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_valid() { // Having nothing after `A` causes an incomplete parse. Shouldn't be a problem for my use // cases. let (input, actual) = Type::parse_.parse_peek("A ").unwrap(); - assert_eq!(input, " "); - assert_eq!(actual.category, Category::American); - assert_eq!(actual.tag, None); - assert_eq!(actual.num, None); + assert_data_eq!(input, str![" "]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Type { + category: American, + tag: None, + num: None, +} + +"#]] + ); let (input, actual) = Type::parse_.parse_peek("Bv ").unwrap(); - assert_eq!(input, " "); - assert_eq!(actual.category, Category::BritishIse); - assert_eq!(actual.tag, Some(Tag::Variant)); - assert_eq!(actual.num, None); + assert_data_eq!(input, str![" "]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Type { + category: BritishIse, + tag: Some( + Variant, + ), + num: None, +} + +"#]] + ); } #[test] fn test_extra() { let (input, actual) = Type::parse_.parse_peek("Z foobar").unwrap(); - assert_eq!(input, " foobar"); - assert_eq!(actual.category, Category::BritishIze); - assert_eq!(actual.tag, None); - assert_eq!(actual.num, None); + assert_data_eq!(input, str![" foobar"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Type { + category: BritishIze, + tag: None, + num: None, +} + +"#]] + ); let (input, actual) = Type::parse_.parse_peek("C- foobar").unwrap(); - assert_eq!(input, " foobar"); - assert_eq!(actual.category, Category::Canadian); - assert_eq!(actual.tag, Some(Tag::Possible)); - assert_eq!(actual.num, None); + assert_data_eq!(input, str![" foobar"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Type { + category: Canadian, + tag: Some( + Possible, + ), + num: None, +} + +"#]] + ); } #[test] fn test_num() { let (input, actual) = Type::parse_.parse_peek("Av1 ").unwrap(); - assert_eq!(input, " "); - assert_eq!(actual.category, Category::American); - assert_eq!(actual.tag, Some(Tag::Variant)); - assert_eq!(actual.num, Some(1)); + assert_data_eq!(input, str![" "]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Type { + category: American, + tag: Some( + Variant, + ), + num: Some( + 1, + ), +} + +"#]] + ); } } @@ -510,18 +1670,34 @@ impl Category { mod test_category { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_valid() { let (input, actual) = Category::parse_.parse_peek("A").unwrap(); - assert_eq!(input, ""); - assert_eq!(actual, Category::American); + assert_data_eq!(input, str![]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +American + +"#]] + ); } #[test] fn test_extra() { let (input, actual) = Category::parse_.parse_peek("_ foobar").unwrap(); - assert_eq!(input, " foobar"); - assert_eq!(actual, Category::Other); + assert_data_eq!(input, str![" foobar"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Other + +"#]] + ); } } @@ -552,18 +1728,34 @@ impl Tag { mod test_tag { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_valid() { let (input, actual) = Tag::parse_.parse_peek(".").unwrap(); - assert_eq!(input, ""); - assert_eq!(actual, Tag::Eq); + assert_data_eq!(input, str![]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Eq + +"#]] + ); } #[test] fn test_extra() { let (input, actual) = Tag::parse_.parse_peek("x foobar").unwrap(); - assert_eq!(input, " foobar"); - assert_eq!(actual, Tag::Improper); + assert_data_eq!(input, str![" foobar"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Improper + +"#]] + ); } } @@ -590,18 +1782,34 @@ impl Pos { mod test_pos { use super::*; + use snapbox::assert_data_eq; + use snapbox::str; + use snapbox::ToDebug; + #[test] fn test_valid() { let (input, actual) = Pos::parse_.parse_peek("").unwrap(); - assert_eq!(input, ""); - assert_eq!(actual, Pos::Noun); + assert_data_eq!(input, str![]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Noun + +"#]] + ); } #[test] fn test_extra() { let (input, actual) = Pos::parse_.parse_peek(" foobar").unwrap(); - assert_eq!(input, " foobar"); - assert_eq!(actual, Pos::Adjective); + assert_data_eq!(input, str![" foobar"]); + assert_data_eq!( + actual.to_debug(), + str![[r#" +Adjective + +"#]] + ); } }