Instead of using Io's `asJson` method which escapes forward slashes,
implement our own string escaping code so it fits the Mal requirements.
The relevant step1 test was modified from soft to hard.
Make: remove part of EVAL breaking # and $
step0: no MAL character must break the interpreter
(soft) no printable ASCII character either
step1: no MAL character must break strings
(soft) no printable ASCII character should break strings
(soft) no character should break comments
step6: redo step1 tests for comments inside read-string, as new
problem may occur with line breaks and escape characters of the host
language.
Output of macros will probably be more readable.
Inline _macro_wrap and _unwrap for efficiency (there are less
primitive operations for maps than for vectors).
Basic check of `map?` and `macro?`. Swap them in order to simplify the
diff with cb9b0654.
Let `with-meta f m` create a function even if f is a macro, instead of
setting an "ismacro" metadata that is never used again (and breaks
self-hosting).
Also move the test for fn? from Optional to Deferrable, the function
is used for self-hosting.
* Move `gensym` and `inc` from step files to `lib/trivial.mal`.
* Move `or` from step files to `lib/test_cascade.mal`.
Shorten it because `(first ())` returns `nil`
* Update process and tests accordingly (not the figures yet).
Specifically, test that when "1" is used as a hash-map key, it is
represented as a string when printed (step 1) and when returned by
'keys' (step 9). PHP used to get both of these wrong.
It seems that the PHP implementation converts integer-like strings as
hash-map keys into integers, so {"1" 1} becomes {1 1}. I don't know if
that's a bug, but it's certainly not the bug I was trying to test for.
Use different keys to avoid this problem.
All the existing tests in step 1 use empty or single-element hash-maps.
That avoids any dependency on the ordering of printed hash-maps, but it
does mean that some code paths (e.g. printing the space between hash-map
elements) aren't tested. Add a test that creates a three-element
hash-map and uses some regexp trickery to check that all the right keys
and values come out.
These tests are intended to catch the cases where the routine for
reading a list, vector, or hashmap fails to consume the trailing token
(')', ']', or '}' as the case may be) from the input. None of the
existing step 1 tests detected this, and I only found it by playing
around in the REPL.
I just introduced a bug in the BBC BASIC implementation meaning that
'load-file' was broken on files over 255 bytes long, and it was only
caught by the optional test of 'time-ms' in step A. This change brings
forward the relevant part of that test so the failure can be detected
earlier and more obviously, at the same time as the other tests of
'load-file'.
When testing `foo.mal`, it makes sense to report parsing errors in
`foo.mal`.
Move tests of `->` and `->>` from `tests/step8_macros.mal` to
`tests/lib/theading.mal`.
Add `lib/trivial.mal`.
equality.mal:
- fix typos
- let and2 and or2 always return booleans
- when looping in sequences, compare lengths only once
- empty? instead of an equality test
- when looping on a keys, do not check if a contains the current key
- change the `cond` logic: when a is a sequence and b a map, return
false instead of delegating to scalar-equal?.
- add tests
memoize.mal:
- make explicit that the function name must be kept
- fix typo in tests
protocols.mal:
- document
- add a function mapping an object to its type
- add default types for remaining built-in MAL values
- let defprotocol return the new protocol instead of last method
- set the right profile for abstract methods, improving error messages
- replace incomplete example with lots of tests
pprint:
- escape parenthesis in expected test results
[kanaka]
- explain in lib/README.md how to run tests/lib/*.
- rename folds to reducers and composition to threading
- move fib and sumdown from lib/ to tests/
Partial translation of examples from lib/ to new tests.
Correct test of memoize.
`reduce`, `foldr`, `every?`, `some` and `and` were previously not
tested in tests/step*.mal. Tests them in `tests/lib/` instead.
In the BBC BASIC implementation, the empty list, vector, and hash-mapp
are distinguished values and detected by their address. Adding metadata
to them makes a copy, and then they don't work properly any more.
Self-hosting currently requires that these functions be defined so
that the mal implementation can pass them through. This test
minimally ensures that.