Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit233de0a

Browse files
authored
Merge pull request#21 from unicode-rs/fmt
Add Display impl for AugmentedScriptSet
2 parents7ea5530 +c2f0cf6 commit233de0a

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

‎src/mixed_script.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ impl Debug for AugmentedScriptSet {
105105
}
106106
}
107107

108+
impl fmt::DisplayforAugmentedScriptSet{
109+
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
110+
ifself.is_empty(){
111+
write!(f,"Empty")?;
112+
}elseifself.is_all(){
113+
write!(f,"All")?;
114+
}else{
115+
letmut first_entry =true;
116+
let hanb =ifself.hanb{
117+
Some("Han with Bopomofo")
118+
}else{
119+
None
120+
};
121+
let jpan =ifself.jpan{Some("Japanese")}else{None};
122+
let kore =ifself.kore{Some("Korean")}else{None};
123+
for writing_systeminNone
124+
.into_iter()
125+
.chain(hanb)
126+
.chain(jpan)
127+
.chain(kore)
128+
.chain(self.base.iter().map(Script::full_name))
129+
{
130+
if !first_entry{
131+
write!(f,", ")?;
132+
}else{
133+
first_entry =false;
134+
}
135+
write!(f,"{}", writing_system)?;
136+
}
137+
}
138+
Ok(())
139+
}
140+
}
141+
108142
implAugmentedScriptSet{
109143
/// Intersect this set with another
110144
pubfnintersect_with(&mutself,other:Self){

‎src/tests.rs‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn test_potential_mixed_script_detection() {
7979
}
8080

8181
#[test]
82-
fntest_augmented_script_set(){
82+
fntest_augmented_script_set_fmt_debug(){
8383
usecrate::mixed_script::AugmentedScriptSet;
8484
let augmented_script_sets =vec![
8585
AugmentedScriptSet::default(),
@@ -114,3 +114,40 @@ fn test_augmented_script_set() {
114114
assert_eq!(format!("{:?}", ss), output);
115115
}
116116
}
117+
118+
#[test]
119+
fntest_augmented_script_set_fmt_display(){
120+
usecrate::mixed_script::AugmentedScriptSet;
121+
let augmented_script_sets =vec![
122+
AugmentedScriptSet::default(),
123+
AugmentedScriptSet::from('0'),
124+
AugmentedScriptSet::from('a'),
125+
AugmentedScriptSet::from('μ'),
126+
AugmentedScriptSet::from('汉'),
127+
AugmentedScriptSet::from('ひ'),
128+
AugmentedScriptSet::from('カ'),
129+
AugmentedScriptSet::from('한'),
130+
AugmentedScriptSet::from("汉ひ"),
131+
AugmentedScriptSet::from("汉a"),
132+
AugmentedScriptSet::from("汉μ"),
133+
AugmentedScriptSet::from("〆切"),
134+
];
135+
let debug_output =vec![
136+
"All",
137+
"All",
138+
"Latin",
139+
"Greek",
140+
"Han with Bopomofo, Japanese, Korean, Han",
141+
"Japanese, Hiragana",
142+
"Japanese, Katakana",
143+
"Korean, Hangul",
144+
"Japanese",
145+
"Empty",
146+
"Empty",
147+
"Han with Bopomofo, Japanese, Korean, Han",
148+
];
149+
150+
for(ss, output)in augmented_script_sets.into_iter().zip(debug_output){
151+
assert_eq!(format!("{}", ss), output);
152+
}
153+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp