forked from Mc-Zen/tidy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
280 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#set page(width: auto, height: auto, margin: 2pt) | ||
|
||
#include "parse-argument-list.typ" | ||
#include "parse-module.typ" |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.