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.
tests: check that `inc` is present in stepA.
nasm: split lines in mal_startup_string for readability.
objpascal: remove obsolete .orig file
swift: remove an unneeded line in template
swift4: remove duplicate definition of `or` macro
In the BBC BASIC implementation, lists and vectors are essentially the
same, and are only distinguished by a flag on the head node. This makes
it cheap to convert between lists and vectors, but it does require a
little care to ensure that a vector doesn't escape where it shouldn't.
The new test checks for a case where I'd got this wrong:
(rest (cons 10 [11 12]))
Here the 'cons' returns a list, but the tail of the list is just the
original vector (complete with vector flag), so a naïve implementation
of 'rest' can end up returning that vector instead of an equivalent
list. The test proves that it doesn't.
In these implementations there is no empty list check before
macroexpansion and so empty lists from step8 onwards produce a crash
or other misbehavior.
Also, add a test to step8 to test empty list again (first time it's
tested is in step2).
Strings are deferrable until step 6, so tests of string functionality at
step 4 should be marked as deferrable. A couple of tests just use
strings as convenient constants to return or print. In those cases,
replace the strings with integers rather than deferring the whole test.
The test makes more sense in step6.
Thanks to kanaka for the read-string suggestion.
Introduction of tail call optimization in step5 was making let* affect
the parent environment. This was partially fixed in later steps.
Introduction of macros in step8 was breaking the evaluation of an
empty list. This was fixed by step 9 but never backported.
- Update to support the new behavior of varargs and table.pack/unpack
in lua 5.2
- Bump up the stack overflow test since lua 5.2 seems to support much
larger stacks before overflow.
- Fix a latent issue in if forms where false in the 4th position would
result in nil returned. Add a new test to catch this in the future.