Skip to content

Commit f99bc99

Browse files
committed
Add test references for Crystal/Dart/Elixir/OCaml
1 parent 6f8a297 commit f99bc99

File tree

4 files changed

+258
-0
lines changed

4 files changed

+258
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: spec
3+
language: crystal
4+
5+
basic_setup: |-
6+
```ruby
7+
def add(a, b)
8+
a + b
9+
end
10+
```
11+
12+
```ruby
13+
describe "simple test" do
14+
it "should add" do
15+
add(1, 1).should eq 2
16+
end
17+
end
18+
```
19+
---
20+
21+
<h1>{{ page.title }}</h1>
22+
<p>
23+
<a href="https://crystal-lang.org/api/0.21.1/Spec.html"><code>spec</code></a>
24+
module can be used to test Crystal code.
25+
</p>
26+
27+
<h2>Basic Setup</h2>
28+
{{ page.basic_setup | markdownify }}

docs/_test_references/dart/test.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: test
3+
language: dart
4+
5+
basic_setup: |-
6+
```dart
7+
add(a, b) => a + b;
8+
```
9+
10+
```dart
11+
test('add', () {
12+
expect(add(1, 1), equals(2));
13+
});
14+
```
15+
16+
Note that `test()` is *not* inside `main`.
17+
18+
From above inputs, a file like the following is generated and executed:
19+
20+
```dart
21+
import 'package:test/test.dart';
22+
23+
// optional "Preloaded" code
24+
25+
// solution
26+
add(a, b) => a + b;
27+
28+
void main() {
29+
// fixture
30+
test('add', () {
31+
expect(add(1, 1), equals(2));
32+
});
33+
}
34+
```
35+
36+
---
37+
38+
<h1>{{ page.title }}</h1>
39+
40+
<a href="https://pub.dartlang.org/packages/test">test</a> package can be used to test Dart code.
41+
42+
<h2>Basic Setup</h2>
43+
{{ page.basic_setup | markdownify }}
44+
45+
46+
{% comment %}
47+
48+
Why does dart-runner do this?
49+
50+
{% endcomment %}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: ExUnit
3+
language: elixir
4+
5+
basic_setup: |-
6+
```elixir
7+
defmodule Adder do
8+
def add(a, b), do: a + b
9+
end
10+
```
11+
12+
```elixir
13+
defmodule TestAdder do
14+
use ExUnit.Case
15+
import Adder, only: [add: 2]
16+
test "add(1, 1) == 2" do
17+
assert add(1, 1) == 2
18+
end
19+
end
20+
```
21+
---
22+
23+
<h1>{{ page.title }}</h1>
24+
25+
<p>Elixir code can be tested using <a href="https://hexdocs.pm/ex_unit/ExUnit.html">ExUnit</a>.</p>
26+
27+
<h2>Basic Setup</h2>
28+
{{ page.basic_setup | markdownify }}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: OUnit
3+
language: ocaml
4+
5+
basic_setup: |-
6+
```ocaml
7+
(* TODO *)
8+
```
9+
10+
assertions:
11+
- name: assert_failure
12+
id: assert-failure
13+
desc: |-
14+
```ocaml
15+
val assert_failure : string -> 'a
16+
```
17+
Signals a failure.
18+
This will raise an exception with the specified string.
19+
20+
- name: assert_bool
21+
id: assert-bool
22+
desc: |-
23+
```ocaml
24+
val assert_bool : string -> bool -> unit
25+
```
26+
Signals a failure when bool is false.
27+
The string identifies the failure.
28+
29+
- name: assert_string
30+
id: assert-string
31+
desc: |-
32+
```ocaml
33+
val assert_string : string -> unit
34+
```
35+
Signals a failure when the string is non-empty.
36+
The string identifies the failure.
37+
38+
- name: assert_equal
39+
id: assert-equal
40+
desc: |-
41+
```ocaml
42+
val assert_equal :
43+
?ctxt:test_ctxt ->
44+
?cmp:('a -> 'a -> bool) ->
45+
?printer:('a -> string) ->
46+
?pp_diff:(Format.formatter -> 'a * 'a -> unit) ->
47+
?msg:string ->
48+
'a -> 'a -> unit
49+
```
50+
51+
Compares two values, when they are not equal a failure is signaled.
52+
53+
`assert_equal expected real`
54+
55+
`ctxt` : if provided, always print expected and real value
56+
57+
`cmp` : customize function to compare, default is `=`
58+
59+
`printer` : value printer, don't print value otherwise
60+
61+
`pp_diff` : if not equal, ask a custom display of the difference using
62+
`diff fmt exp real` where `fmt` is the formatter to use
63+
64+
`msg` : custom message to identify the failure
65+
66+
- name: assert_raises
67+
desc: |-
68+
```ocaml
69+
val assert_raises :
70+
?msg:string ->
71+
exn -> (unit -> 'a) -> unit
72+
```
73+
Asserts if the expected exception was raised.
74+
75+
`msg` : identify the failure
76+
77+
compare_functions:
78+
- name: cmp_float
79+
id: cmp-float
80+
desc: |-
81+
```ocaml
82+
val cmp_float : ?epsilon:float -> float -> float -> bool
83+
```
84+
Compare floats up to a given relative error.
85+
86+
`epsilon`: if the difference is smaller epsilon values are equal
87+
88+
constructing:
89+
- name: '>:'
90+
id: label-test
91+
desc: |-
92+
```ocaml
93+
val (>:) : string -> test -> test
94+
```
95+
Create a TestLabel for a test
96+
- name: '>::'
97+
id: label-test-case
98+
desc: |-
99+
```ocaml
100+
val (>::) : string -> test_fun -> test
101+
```
102+
Create a TestLabel for a TestCase
103+
- name: '>:::'
104+
id: label-test-list
105+
desc: |-
106+
```ocaml
107+
val (>:::) : string -> test list -> test
108+
```
109+
Create a TestLabel for a TestList
110+
- name: test_case
111+
id: test-case
112+
desc: |-
113+
```ocaml
114+
val test_case : ?length:test_length -> test_fun -> test
115+
```
116+
Generic function to create a test case.
117+
- name: test_list
118+
id: test-list
119+
desc: |-
120+
```ocaml
121+
val test_list : test list -> test
122+
```
123+
Generic function to create a test list.
124+
---
125+
126+
<h1>{{ page.title }}</h1>
127+
<p><a href="http://ounit.forge.ocamlcore.org/api-ounit/">OUnit</a> can be used to test OCaml code.</p>
128+
129+
<h2>Basic Setup</h2>
130+
{{ page.basic_setup | markdownify }}
131+
132+
<h2>Assertions</h2>
133+
<dl>
134+
{% for a in page.assertions %}
135+
<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd>
136+
{% endfor %}
137+
</dl>
138+
139+
<h2>Compare Functions</h2>
140+
<dl>
141+
{% for a in page.compare_functions %}
142+
<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd>
143+
{% endfor %}
144+
</dl>
145+
146+
147+
<h2>Constructing</h2>
148+
<dl>
149+
{% for a in page.constructing %}
150+
<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd>
151+
{% endfor %}
152+
</dl>

0 commit comments

Comments
 (0)