diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index cec2d26..bf8eb0d 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -1,13 +1,37 @@
-name: Tests
-on: push
+name: tests
+on:
+ push:
+ branches: [ main ]
+ paths:
+ - src/**
+ - tests/**
+ pull_request:
+ branches: [ main ]
jobs:
- build_typst_documents:
+ tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- - name: Typst
- uses: lvignoli/typst-action@main
+
+ - name: Probe runner package cache
+ uses: awalsh128/cache-apt-pkgs-action@latest
+ with:
+ packages: cargo
+ version: 1.0
+
+ - name: Install typst-test from github
+ uses: baptiste0928/cargo-install@v2.2.0
with:
- source_file: tests/test_tidy.typ
+ crate: typst-test
+ git: https://github.com/tingerrr/typst-test.git
+ tag: ci-semi-stable
+
+ - name: Setup typst
+ uses: yusancky/setup-typst@v2
+ with:
+ version: 'v0.12.0'
+
+ - name: Run test suite
+ run: typst-test run
\ No newline at end of file
diff --git a/src/helping.typ b/src/helping.typ
index d7a66d4..86d776a 100644
--- a/src/helping.typ
+++ b/src/helping.typ
@@ -5,13 +5,14 @@
#import "show-module.typ": show-module
#let help-box(content) = {
- set text(size: .9em)
block(
above: 1em,
inset: 1em,
stroke: rgb("#AAA"),
- fill: rgb("#F5F5F544"),
- text(size: 2em, [? #smallcaps("help")#h(1fr)?]) + content
+ fill: rgb("#F5F5F544"), {
+ text(size: 1.8em, [? #smallcaps("help")#h(1fr)?])
+ text(.9em, content)
+ }
)
}
diff --git a/tests/helping/ref/1.png b/tests/helping/ref/1.png
new file mode 100644
index 0000000..d24ab37
Binary files /dev/null and b/tests/helping/ref/1.png differ
diff --git a/tests/test_helping.typ b/tests/helping/test.typ
similarity index 66%
rename from tests/test_helping.typ
rename to tests/helping/test.typ
index e1769bf..939d1c4 100644
--- a/tests/test_helping.typ
+++ b/tests/helping/test.typ
@@ -1,5 +1,6 @@
#import "/src/tidy.typ"
+#set page(width: 10cm, height: auto, margin: 2pt)
#let heymath = ```
#import "vector.typ": *
@@ -20,8 +21,11 @@
#let matrix = ```
#import "solve.typ"
-/// - n (int): dimension
-#let id(n)
+///
+#let id(
+ /// dimension -> int
+ n
+ )
```.text
#let solve = ```
@@ -29,6 +33,8 @@
#let solve(n)
```.text
+#let error = highlight
+
#let help(..args) = {
let namespace = (
@@ -39,17 +45,16 @@
tidy.generate-help(
namespace: namespace,
package-name: "heymath",
- onerror: msg => block(msg)
+ onerror: msg => error(msg)
)(..args)
}
#help("pi-squared")
#let assert-not-failed(help-result) = {
- assert.eq(
- help-result.child.body.children.at(1)
- .child.children.first().fill,
- rgb("#d8dbed44")
+ let body = help-result.body.children.at(1).child
+ assert(
+ body.func() != highlight,
)
}
@@ -60,20 +65,24 @@
#assert-not-failed(help("vec-subtract"))
#assert-not-failed(help("matrix.id"))
#assert-not-failed(help("matrix.solve.solve"))
-// #assert-not-failed(help("matrix.id(n)"))
+#assert-not-failed(help("matrix.id(n)"))
#help("matrix.id(n)")
// Invalid definition
#assert.eq(
help("ma"),
- tidy.helping.help-box(block("The package `heymath` contains no (documented) definition `ma`"))
+ tidy.helping.help-box(
+ error("The package `heymath` contains no (documented) definition `ma`")
+ )
)
// Invalid submodule
#assert.eq(
help("matrixs.id"),
- tidy.helping.help-box(block("The package `heymath` contains no module `matrixs`"))
+ tidy.helping.help-box(
+ error("The package `heymath` contains no module `matrixs`")
+ )
)
@@ -81,14 +90,18 @@
// Invalid submodule
#assert.eq(
help("matrix.id(aaaa)"),
- tidy.helping.help-box(block("The function `matrix.id` has no parameter `aaaa`"))
+ tidy.helping.help-box(
+ error("The function `matrix.id` has no parameter `aaaa`")
+ )
)
// Invalid submodule
#assert.eq(
help("cos(aaaa)"),
- tidy.helping.help-box(block("The function `cos` has no parameter `aaaa`"))
+ tidy.helping.help-box(
+ error("The function `cos` has no parameter `aaaa`")
+ )
)
diff --git a/tests/parser/argument-description.typ b/tests/new-parser/argument-description.typ
similarity index 100%
rename from tests/parser/argument-description.typ
rename to tests/new-parser/argument-description.typ
diff --git a/tests/parser/argument-type.typ b/tests/new-parser/argument-type.typ
similarity index 100%
rename from tests/parser/argument-type.typ
rename to tests/new-parser/argument-type.typ
diff --git a/tests/parser/arguments.typ b/tests/new-parser/arguments.typ
similarity index 100%
rename from tests/parser/arguments.typ
rename to tests/new-parser/arguments.typ
diff --git a/tests/parser/currying.typ b/tests/new-parser/currying.typ
similarity index 100%
rename from tests/parser/currying.typ
rename to tests/new-parser/currying.typ
diff --git a/tests/parser/description.typ b/tests/new-parser/description.typ
similarity index 100%
rename from tests/parser/description.typ
rename to tests/new-parser/description.typ
diff --git a/tests/parser/module-description.typ b/tests/new-parser/module-description.typ
similarity index 100%
rename from tests/parser/module-description.typ
rename to tests/new-parser/module-description.typ
diff --git a/tests/parser/multiple-definitions.typ b/tests/new-parser/multiple-definitions.typ
similarity index 100%
rename from tests/parser/multiple-definitions.typ
rename to tests/new-parser/multiple-definitions.typ
diff --git a/tests/new-parser/ref/1.png b/tests/new-parser/ref/1.png
new file mode 100644
index 0000000..d0fcd00
Binary files /dev/null and b/tests/new-parser/ref/1.png differ
diff --git a/tests/parser/test.typ b/tests/new-parser/test.typ
similarity index 77%
rename from tests/parser/test.typ
rename to tests/new-parser/test.typ
index 6386ba2..408e315 100644
--- a/tests/parser/test.typ
+++ b/tests/new-parser/test.typ
@@ -5,3 +5,5 @@
#include "argument-description.typ"
#include "argument-type.typ"
#include "currying.typ"
+
+#set page(width: auto, height: auto, margin: 2pt)
diff --git a/tests/test_parse_argument_list.typ b/tests/old-parser/parse-argument-list.typ
similarity index 100%
rename from tests/test_parse_argument_list.typ
rename to tests/old-parser/parse-argument-list.typ
diff --git a/tests/old-parser/parse-module.typ b/tests/old-parser/parse-module.typ
new file mode 100644
index 0000000..612ed53
--- /dev/null
+++ b/tests/old-parser/parse-module.typ
@@ -0,0 +1,211 @@
+#import "/src/tidy.typ": *
+#import "/src/old-parser.typ": *
+#import "/src/utilities.typ": *
+
+#let eval-string(string) = eval-docstring(string, (scope: (:)))
+
+#let parse-module = parse-module.with(old-syntax: true)
+
+#{
+ let code = ```
+ /// - alpha (str):
+ /// - beta (length):
+ // / - ..children (any):
+ #let z(alpha, beta: 2pt, ..children) = {}
+ ```
+ let k = parse-module(code.text)
+}
+
+// Test reference-matcher
+#{
+ let matches = " @@func".matches(reference-matcher)
+ assert.eq(matches.len(), 1)
+ assert.eq(matches.at(0).captures, ("func",))
+
+ let matches = " @@func()".matches(reference-matcher)
+ assert.eq(matches.len(), 1)
+ assert.eq(matches.at(0).captures, ("func()",))
+
+ let matches = " ()@@@@my-func12-bliblablub @@ @@a".matches(reference-matcher)
+ assert.eq(matches.len(), 2)
+ assert.eq(matches.at(0).captures, ("my-func12-bliblablub",))
+ assert.eq(matches.at(1).captures, ("a",))
+}
+
+
+// Test argument-documentation-matcher
+#{
+ let matches = " \t\n\t /// - my-arg1 (string, content): desc".matches(argument-documentation-matcher)
+ assert.eq(matches.len(), 1)
+ assert.eq(matches.at(0).captures, ("my-arg1","string, content", "desc"))
+
+ // multiline argument description
+ let matches = "/// - arg (type): desc\n\tasd\n-3$234$".matches(argument-documentation-matcher)
+ assert.eq(matches.len(), 1)
+ assert.eq(matches.at(0).captures, ("arg", "type", "desc"))
+}
+
+
+// Basic tests
+#{
+let a = ```
+/// Func
+#let a-3_56C() = {}
+```.text
+let result = parse-module(a)
+assert.eq(result.functions.len(), 1)
+assert.eq(result.functions.at(0).name, "a-3_56C")
+assert.eq(eval-string(result.functions.at(0).description), [Func])
+assert.eq(result.functions.at(0).return-types, none)
+}
+
+
+#{
+ let a = ```
+ #{
+ /// Func
+ ///
+ let a() = {}
+ }
+ ```.text
+ let result = parse-module(a)
+ assert.eq(result.functions.len(), 1)
+ assert.eq(result.functions.at(0).name, "a")
+ assert.eq(eval-string(result.functions.at(0).description), [Func])
+ assert.eq(result.functions.at(0).return-types, none)
+}
+
+
+
+// Parameters and defaults
+#{
+ let a = ```
+ /// Func
+ #let a(p1, p2: 2, p3: (), p4: ("entries": ())) = {}
+ ```.text
+ let result = parse-module(a)
+ assert.eq(result.functions.len(), 1)
+ let f0 = result.functions.at(0)
+
+ assert.eq(f0.name, "a")
+ assert.eq(eval-string(f0.description), [Func])
+ assert.eq(f0.args.len(), 4)
+ assert.eq(f0.args.p1, (:))
+ assert.eq(f0.args.p2, (default: "2"))
+ assert.eq(f0.args.p3, (default: "()"))
+ assert.eq(f0.args.p4, (default: "(\"entries\": ())"))
+ assert.eq(f0.return-types, none)
+}
+
+
+
+
+// Parameter and return types
+#{
+ let a = ```
+ /// Func
+ /// - p1 (string): a param $a$
+ /// - p2 (boolean, function): a param $b$
+ /// Oh yes
+ /// - p3 (string):
+ /// -> content, integer
+ #let a(p1, p2: 2, p3: (), p4: ("entries": ())) = {}
+ ```.text
+ let result = parse-module(a)
+ assert.eq(result.functions.len(), 1)
+ let f0 = result.functions.at(0)
+
+ assert.eq(f0.name, "a")
+ assert.eq(eval-string(f0.description), [Func])
+ assert.eq(f0.args.len(), 4)
+ assert.eq(f0.args.p1.types, ("string",))
+ assert.eq(eval-string(f0.args.p1.description), [a param $a$])
+ assert.eq(f0.args.p2.default, "2")
+ assert.eq(eval-string(f0.args.p2.description), [a param $b$ Oh yes])
+ assert.eq(f0.args.p2.types, ("boolean", "function"))
+ assert.eq(f0.return-types, ("content", "integer"))
+}
+
+
+
+
+
+// // Ignore args that are not in the argument list
+// #{
+// let a = ```
+// /// Func
+// /// - bar (content): asd
+// #let a(bar) = {}
+// ```.text
+// let result = parse-module(a)
+// assert.eq(result.functions.len(), 1)
+// assert.eq(result.functions.at(0).args.len(), 1)
+// }
+
+
+// Ignore interrupted docstring
+#{
+ let a = ```
+ /// Func
+ // a
+ #let a()
+ ```.text
+ let result = parse-module(a)
+ assert.eq(result.functions.len(), 0)
+}
+
+
+// Ensure that wide unicode characters don't disturb line calculation for error messages
+#{
+ let code = ```
+ // ⇒⇐ßáà€
+
+ /// foo
+ /// >>> 2 == 2
+ #let f()
+ ```
+
+ let result = show-module(parse-module(code.text))
+}
+
+// Curried functions
+#{
+ let code = ```
+/// - foo (content): Something.
+/// - bar (boolean): A boolean.
+/// -> content
+#let myfunc(foo, bar: false) = strong(foo)
+
+/// My curried function.
+/// -> content
+#let curried = myfunc.with(bar: true, 2)
+ ```
+
+ let result = parse-module(code.text)
+ let f1 = result.functions.at(0)
+ let f2 = result.functions.at(1)
+ assert.eq(f1.name, "myfunc")
+ assert.eq(f2.parent.name, "myfunc")
+ assert.eq(f2.parent.pos, ("2",))
+ assert.eq(f2.parent.named, (bar: "true"))
+ // assert.eq(f2.args.len(), 1)
+ // assert.eq(f2.args.bar, (
+ // default: "true",
+ // description: "A boolean.",
+ // types: ("boolean",),
+ // ))
+}
+
+// module description
+#{
+ let code = ```
+ // License
+
+ /// This is a module
+
+ a
+ ```
+
+ let result = parse-module(code.text)
+ assert.eq(result.description, "This is a module")
+}
\ No newline at end of file
diff --git a/tests/old-parser/ref/1.png b/tests/old-parser/ref/1.png
new file mode 100644
index 0000000..d0fcd00
Binary files /dev/null and b/tests/old-parser/ref/1.png differ
diff --git a/tests/old-parser/test.typ b/tests/old-parser/test.typ
new file mode 100644
index 0000000..fee58ff
--- /dev/null
+++ b/tests/old-parser/test.typ
@@ -0,0 +1,4 @@
+#set page(width: auto, height: auto, margin: 2pt)
+
+#include "parse-argument-list.typ"
+#include "parse-module.typ"
\ No newline at end of file
diff --git a/tests/parser/ref/1.png b/tests/parser/ref/1.png
deleted file mode 100644
index 903f45e..0000000
Binary files a/tests/parser/ref/1.png and /dev/null differ
diff --git a/tests/show-example/ref/1.png b/tests/show-example/ref/1.png
index acb1d38..a432332 100644
Binary files a/tests/show-example/ref/1.png and b/tests/show-example/ref/1.png differ
diff --git a/tests/show-example/ref/2.png b/tests/show-example/ref/2.png
index 052b685..05f4d1a 100644
Binary files a/tests/show-example/ref/2.png and b/tests/show-example/ref/2.png differ
diff --git a/tests/show-example/test.typ b/tests/show-example/test.typ
index 3f2af3b..ff9ea03 100644
--- a/tests/show-example/test.typ
+++ b/tests/show-example/test.typ
@@ -33,7 +33,7 @@
#pagebreak()
-#show-example(`Fit that code in a tiny space`)
+#almost-default-show-example(`Fit that code in a tiny space`)
#pagebreak()
diff --git a/tests/test (2.svg b/tests/test (2.svg
deleted file mode 100644
index 0deee02..0000000
--- a/tests/test (2.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-
\ No newline at end of file
diff --git a/tests/test.svg b/tests/test.svg
deleted file mode 100644
index 0deee02..0000000
--- a/tests/test.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-
\ No newline at end of file
diff --git a/tests/test_tidy.typ b/tests/test_tidy.typ
deleted file mode 100644
index a6308d4..0000000
--- a/tests/test_tidy.typ
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "test_parse.typ"
-#include "test_parse_argument_list.typ"
-#include "test_testing.typ"
diff --git a/tests/testing.typ/ref/1.png b/tests/testing.typ/ref/1.png
new file mode 100644
index 0000000..d0fcd00
Binary files /dev/null and b/tests/testing.typ/ref/1.png differ
diff --git a/tests/test_testing.typ b/tests/testing.typ/test.typ
similarity index 90%
rename from tests/test_testing.typ
rename to tests/testing.typ/test.typ
index 32ee41b..2f64108 100644
--- a/tests/test_testing.typ
+++ b/tests/testing.typ/test.typ
@@ -1,3 +1,6 @@
+#set page(width: auto, height: auto, margin: 2pt)
+
+
#import "/src/tidy.typ": *