Skip to content

Commit fe93995

Browse files
committed
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/
1 parent c469e87 commit fe93995

File tree

7 files changed

+123
-100
lines changed

7 files changed

+123
-100
lines changed

src/__test_api.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This crate comprises hacks and glue required to test private functions from tests/
2+
//
3+
// Keep this as slim as possible.
4+
//
5+
// If you're caught using this outside this crates tests/, you get to clean up the mess.
6+
7+
use crate::stream_safe::StreamSafe;
8+
pub fn stream_safe(s: &str) -> String {
9+
StreamSafe::new(s.chars()).collect()
10+
}
11+
pub mod quick_check {
12+
pub use crate::quick_check::*;
13+
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ mod tables;
7575

7676
#[cfg(test)]
7777
mod test;
78-
#[cfg(test)]
79-
mod normalization_tests;
78+
#[doc(hidden)]
79+
pub mod __test_api;
8080

8181
/// Methods for composing and decomposing characters.
8282
pub mod char {

src/stream_safe.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,13 @@ mod tests {
111111
classify_nonstarters,
112112
};
113113
use std::char;
114-
use normalization_tests::NORMALIZATION_TESTS;
115114
use normalize::decompose_compatible;
116115
use lookups::canonical_combining_class;
117116

118117
fn stream_safe(s: &str) -> String {
119118
StreamSafe::new(s.chars()).collect()
120119
}
121120

122-
#[test]
123-
fn test_normalization_tests_unaffected() {
124-
for test in NORMALIZATION_TESTS {
125-
for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] {
126-
assert_eq!(stream_safe(s), s);
127-
}
128-
}
129-
}
130-
131121
#[test]
132122
fn test_simple() {
133123
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";

src/test.rs

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -95,94 +95,6 @@ fn test_nfkc() {
9595
t!("a\u{300}\u{305}\u{315}\u{5ae}b", "\u{e0}\u{5ae}\u{305}\u{315}b");
9696
}
9797

98-
#[test]
99-
fn test_official() {
100-
use normalization_tests::NORMALIZATION_TESTS;
101-
macro_rules! normString {
102-
($method: ident, $input: expr) => { $input.$method().collect::<String>() }
103-
}
104-
105-
for test in NORMALIZATION_TESTS {
106-
// these invariants come from the CONFORMANCE section of
107-
// http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt
108-
{
109-
let r1 = normString!(nfc, test.source);
110-
let r2 = normString!(nfc, test.nfc);
111-
let r3 = normString!(nfc, test.nfd);
112-
let r4 = normString!(nfc, test.nfkc);
113-
let r5 = normString!(nfc, test.nfkd);
114-
assert_eq!(test.nfc, &r1[..]);
115-
assert_eq!(test.nfc, &r2[..]);
116-
assert_eq!(test.nfc, &r3[..]);
117-
assert_eq!(test.nfkc, &r4[..]);
118-
assert_eq!(test.nfkc, &r5[..]);
119-
}
120-
121-
{
122-
let r1 = normString!(nfd, test.source);
123-
let r2 = normString!(nfd, test.nfc);
124-
let r3 = normString!(nfd, test.nfd);
125-
let r4 = normString!(nfd, test.nfkc);
126-
let r5 = normString!(nfd, test.nfkd);
127-
assert_eq!(test.nfd, &r1[..]);
128-
assert_eq!(test.nfd, &r2[..]);
129-
assert_eq!(test.nfd, &r3[..]);
130-
assert_eq!(test.nfkd, &r4[..]);
131-
assert_eq!(test.nfkd, &r5[..]);
132-
}
133-
134-
{
135-
let r1 = normString!(nfkc, test.source);
136-
let r2 = normString!(nfkc, test.nfc);
137-
let r3 = normString!(nfkc, test.nfd);
138-
let r4 = normString!(nfkc, test.nfkc);
139-
let r5 = normString!(nfkc, test.nfkd);
140-
assert_eq!(test.nfkc, &r1[..]);
141-
assert_eq!(test.nfkc, &r2[..]);
142-
assert_eq!(test.nfkc, &r3[..]);
143-
assert_eq!(test.nfkc, &r4[..]);
144-
assert_eq!(test.nfkc, &r5[..]);
145-
}
146-
147-
{
148-
let r1 = normString!(nfkd, test.source);
149-
let r2 = normString!(nfkd, test.nfc);
150-
let r3 = normString!(nfkd, test.nfd);
151-
let r4 = normString!(nfkd, test.nfkc);
152-
let r5 = normString!(nfkd, test.nfkd);
153-
assert_eq!(test.nfkd, &r1[..]);
154-
assert_eq!(test.nfkd, &r2[..]);
155-
assert_eq!(test.nfkd, &r3[..]);
156-
assert_eq!(test.nfkd, &r4[..]);
157-
assert_eq!(test.nfkd, &r5[..]);
158-
}
159-
}
160-
}
161-
162-
#[test]
163-
fn test_quick_check() {
164-
use normalization_tests::NORMALIZATION_TESTS;
165-
use quick_check;
166-
for test in NORMALIZATION_TESTS {
167-
assert!(quick_check::is_nfc(test.nfc));
168-
assert!(quick_check::is_nfd(test.nfd));
169-
assert!(quick_check::is_nfkc(test.nfkc));
170-
assert!(quick_check::is_nfkd(test.nfkd));
171-
if test.nfc != test.nfd {
172-
assert!(!quick_check::is_nfc(test.nfd));
173-
assert!(!quick_check::is_nfd(test.nfc));
174-
}
175-
if test.nfkc != test.nfc {
176-
assert!(!quick_check::is_nfkc(test.nfc));
177-
assert!(quick_check::is_nfc(test.nfkc));
178-
}
179-
if test.nfkd != test.nfd {
180-
assert!(!quick_check::is_nfkd(test.nfd));
181-
assert!(quick_check::is_nfd(test.nfkd));
182-
}
183-
}
184-
}
185-
18698
#[test]
18799
fn test_is_combining_mark_ascii() {
188100
for cp in 0..0x7f {
File renamed without changes.

tests/stream_safe_normalization.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extern crate unicode_normalization;
2+
use unicode_normalization::__test_api::{
3+
stream_safe,
4+
};
5+
6+
mod normalization_tests;
7+
use normalization_tests::NORMALIZATION_TESTS;
8+
9+
#[test]
10+
fn test_normalization_tests_unaffected() {
11+
for test in NORMALIZATION_TESTS {
12+
for &s in &[test.source, test.nfc, test.nfd, test.nfkc, test.nfkd] {
13+
assert_eq!(stream_safe(s), s);
14+
}
15+
}
16+
}
17+

tests/test_normalization.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
extern crate unicode_normalization;
2+
use unicode_normalization::UnicodeNormalization;
3+
mod normalization_tests;
4+
use normalization_tests::NORMALIZATION_TESTS;
5+
6+
#[test]
7+
fn test_official() {
8+
macro_rules! normString {
9+
($method: ident, $input: expr) => { $input.$method().collect::<String>() }
10+
}
11+
12+
for test in NORMALIZATION_TESTS {
13+
// these invariants come from the CONFORMANCE section of
14+
// http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt
15+
{
16+
let r1 = normString!(nfc, test.source);
17+
let r2 = normString!(nfc, test.nfc);
18+
let r3 = normString!(nfc, test.nfd);
19+
let r4 = normString!(nfc, test.nfkc);
20+
let r5 = normString!(nfc, test.nfkd);
21+
assert_eq!(test.nfc, &r1[..]);
22+
assert_eq!(test.nfc, &r2[..]);
23+
assert_eq!(test.nfc, &r3[..]);
24+
assert_eq!(test.nfkc, &r4[..]);
25+
assert_eq!(test.nfkc, &r5[..]);
26+
}
27+
28+
{
29+
let r1 = normString!(nfd, test.source);
30+
let r2 = normString!(nfd, test.nfc);
31+
let r3 = normString!(nfd, test.nfd);
32+
let r4 = normString!(nfd, test.nfkc);
33+
let r5 = normString!(nfd, test.nfkd);
34+
assert_eq!(test.nfd, &r1[..]);
35+
assert_eq!(test.nfd, &r2[..]);
36+
assert_eq!(test.nfd, &r3[..]);
37+
assert_eq!(test.nfkd, &r4[..]);
38+
assert_eq!(test.nfkd, &r5[..]);
39+
}
40+
41+
{
42+
let r1 = normString!(nfkc, test.source);
43+
let r2 = normString!(nfkc, test.nfc);
44+
let r3 = normString!(nfkc, test.nfd);
45+
let r4 = normString!(nfkc, test.nfkc);
46+
let r5 = normString!(nfkc, test.nfkd);
47+
assert_eq!(test.nfkc, &r1[..]);
48+
assert_eq!(test.nfkc, &r2[..]);
49+
assert_eq!(test.nfkc, &r3[..]);
50+
assert_eq!(test.nfkc, &r4[..]);
51+
assert_eq!(test.nfkc, &r5[..]);
52+
}
53+
54+
{
55+
let r1 = normString!(nfkd, test.source);
56+
let r2 = normString!(nfkd, test.nfc);
57+
let r3 = normString!(nfkd, test.nfd);
58+
let r4 = normString!(nfkd, test.nfkc);
59+
let r5 = normString!(nfkd, test.nfkd);
60+
assert_eq!(test.nfkd, &r1[..]);
61+
assert_eq!(test.nfkd, &r2[..]);
62+
assert_eq!(test.nfkd, &r3[..]);
63+
assert_eq!(test.nfkd, &r4[..]);
64+
assert_eq!(test.nfkd, &r5[..]);
65+
}
66+
}
67+
}
68+
69+
#[test]
70+
fn test_quick_check() {
71+
use unicode_normalization::__test_api::quick_check;
72+
for test in NORMALIZATION_TESTS {
73+
assert!(quick_check::is_nfc(test.nfc));
74+
assert!(quick_check::is_nfd(test.nfd));
75+
assert!(quick_check::is_nfkc(test.nfkc));
76+
assert!(quick_check::is_nfkd(test.nfkd));
77+
if test.nfc != test.nfd {
78+
assert!(!quick_check::is_nfc(test.nfd));
79+
assert!(!quick_check::is_nfd(test.nfc));
80+
}
81+
if test.nfkc != test.nfc {
82+
assert!(!quick_check::is_nfkc(test.nfc));
83+
assert!(quick_check::is_nfc(test.nfkc));
84+
}
85+
if test.nfkd != test.nfd {
86+
assert!(!quick_check::is_nfkd(test.nfd));
87+
assert!(quick_check::is_nfd(test.nfkd));
88+
}
89+
}
90+
}
91+

0 commit comments

Comments
 (0)