Skip to content

Commit 1e0dea0

Browse files
committed
docs: add documentation on how to use std.Testing
1 parent 580ccf9 commit 1e0dea0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Testing.ark

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# internal, do not use
12
(let _runner (fun (_name _callable) {
23
(mut _passed 0)
34
(mut _failed 0)
@@ -25,6 +26,7 @@
2526

2627
[_passed _failed]}))
2728

29+
# internal, do not use
2830
(let _report_error (fun (_lhs _rhs _lhs_repr _rhs_repr) {
2931
(set _failed (+ 1 _failed))
3032
(append! _failures (str:format "{} was not equal to {}" _lhs_repr _rhs_repr))
@@ -34,25 +36,59 @@
3436
(append! _failures (str:format (+ "{: <" (toString _rhs_start) "}{:~<" (toString _rhs_align) "} {}") "|" "\\" _lhs))
3537
(append! _failures (str:format (+ "{:~<" (toString _lhs_align) "} {}") "\\" _rhs))}))
3638

39+
# internal, do not use
3740
(let _report_success (fun () (set _passed (+ 1 _passed))))
3841

42+
# @brief Given a value or function call returning a boolean, generate a test case
43+
# @param _cond the value to test for truthiness
44+
# =begin
45+
# (test:suite name {
46+
# (test:expect (my_function 1 2 3))})
47+
# =end
48+
# @author https://github.com/SuperFola
3949
($ test:expect (_cond) {
4050
(if (!= true _cond)
4151
{
4252
(set _failed (+ 1 _failed))
4353
(append! _failures (str:format "{} was not true but {}" ($repr _cond) _cond)) }
4454
(_report_success))})
4555

56+
# @brief Compare two values that should be equal and generate a test case
57+
# @param _lhs the first value
58+
# @param _rhs the second value
59+
# =begin
60+
# (test:suite name {
61+
# (test:eq 6 (my_function 1 2 3))})
62+
# =end
63+
# @author https://github.com/SuperFola
4664
($ test:eq (_lhs _rhs) {
4765
(if (= _lhs _rhs)
4866
(_report_success)
4967
(_report_error _lhs _rhs ($repr _lhs) ($repr _rhs)))})
5068

69+
# @brief Compare two values that should **not** be equal and generate a test case
70+
# @param _lhs the first value
71+
# @param _rhs the second value
72+
# =begin
73+
# (test:suite name {
74+
# (test:neq 0 (my_function 1 2 3))})
75+
# =end
76+
# @author https://github.com/SuperFola
5177
($ test:neq (_lhs _rhs) {
5278
(if (!= _lhs _rhs)
5379
(_report_success)
5480
(_report_error _lhs _rhs ($repr _lhs) ($repr _rhs)))})
5581

82+
# @brief Generate the code for a test suite
83+
# @details Create two variables: _name-output (a list: [successes, failures]) and _name-status (boolean, true on success)
84+
# @param _name test name, as an identifier
85+
# @param _body body of the test, a begin block
86+
# =begin
87+
# (test:suite name {
88+
# (test:eq 6 (my_function 1 2 3))
89+
# (test:eq 128 (* 8 16))})
90+
# =end
91+
# @author https://github.com/SuperFola
5692
($ test:suite (_name _body) {
5793
(let (symcat _name "-output") (_runner ($repr _name) (fun () {_body})))
5894
(let (symcat _name "-status") (= 0 (@ (symcat _name "-output") 1)))})

0 commit comments

Comments
 (0)