mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 06:34:54 +08:00
fix(glossary): 补齐术语删除和审核门禁
This commit is contained in:
@@ -551,6 +551,16 @@ pub fn validate_glossary_draft(draft: &GlossaryTermDraft) -> crate::Result<()> {
|
||||
"Glossary allowed_translations 不能包含空字符串".to_string(),
|
||||
));
|
||||
}
|
||||
if draft
|
||||
.definition
|
||||
.aliases
|
||||
.iter()
|
||||
.any(|value| value.trim().is_empty())
|
||||
{
|
||||
return Err(crate::Error::InvalidArgument(
|
||||
"Glossary aliases 不能包含空字符串".to_string(),
|
||||
));
|
||||
}
|
||||
let accepted = draft
|
||||
.definition
|
||||
.allowed_translations
|
||||
@@ -687,4 +697,33 @@ mod tests {
|
||||
.iter()
|
||||
.any(|diagnostic| diagnostic.kind == GlossaryDiagnosticKind::Overridden));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_alias_is_rejected() {
|
||||
let mut draft = GlossaryTermDraft {
|
||||
term_id: "term".to_string(),
|
||||
definition: GlossaryTermSnapshot {
|
||||
source_term: "Sensei".to_string(),
|
||||
aliases: vec![" ".to_string()],
|
||||
recommended_translation: "老师".to_string(),
|
||||
allowed_translations: Vec::new(),
|
||||
source_language: None,
|
||||
target_language: None,
|
||||
category: None,
|
||||
priority: 0,
|
||||
scope: BTreeMap::new(),
|
||||
},
|
||||
review_status: GlossaryReviewStatus::Draft,
|
||||
source: GlossarySourceRecord {
|
||||
source_kind: GlossarySourceKind::Manual,
|
||||
source_ref: None,
|
||||
source_author: None,
|
||||
source_note: None,
|
||||
observed_unix_seconds: 1,
|
||||
},
|
||||
};
|
||||
assert!(validate_glossary_draft(&draft).is_err());
|
||||
draft.definition.aliases.clear();
|
||||
assert!(validate_glossary_draft(&draft).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user