8000 Merge pull request #48 from kentfredric/attempt-4 · unicode-rs/unicode-normalization@717e6c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 717e6c2

Browse files
authored
Merge pull request #48 from kentfredric/attempt-4
Migrate normalization tests to test/ to simplify pruning tests during shipping.
2 parents fc87399 + 0f4cb1e commit 717e6c2

File tree

8 files changed

+124
-101
lines changed

8 files changed

+124
-101
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ sudo: false
77
script:
88
- cargo build --verbose
99
- cargo test --verbose
10+
- cargo package
11+
- cd target/package/unicode-normalization-*
12+
- cargo test --verbose
1013
notifications:
1114
email:
1215
on_success: never

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Decomposition and Recomposition, as described in
1818
Unicode Standard Annex #15.
1919
"""
2020

21-
exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "src/normalization_tests.rs", "src/test.rs" ]
21+
exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ]
2222

2323
[dependencies]
2424
smallvec = "1.0"

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 norm F438 alization_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/tests.rs

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

0 commit comments

Comments
 (0)
0