mirror of
https://github.com/typst/typst
synced 2025-07-29 23:37:55 +08:00
Move error back into symbol constructor, fix and add tests
This commit is contained in:
parent
430f6b1686
commit
07316ff9b0
@ -238,6 +238,13 @@ impl Symbol {
|
|||||||
'variants: for (i, &Spanned { ref v, span }) in variants.iter().enumerate() {
|
'variants: for (i, &Spanned { ref v, span }) in variants.iter().enumerate() {
|
||||||
modifiers.clear();
|
modifiers.clear();
|
||||||
|
|
||||||
|
if v.1.is_empty() || v.1.graphemes(true).nth(1).is_some() {
|
||||||
|
errors.push(error!(
|
||||||
|
span, "invalid variant value: {}", v.1.repr();
|
||||||
|
hint: "variant value must be exactly one grapheme cluster"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if !v.0.is_empty() {
|
if !v.0.is_empty() {
|
||||||
// Collect all modifiers.
|
// Collect all modifiers.
|
||||||
for modifier in v.0.split('.') {
|
for modifier in v.0.split('.') {
|
||||||
@ -399,11 +406,7 @@ pub struct SymbolVariant(EcoString, EcoString);
|
|||||||
|
|
||||||
cast! {
|
cast! {
|
||||||
SymbolVariant,
|
SymbolVariant,
|
||||||
s: EcoString => if s.is_empty() || s.graphemes(true).nth(1).is_some() {
|
s: EcoString => Self(EcoString::new(), s),
|
||||||
Err("variant value must be exactly one grapheme cluster")?
|
|
||||||
} else {
|
|
||||||
Self(EcoString::new(), s)
|
|
||||||
},
|
|
||||||
array: Array => {
|
array: Array => {
|
||||||
let mut iter = array.into_iter();
|
let mut iter = array.into_iter();
|
||||||
match (iter.next(), iter.next(), iter.next()) {
|
match (iter.next(), iter.next(), iter.next()) {
|
||||||
|
@ -88,14 +88,26 @@
|
|||||||
("variant.duplicate", "y"),
|
("variant.duplicate", "y"),
|
||||||
)
|
)
|
||||||
|
|
||||||
--- symbol-constructor-empty-variant ---
|
--- symbol-constructor-empty-variant-value ---
|
||||||
// Error: 2:3-2:5 empty default variant
|
// Error: 2:3-2:5 invalid variant value: ""
|
||||||
// Error: 3:3-3:16 empty variant: "empty"
|
// Hint: 2:3-2:5 variant value must be exactly one grapheme cluster
|
||||||
|
// Error: 3:3-3:16 invalid variant value: ""
|
||||||
|
// Hint: 3:3-3:16 variant value must be exactly one grapheme cluster
|
||||||
#symbol(
|
#symbol(
|
||||||
"",
|
"",
|
||||||
("empty", "")
|
("empty", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--- symbol-constructor-multi-cluster-variant-value ---
|
||||||
|
// Error: 2:3-2:7 invalid variant value: "aa"
|
||||||
|
// Hint: 2:3-2:7 variant value must be exactly one grapheme cluster
|
||||||
|
// Error: 3:3-3:14 invalid variant value: "bb"
|
||||||
|
// Hint: 3:3-3:14 variant value must be exactly one grapheme cluster
|
||||||
|
#symbol(
|
||||||
|
"aa",
|
||||||
|
("b", "bb")
|
||||||
|
)
|
||||||
|
|
||||||
--- symbol-unknown-modifier ---
|
--- symbol-unknown-modifier ---
|
||||||
// Error: 13-20 unknown symbol modifier
|
// Error: 13-20 unknown symbol modifier
|
||||||
#emoji.face.garbage
|
#emoji.face.garbage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user