Skip to content

Commit

Permalink
[add] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Zen committed Nov 21, 2024
1 parent 2ea1d30 commit fa70b28
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// #import "@preview/tidy:0.3.0"
#import "src/tidy.typ"

#show raw.where(block: true): highlight

#let module = ````
/// #example(```
/// [a #raw("foo") b]
/// ```)
let x = none

/// #example(`[a #raw("foo") b]`)
let y = none

/// #example(raw(`[a #raw("foo") b]`.text), mode: "markup")
let z = none

/// #example(raw(lang: "typc", `[a #raw("foo") b]`.text))
let ß = none
````.text
#let module = tidy.parse-module(
module,
// preamble: "set raw(block: false);"
)
#tidy.show-module(
module,
sort-functions: none,
style: tidy.styles.minimal,
)
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# added by typst-test
**/out/
**/diff/
Binary file added tests/parser/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.
Binary file added tests/show-example/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.
Binary file added tests/show-example/ref/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/show-example/ref/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions tests/show-example/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#set page(width: 170pt, height: auto, margin: 0pt)
#import "/src/tidy.typ": show-example as example, render-examples
#let show-example = example.show-example.with(
layout: (code, preview, ..sink) => {
grid(columns: (1fr, 1fr), align: horizon, code, preview)
}
)
#let almost-default-show-example = example.show-example.with(
layout: example.default-layout-example.with(
code-block: block.with(stroke: .5pt + luma(200)),
col-spacing: 0pt
)
)

#set block(below: 0pt)

// All possible combinations of code and markup mode
#show-example(`1`)
#show-example(`#calc.sin(0)`)
#show-example(raw("#calc.sin(0)"))
#show-example(raw(lang: "typc", "calc.sin(0)"))
#show-example(raw(lang: "typc", "calc.sin(0)", block: true))
#show-example(raw(lang: "typ", "#calc.sin(0)"))
#show-example(raw(lang: "typ", "a^2"), mode: "math")
#show-example(raw(lang: "typm", "a^2"), mode: "math")

#pagebreak()

// Check that `raw` is not forced to block in the preview, see #21
#show-example(`a #raw("foo") b`, mode: "markup")
// Language should NOT default to typ in the preview, see #21
#show-example(`#raw("#import")`, mode: "markup")

#pagebreak()

#show-example(`Fit that code in a tiny space`)

#pagebreak()

// Test ratio
#almost-default-show-example(`Ratio .5`, ratio: .5)
#pagebreak()

// Test scale-preview
#almost-default-show-example(`Fit that 200%`, scale-preview: 200%)
#almost-default-show-example(`Fit that 50%`, scale-preview: 50%)
#pagebreak()


// Test direction
#almost-default-show-example(`#ltr`, dir: ltr)
#pagebreak()
#almost-default-show-example(`#ttb`, dir: ttb)

#pagebreak()

// The auto-shower, see #15

#[
#show: render-examples

```example
#rect(height: 3pt)
```
]

#pagebreak()


#[
#set page(width: auto, height: auto, margin: 0pt)
#show: render-examples.with(layout: (code, preview) => grid(columns: 2, align: horizon, code, preview))

```example
#rect(height: 3pt)
```
]

0 comments on commit fa70b28

Please sign in to comment.