|
4 | 4 | externcrate libfuzzer_sys; |
5 | 5 |
|
6 | 6 | use unicode_normalization::{ |
7 | | - is_nfc,is_nfc_quick, is_nfc_stream_safe,is_nfc_stream_safe_quick, is_nfd,is_nfd_quick, |
8 | | - is_nfd_stream_safe,is_nfd_stream_safe_quick, is_nfkc,is_nfkc_quick, is_nfkd,is_nfkd_quick, |
9 | | -IsNormalized,UnicodeNormalization, |
| 7 | + is_nfc,check_nfc_quick, is_nfc_stream_safe,check_nfc_stream_safe_quick, is_nfd,check_nfd_quick, |
| 8 | + is_nfd_stream_safe,check_nfd_stream_safe_quick, is_nfkc,check_nfkc_quick, is_nfkd,check_nfkd_quick, |
| 9 | +UnicodeNormalization, |
10 | 10 | }; |
11 | 11 |
|
12 | | -fnfrom_bool(is_normalized:bool) ->IsNormalized{ |
13 | | -if is_normalized{ |
14 | | -IsNormalized::Yes |
15 | | -}else{ |
16 | | -IsNormalized::No |
17 | | -} |
18 | | -} |
19 | | - |
20 | 12 | fuzz_target!(|input:String|{ |
21 | 13 | // The full predicates imply the quick predicates. |
22 | | - assert_ne!(is_nfc_quick(input.chars()), from_bool(!is_nfc(&input))); |
23 | | - assert_ne!(is_nfd_quick(input.chars()), from_bool(!is_nfd(&input))); |
24 | | - assert_ne!(is_nfkc_quick(input.chars()), from_bool(!is_nfkc(&input))); |
25 | | - assert_ne!(is_nfkd_quick(input.chars()), from_bool(!is_nfkd(&input))); |
| 14 | + assert_ne!(check_nfc_quick(&input).is_ok(),!is_nfc(&input)); |
| 15 | + assert_ne!(check_nfd_quick(&input).is_ok(),!is_nfd(&input)); |
| 16 | + assert_ne!(check_nfkc_quick(&input).is_ok(),!is_nfkc(&input)); |
| 17 | + assert_ne!(check_nfkd_quick(&input).is_ok(),!is_nfkd(&input)); |
26 | 18 | assert_ne!( |
27 | | -is_nfc_stream_safe_quick(input.chars()), |
28 | | -from_bool(!is_nfc_stream_safe(&input)) |
| 19 | +check_nfc_stream_safe_quick(&input).is_ok(), |
| 20 | + !is_nfc_stream_safe(&input) |
29 | 21 | ); |
30 | 22 | assert_ne!( |
31 | | -is_nfd_stream_safe_quick(input.chars()), |
32 | | -from_bool(!is_nfd_stream_safe(&input)) |
| 23 | +check_nfd_stream_safe_quick(&input).is_ok(), |
| 24 | + !is_nfd_stream_safe(&input) |
33 | 25 | ); |
34 | 26 |
|
35 | 27 | // Check NFC, NFD, NFKC, and NFKD normalization. |
36 | | -let nfc = input.chars().nfc().collect::<String>(); |
| 28 | +let nfc = input.nfc().collect::<String>(); |
37 | 29 | assert_eq!(nfc.is_empty(), input.is_empty()); |
38 | | -assert_ne!(is_nfc_quick(nfc.chars()),IsNormalized::No); |
| 30 | +assert!(check_nfc_quick(&nfc).is_ok()); |
39 | 31 | assert!(is_nfc(&nfc)); |
40 | 32 |
|
41 | | -let nfd = input.chars().nfd().collect::<String>(); |
| 33 | +let nfd = input.nfd().collect::<String>(); |
42 | 34 | assert!(nfd.len() >= nfc.len()); |
43 | | -assert_ne!(is_nfd_quick(nfd.chars()),IsNormalized::No); |
| 35 | +assert!(check_nfd_quick(&nfd).is_ok()); |
44 | 36 | assert!(is_nfd(&nfd)); |
45 | 37 |
|
46 | | -let nfkc = input.chars().nfkc().collect::<String>(); |
| 38 | +let nfkc = input.nfkc().collect::<String>(); |
47 | 39 | assert_eq!(nfkc.is_empty(), input.is_empty()); |
48 | | -assert_ne!(is_nfkc_quick(nfkc.chars()),IsNormalized::No); |
| 40 | +assert!(check_nfkc_quick(&nfkc).is_ok()); |
49 | 41 | assert!(is_nfkc(&nfkc)); |
50 | 42 |
|
51 | | -let nfkd = input.chars().nfkd().collect::<String>(); |
| 43 | +let nfkd = input.nfkd().collect::<String>(); |
52 | 44 | assert!(nfkd.len() >= nfkc.len()); |
53 | | -assert_ne!(is_nfkd_quick(nfkd.chars()),IsNormalized::No); |
| 45 | +assert!(check_nfkd_quick(&nfkd).is_ok()); |
54 | 46 | assert!(is_nfkd(&nfkd)); |
55 | 47 |
|
56 | 48 | // Check stream-safe. |
57 | | -let nfc_ss = nfc.chars().stream_safe().collect::<String>(); |
| 49 | +let nfc_ss = nfc.stream_safe().collect::<String>(); |
58 | 50 | assert!(nfc_ss.len() >= nfc.len()); |
59 | | -assert_ne!(is_nfc_stream_safe_quick(nfc_ss.chars()),IsNormalized::No); |
| 51 | +assert!(check_nfc_stream_safe_quick(&nfc_ss).is_ok()); |
60 | 52 | assert!(is_nfc_stream_safe(&nfc_ss)); |
61 | 53 |
|
62 | | -let nfd_ss = nfd.chars().stream_safe().collect::<String>(); |
| 54 | +let nfd_ss = nfd.stream_safe().collect::<String>(); |
63 | 55 | assert!(nfd_ss.len() >= nfd.len()); |
64 | | -assert_ne!(is_nfd_stream_safe_quick(nfd_ss.chars()),IsNormalized::No); |
| 56 | +assert!(check_nfd_stream_safe_quick(&nfd_ss).is_ok()); |
65 | 57 | assert!(is_nfd_stream_safe(&nfd_ss)); |
66 | 58 |
|
67 | 59 | // Check that NFC and NFD preserve stream-safe. |
68 | | -let ss_nfc = input.chars().stream_safe().nfc().collect::<String>(); |
| 60 | +let ss_nfc = input.stream_safe().nfc().collect::<String>(); |
69 | 61 | assert_eq!(ss_nfc.is_empty(), input.is_empty()); |
70 | | -assert_ne!(is_nfc_stream_safe_quick(ss_nfc.chars()),IsNormalized::No); |
| 62 | +assert!(check_nfc_stream_safe_quick(&ss_nfc).is_ok()); |
71 | 63 | assert!(is_nfc_stream_safe(&ss_nfc)); |
72 | 64 |
|
73 | | -let ss_nfd = input.chars().stream_safe().nfd().collect::<String>(); |
| 65 | +let ss_nfd = input.stream_safe().nfd().collect::<String>(); |
74 | 66 | assert_eq!(ss_nfd.is_empty(), input.is_empty()); |
75 | | -assert_ne!(is_nfd_stream_safe_quick(ss_nfd.chars()),IsNormalized::No); |
| 67 | +assert!(check_nfd_stream_safe_quick(&ss_nfd).is_ok()); |
76 | 68 | assert!(is_nfd_stream_safe(&ss_nfd)); |
77 | 69 | }); |