Debian Codegraph @

debian/rust-vendor/icu_segmenter/tests/locale.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 use icu_locale_core::langid;
6 use icu_segmenter::options::{SentenceBreakOptions, WordBreakOptions};
7 use icu_segmenter::*;
8
9 include!("helpers.rs.raw");
10
11 // Additional segmenter tests with locale.
12
13 #[test]
14 fn word_break_with_locale() {
15 let mut options = WordBreakOptions::default();
16
17 let langid = langid!("sv");
18 options.content_locale = Some(&langid);
19 check_word(
20 "hello:world",
21 &["hello:world"],
22 WordSegmenter::try_new_auto(options).unwrap().as_borrowed(),
23 );
24 check_word("hello:world", &["hello:world"], {
25 let mut s = WordSegmenter::new_neo_for_non_complex_scripts(Default::default());
26 s.load_auto();
27 s
28 });
29
30 check_word("hello:world", &["hello:world"], {
31 let mut s = WordSegmenter::new_neo_for_non_complex_scripts(Default::default());
32 s.load_auto();
33 s
34 });
35 }
36
37 #[test]
38 fn sentence_break_with_locale() {
39 // SB11 is different because U+0x3B is STerm on Greek.
40 let mut options = SentenceBreakOptions::default();
41
42 let langid = langid!("el");
43 options.content_locale = Some(&langid);
44 check_sentence(
45 "hello; world",
46 &["hello; ", "world"],
47 SentenceSegmenter::try_new(options).unwrap().as_borrowed(),
48 );
49 check_sentence(
50 "hello; world",
51 &["hello; ", "world"],
52 SentenceSegmenter::try_new_neo(options)
53 .unwrap()
54 .as_borrowed(),
55 );
56
57 let langid = langid!("en");
58 options.content_locale = Some(&langid);
59 check_sentence(
60 "hello; world",
61 &["hello; world"],
62 SentenceSegmenter::try_new(options).unwrap().as_borrowed(),
63 );
64 check_sentence(
65 "hello; world",
66 &["hello; world"],
67 SentenceSegmenter::try_new_neo(options)
68 .unwrap()
69 .as_borrowed(),
70 );
71 }