Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ included_tests_from_toml = (path) ->

-- ----------------------------------------------------------
-- functions marked as global so spec_generators can see them
export indent, quote, is_json_null
export indent, quote, is_json_null, is_empty

indent = (text, level) -> string.rep(' ', level) .. text

Expand All @@ -58,8 +58,10 @@ quote = (str) ->
else
"'#{str}'"

is_empty = (t) -> not next t

-- the dkjson `json.null` value is an empty table
is_json_null = (value) -> type(value) == 'table' and #value == 0
is_json_null = (value) -> type(value) == 'table' and is_empty(value)

-- ----------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/matching-brackets/.meta/example.moon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
push = table.insert
pop = table.remove
is_empty = (s) -> #s == 0
is_empty = (t) -> not next t

opener = { [']']: '[', ['}']: '{', [')']: '(' }
opener = ']':'[', '}':'{', ')':'('


{
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/proverb/.meta/spec_generator.moon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
generate_test: (case, level) ->
input = table.concat [quote word for word in *case.input.strings], ', '
local expected
if #case.expected == 0
if is_empty case.expected
expected = "''"
else
expected = "[[\n#{table.concat case.expected, '\n'}\n]]"
Expand Down
9 changes: 9 additions & 0 deletions exercises/test_helpers.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Reusable stuff for spec generators

## Functions in generate-spec script

These functions are exported from generate-spec for use in spec_generator modules

- `indent(text, level)` -- provide leading whitespace to the appropriate level.
- `quote(str)` -- add quotation marks to the string, single or double as appropriate.
- `is_empty(tbl)` -- predicate: is the table empty
- `is_json_null(value)` -- predicate: is the value `json.null` from dkjson

## Helper functions

Useful for generating pretty tables mostly.
Expand Down
Loading