mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Add error cases for [font] 🧯
This commit is contained in:
parent
e59de77f96
commit
c44ebf876f
@ -105,9 +105,9 @@ pub fn font(mut args: Args, ctx: &mut EvalContext) -> Value {
|
|||||||
ctx.state.font.variant.stretch = stretch;
|
ctx.state.font.variant.stretch = stretch;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FontList(Vec<String>);
|
struct FamilyList(Vec<String>);
|
||||||
|
|
||||||
try_from_match!(FontList["font or list of fonts"] @ span:
|
try_from_match!(FamilyList["family or list of families"] @ span:
|
||||||
Value::Str(v) => Self(vec![v.to_lowercase()]),
|
Value::Str(v) => Self(vec![v.to_lowercase()]),
|
||||||
Value::Dict(v) => Self(Args(v.span_with(span))
|
Value::Dict(v) => Self(Args(v.span_with(span))
|
||||||
.find_all::<StringLike>()
|
.find_all::<StringLike>()
|
||||||
@ -117,7 +117,7 @@ pub fn font(mut args: Args, ctx: &mut EvalContext) -> Value {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for &class in &["serif", "sans-serif", "monospace", "emoji", "math"] {
|
for &class in &["serif", "sans-serif", "monospace", "emoji", "math"] {
|
||||||
if let Some(list) = args.get::<_, FontList>(ctx, class) {
|
if let Some(list) = args.get::<_, FamilyList>(ctx, class) {
|
||||||
Rc::make_mut(&mut ctx.state.font.families)
|
Rc::make_mut(&mut ctx.state.font.families)
|
||||||
.update_class_list(class.to_string(), list.0);
|
.update_class_list(class.to_string(), list.0);
|
||||||
needs_flattening = true;
|
needs_flattening = true;
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
// Test error cases of the `font` function.
|
// Test error cases of the `font` function.
|
||||||
|
|
||||||
|
// Not one of the valid things for positional arguments.
|
||||||
|
[font: false]
|
||||||
|
|
||||||
|
// Wrong types.
|
||||||
|
[font: style=bold, weight="thin", emoji=0]
|
||||||
|
|
||||||
|
// Non-existing argument.
|
||||||
[font: something="invalid"]
|
[font: something="invalid"]
|
||||||
|
|
||||||
// compare-ref: false
|
// compare-ref: false
|
||||||
// error: 3:8-3:27 unexpected argument
|
// error: 4:8-4:13 unexpected argument
|
||||||
|
// error: 7:14-7:18 invalid font style
|
||||||
|
// error: 7:27-7:33 expected font weight, found string
|
||||||
|
// error: 7:41-7:42 expected family or list of families, found integer
|
||||||
|
// error: 10:8-10:27 unexpected argument
|
||||||
|
Loading…
x
Reference in New Issue
Block a user