From fe93995a5583eb39ed22da931a030192b88d7e9c Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 20 Nov 2019 03:57:38 +1300 Subject: [PATCH 1/4] Move "normalization" test data and dependent tests all into tests/ Leaves all other tests in place. Provides a #[doc(hidden)] shim for accessing/using otherwise private members from tests/ --- src/__test_api.rs | 13 ++++ src/lib.rs | 4 +- src/stream_safe.rs | 10 --- src/test.rs | 88 -------------------------- {src => tests}/normalization_tests.rs | 0 tests/stream_safe_normalization.rs | 17 +++++ tests/test_normalization.rs | 91 +++++++++++++++++++++++++++ 7 files changed, 123 insertions(+), 100 deletions(-) create mode 100644 src/__test_api.rs rename {src => tests}/normalization_tests.rs (100%) create mode 100644 tests/stream_safe_normalization.rs create mode 100644 tests/test_normalization.rs diff --git a/src/__test_api.rs b/src/__test_api.rs new file mode 100644 index 0000000..9deff6b --- /dev/null +++ b/src/__test_api.rs @@ -0,0 +1,13 @@ +// This crate comprises hacks and glue required to test private functions from tests/ +// +// Keep this as slim as possible. +// +// If you're caught using this outside this crates tests/, you get to clean up the mess. + +use crate::stream_safe::StreamSafe; +pub fn stream_safe(s: &str) -> String { + StreamSafe::new(s.chars()).collect() +} +pub mod quick_check { + pub use crate::quick_check::*; +} diff --git a/src/lib.rs b/src/lib.rs index 7a4b4e0..a86ade1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,8 +75,8 @@ mod tables; #[cfg(test)] mod test; -#[cfg(test)] -mod normalization_tests; +#[doc(hidden)] +pub mod __test_api; /// Methods for composing and decomposing characters. pub mod char { diff --git a/src/stream_safe.rs b/src/stream_safe.rs index 38bb42c..2cfcc36 100644 --- a/src/stream_safe.rs +++ b/src/stream_safe.rs @@ -111,7 +111,6 @@ mod tests { classify_nonstarters, }; use std::char; - use normalization_tests::NORMALIZATION_TESTS; use normalize::decompose_compatible; use lookups::canonical_combining_class; @@ -119,15 +118,6 @@ mod tests { StreamSafe::new(s.chars()).collect() } - #[test] - fn test_normalization_tests_unaffected() { - for test in NORMALIZATION_TESTS { - for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] { - assert_eq!(stream_safe(s), s); - } - } - } - #[test] fn test_simple() { let technically_okay = "Da\u{0300}\u{0301}\u{0302}\u{0303}\u{0304}\u{0305}\u{0306}\u{0307}\u{0308}\u{0309}\u{030a}\u{030b}\u{030c}\u{030d}\u{030e}\u{030f}\u{0310}\u{0311}\u{0312}\u{0313}\u{0314}\u{0315}\u{0316}\u{0317}\u{0318}\u{0319}\u{031a}\u{031b}\u{031c}\u{031d}ngerzone"; diff --git a/src/test.rs b/src/test.rs index 4c7d2eb..8aaadba 100644 --- a/src/test.rs +++ b/src/test.rs @@ -95,94 +95,6 @@ fn test_nfkc() { t!("a\u{300}\u{305}\u{315}\u{5ae}b", "\u{e0}\u{5ae}\u{305}\u{315}b"); } -#[test] -fn test_official() { - use normalization_tests::NORMALIZATION_TESTS; - macro_rules! normString { - ($method: ident, $input: expr) => { $input.$method().collect::() } - } - - for test in NORMALIZATION_TESTS { - // these invariants come from the CONFORMANCE section of - // http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt - { - let r1 = normString!(nfc, test.source); - let r2 = normString!(nfc, test.nfc); - let r3 = normString!(nfc, test.nfd); - let r4 = normString!(nfc, test.nfkc); - let r5 = normString!(nfc, test.nfkd); - assert_eq!(test.nfc, &r1[..]); - assert_eq!(test.nfc, &r2[..]); - assert_eq!(test.nfc, &r3[..]); - assert_eq!(test.nfkc, &r4[..]); - assert_eq!(test.nfkc, &r5[..]); - } - - { - let r1 = normString!(nfd, test.source); - let r2 = normString!(nfd, test.nfc); - let r3 = normString!(nfd, test.nfd); - let r4 = normString!(nfd, test.nfkc); - let r5 = normString!(nfd, test.nfkd); - assert_eq!(test.nfd, &r1[..]); - assert_eq!(test.nfd, &r2[..]); - assert_eq!(test.nfd, &r3[..]); - assert_eq!(test.nfkd, &r4[..]); - assert_eq!(test.nfkd, &r5[..]); - } - - { - let r1 = normString!(nfkc, test.source); - let r2 = normString!(nfkc, test.nfc); - let r3 = normString!(nfkc, test.nfd); - let r4 = normString!(nfkc, test.nfkc); - let r5 = normString!(nfkc, test.nfkd); - assert_eq!(test.nfkc, &r1[..]); - assert_eq!(test.nfkc, &r2[..]); - assert_eq!(test.nfkc, &r3[..]); - assert_eq!(test.nfkc, &r4[..]); - assert_eq!(test.nfkc, &r5[..]); - } - - { - let r1 = normString!(nfkd, test.source); - let r2 = normString!(nfkd, test.nfc); - let r3 = normString!(nfkd, test.nfd); - let r4 = normString!(nfkd, test.nfkc); - let r5 = normString!(nfkd, test.nfkd); - assert_eq!(test.nfkd, &r1[..]); - assert_eq!(test.nfkd, &r2[..]); - assert_eq!(test.nfkd, &r3[..]); - assert_eq!(test.nfkd, &r4[..]); - assert_eq!(test.nfkd, &r5[..]); - } - } -} - -#[test] -fn test_quick_check() { - use normalization_tests::NORMALIZATION_TESTS; - use quick_check; - for test in NORMALIZATION_TESTS { - assert!(quick_check::is_nfc(test.nfc)); - assert!(quick_check::is_nfd(test.nfd)); - assert!(quick_check::is_nfkc(test.nfkc)); - assert!(quick_check::is_nfkd(test.nfkd)); - if test.nfc != test.nfd { - assert!(!quick_check::is_nfc(test.nfd)); - assert!(!quick_check::is_nfd(test.nfc)); - } - if test.nfkc != test.nfc { - assert!(!quick_check::is_nfkc(test.nfc)); - assert!(quick_check::is_nfc(test.nfkc)); - } - if test.nfkd != test.nfd { - assert!(!quick_check::is_nfkd(test.nfd)); - assert!(quick_check::is_nfd(test.nfkd)); - } - } -} - #[test] fn test_is_combining_mark_ascii() { for cp in 0..0x7f { diff --git a/src/normalization_tests.rs b/tests/normalization_tests.rs similarity index 100% rename from src/normalization_tests.rs rename to tests/normalization_tests.rs diff --git a/tests/stream_safe_normalization.rs b/tests/stream_safe_normalization.rs new file mode 100644 index 0000000..55ba960 --- /dev/null +++ b/tests/stream_safe_normalization.rs @@ -0,0 +1,17 @@ +extern crate unicode_normalization; +use unicode_normalization::__test_api::{ + stream_safe, +}; + +mod normalization_tests; +use normalization_tests::NORMALIZATION_TESTS; + +#[test] +fn test_normalization_tests_unaffected() { + for test in NORMALIZATION_TESTS { + for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] { + assert_eq!(stream_safe(s), s); + } + } +} + diff --git a/tests/test_normalization.rs b/tests/test_normalization.rs new file mode 100644 index 0000000..356d07e --- /dev/null +++ b/tests/test_normalization.rs @@ -0,0 +1,91 @@ +extern crate unicode_normalization; +use unicode_normalization::UnicodeNormalization; +mod normalization_tests; +use normalization_tests::NORMALIZATION_TESTS; + +#[test] +fn test_official() { + macro_rules! normString { + ($method: ident, $input: expr) => { $input.$method().collect::() } + } + + for test in NORMALIZATION_TESTS { + // these invariants come from the CONFORMANCE section of + // http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt + { + let r1 = normString!(nfc, test.source); + let r2 = normString!(nfc, test.nfc); + let r3 = normString!(nfc, test.nfd); + let r4 = normString!(nfc, test.nfkc); + let r5 = normString!(nfc, test.nfkd); + assert_eq!(test.nfc, &r1[..]); + assert_eq!(test.nfc, &r2[..]); + assert_eq!(test.nfc, &r3[..]); + assert_eq!(test.nfkc, &r4[..]); + assert_eq!(test.nfkc, &r5[..]); + } + + { + let r1 = normString!(nfd, test.source); + let r2 = normString!(nfd, test.nfc); + let r3 = normString!(nfd, test.nfd); + let r4 = normString!(nfd, test.nfkc); + let r5 = normString!(nfd, test.nfkd); + assert_eq!(test.nfd, &r1[..]); + assert_eq!(test.nfd, &r2[..]); + assert_eq!(test.nfd, &r3[..]); + assert_eq!(test.nfkd, &r4[..]); + assert_eq!(test.nfkd, &r5[..]); + } + + { + let r1 = normString!(nfkc, test.source); + let r2 = normString!(nfkc, test.nfc); + let r3 = normString!(nfkc, test.nfd); + let r4 = normString!(nfkc, test.nfkc); + let r5 = normString!(nfkc, test.nfkd); + assert_eq!(test.nfkc, &r1[..]); + assert_eq!(test.nfkc, &r2[..]); + assert_eq!(test.nfkc, &r3[..]); + assert_eq!(test.nfkc, &r4[..]); + assert_eq!(test.nfkc, &r5[..]); + } + + { + let r1 = normString!(nfkd, test.source); + let r2 = normString!(nfkd, test.nfc); + let r3 = normString!(nfkd, test.nfd); + let r4 = normString!(nfkd, test.nfkc); + let r5 = normString!(nfkd, test.nfkd); + assert_eq!(test.nfkd, &r1[..]); + assert_eq!(test.nfkd, &r2[..]); + assert_eq!(test.nfkd, &r3[..]); + assert_eq!(test.nfkd, &r4[..]); + assert_eq!(test.nfkd, &r5[..]); + } + } +} + +#[test] +fn test_quick_check() { + use unicode_normalization::__test_api::quick_check; + for test in NORMALIZATION_TESTS { + assert!(quick_check::is_nfc(test.nfc)); + assert!(quick_check::is_nfd(test.nfd)); + assert!(quick_check::is_nfkc(test.nfkc)); + assert!(quick_check::is_nfkd(test.nfkd)); + if test.nfc != test.nfd { + assert!(!quick_check::is_nfc(test.nfd)); + assert!(!quick_check::is_nfd(test.nfc)); + } + if test.nfkc != test.nfc { + assert!(!quick_check::is_nfkc(test.nfc)); + assert!(quick_check::is_nfc(test.nfkc)); + } + if test.nfkd != test.nfd { + assert!(!quick_check::is_nfkd(test.nfd)); + assert!(quick_check::is_nfd(test.nfkd)); + } + } +} + From 830bebfd36a77bae5931d1d63a29cc53d0671587 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 20 Nov 2019 04:04:55 +1300 Subject: [PATCH 2/4] Tidy up test layout - Unify all tests/ into a single file to reduce the number of output targets during `cargo test` - This also avoids double-compiling the normalization_tests.rs - Move normalization_tests.rs to be a child of tests/data/ to avoid getting compiled as a test unit, and further removing useless output from cargo test --- tests/{ => data}/normalization_tests.rs | 0 tests/stream_safe_normalization.rs | 17 ----------------- tests/{test_normalization.rs => tests.rs} | 20 +++++++++++++++++--- 3 files changed, 17 insertions(+), 20 deletions(-) rename tests/{ => data}/normalization_tests.rs (100%) delete mode 100644 tests/stream_safe_normalization.rs rename tests/{test_normalization.rs => tests.rs} (89%) diff --git a/tests/normalization_tests.rs b/tests/data/normalization_tests.rs similarity index 100% rename from tests/normalization_tests.rs rename to tests/data/normalization_tests.rs diff --git a/tests/stream_safe_normalization.rs b/tests/stream_safe_normalization.rs deleted file mode 100644 index 55ba960..0000000 --- a/tests/stream_safe_normalization.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern crate unicode_normalization; -use unicode_normalization::__test_api::{ - stream_safe, -}; - -mod normalization_tests; -use normalization_tests::NORMALIZATION_TESTS; - -#[test] -fn test_normalization_tests_unaffected() { - for test in NORMALIZATION_TESTS { - for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] { - assert_eq!(stream_safe(s), s); - } - } -} - diff --git a/tests/test_normalization.rs b/tests/tests.rs similarity index 89% rename from tests/test_normalization.rs rename to tests/tests.rs index 356d07e..03531b0 100644 --- a/tests/test_normalization.rs +++ b/tests/tests.rs @@ -1,7 +1,22 @@ extern crate unicode_normalization; use unicode_normalization::UnicodeNormalization; -mod normalization_tests; -use normalization_tests::NORMALIZATION_TESTS; +use unicode_normalization::__test_api::{ + stream_safe, +}; + +mod data { + pub mod normalization_tests; +} +use data::normalization_tests::NORMALIZATION_TESTS; + +#[test] +fn test_normalization_tests_unaffected() { + for test in NORMALIZATION_TESTS { + for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] { + assert_eq!(stream_safe(s), s); + } + } +} #[test] fn test_official() { @@ -88,4 +103,3 @@ fn test_quick_check() { } } } - From 9cea0c836f82222f5a00e9bf8f4983f1720ba140 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 20 Nov 2019 04:07:04 +1300 Subject: [PATCH 3/4] Only strip tests/ in Cargo.toml Leaving integrated bundled tests working. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e4727c7..e4285ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ Decomposition and Recomposition, as described in Unicode Standard Annex #15. """ -exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "src/normalization_tests.rs", "src/test.rs" ] +exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ] [dependencies] smallvec = "0.6" \ No newline at end of file From 0f4cb1e0b50a802ed891e2fcc3748fac2fdc075f Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 20 Nov 2019 04:09:17 +1300 Subject: [PATCH 4/4] Add travis glue to test built package too --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8f11202..7bbfda1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,9 @@ sudo: false script: - cargo build --verbose - cargo test --verbose + - cargo package + - cd target/package/unicode-normalization-* + - cargo test --verbose notifications: email: on_success: never