-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspec_generator.moon
More file actions
57 lines (52 loc) · 2.18 KB
/
spec_generator.moon
File metadata and controls
57 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
module_imports: {'modifier', 'ability', 'character'},
test_helpers: [[
-- ----------------------------------------------------------
between = (state, arguments) ->
assert #arguments == 3, 'expected three arguments to assert.between: value, min, max'
{ val, min, max } = arguments
val and min <= val and val <= max
say = require 'say'
say\set 'assertion.between.positive', 'Expected %s to be in the range [%s, %s]'
say\set 'assertion.between.negative', 'Expected %s not to be in the range [%s, %s]'
assert\register 'assertion', 'between', between, 'assertion.between.positive', 'assertion.between.negative'
-- ----------------------------------------------------------
]]
generate_test: (case, level) ->
local lines
switch case.property
when 'modifier'
lines = {
"assert.are.equal #{case.expected}, modifier #{case.input.score}"
}
when 'ability'
lines = {
"for i = 1, 50",
" score = ability!",
" assert.between score, 3, 18"
}
when 'character'
if case.description == "random character is valid"
lines = {
"player = character!",
"assert.between player.strength, 3, 18",
"assert.between player.dexterity, 3, 18",
"assert.between player.constitution, 3, 18",
"assert.between player.intelligence, 3, 18",
"assert.between player.wisdom, 3, 18",
"assert.between player.charisma, 3, 18",
"assert.are.equal (10 + modifier player.constitution), player.hitpoints"
}
else
lines = {
"player = character!",
"assert.are.equal player.strength, player.strength",
"assert.are.equal player.dexterity, player.dexterity",
"assert.are.equal player.constitution, player.constitution",
"assert.are.equal player.intelligence, player.intelligence",
"assert.are.equal player.wisdom, player.wisdom",
"assert.are.equal player.charisma, player.charisma",
"assert.are.equal player.hitpoints, player.hitpoints"
}
table.concat [indent line, level for line in *lines], '\n'
}