Skip to content

Commit

Permalink
Merge pull request #26 from typst-community/14-handle-default-in-case…
Browse files Browse the repository at this point in the history
…-of-auto-not-none

Revert to default if `auto` is given
  • Loading branch information
jamesrswift authored Jun 3, 2024
2 parents 1b3897c + 8c2872f commit 100ea41
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Array schema generator now takes additional optional parameters `min` and `max` which a sugar for value length assertions.
- Added schema generator for argument sinks. Takes `positional` and `named` as optional parameters that take schema types. Absence of one of these parameters indicate that these must also be absent from the argument type being validated.
- **(Potentially Breaking)** Content now accepts `symbol` as a valid input type by default (see #20)
- **(Potentially Breaking)** If the tested value is `auto`, parsing no longer fails. If `default` is set, it takes the default value. If `optional` is set but not `default`, value is parsed as `none`.

---

Expand Down
2 changes: 1 addition & 1 deletion src/base-type.typ
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
validate: (self, it, scope: (), ctx: z-ctx()) => {

//it = self.default
if (it == none or type(it) == none) {
if (it == none or it == auto) {
it = self.default
}
it = (self.pre-transform)(self, it)
Expand Down
Binary file modified tests/types/string/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion tests/types/string/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@
#z.parse("192.168.0.1", z.ip())

== default
#z.parse(none, z.string(default: "Hello"))
#let _ = z.parse(none, z.string(default: "Hello"))
#let _ = z.parse(auto, z.string(default: "Hello"))
#let _ = z.parse(auto, z.string(default: "Hello", optional: true))
#let _ = repr(z.parse(auto, z.string(optional: true)))
// #z.parse(auto, z.string()) \
#let _ = z.parse("none", z.string(default: "Hello"))

0 comments on commit 100ea41

Please sign in to comment.