summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* suffix functions: leading dot is not delimiterKaz Kylheku2021-06-261-13/+23
| | | | | | | | | | * stream.c (short_suffix, long_suffix): Do not treat the starting dot of the last componet as a suffix delimiter. * tests/018/path.tl: Test cases edited to reflect requirements change; new tests added. * txr.1: Updated.
* signals: disable stack overflow in handler.Kaz Kylheku2021-06-241-0/+11
| | | | | | | | | | | * signal.c (sig_handler): For a is_cpu_exception signal, we temporarily disable the stack limit. It might be executing on the sigaltstack buffer, which is almost certainly below the stack limit. * tests/012/stack.tl: New test case. We raise a SIGSEGV and check that in the handler, the stack limit is disabled, and that we can executed code.
* txr: stack protection in pattern language.Kaz Kylheku2021-06-242-0/+9
| | | | | | | | | * txr.c (do_match_line, match_files): call gc_stack_check on entry. * tests/012/stack2.txr: New file. * tests/012/stack2.expected: New file.
* Test for stack overflow protection.Kaz Kylheku2021-06-242-0/+34
| | | | | | * tests/012/stack.tl: New file. * tets/common.tl (mvtest): New macro.
* matcher: new looping macros.Kaz Kylheku2021-06-241-0/+25
| | | | | | | | | | | | | | * lisplib.c (match_set_entries): Autoload on new while-match, while-match-case and while-true-match-case symbols. * share/txr/stdlib/match.tl (while-match, while-match-case, while-true-match-case): New macros. * tests/011/patmatch.tl: Tests. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* short-suffix, long-suffix: no match across slash.Kaz Kylheku2021-06-221-0/+26
| | | | | | | | | | | * stream.c (short_suffix, long_suffix): Take path separator characters into account; the suffix must not span across separators. The trailing separator must also not appear in the suffix. * tests/018/path.tl: Test cases added. * txr.1: Redocumented.
* lib: rmismatch tests and bugfix.Kaz Kylheku2021-06-221-0/+39
| | | | | | | * lib.c (rmismatch): when left is an empty string or vector, and right is nil: we must return -1 not zero. * tests/012/seq.tl: More rmismatch tests.
* lib: optimize mismatch, rmismatch for strings.Kaz Kylheku2021-06-221-0/+49
| | | | | | | | | | | * lib (mismatch, rmismatch): If the arguments are strings or literals, other than lazy strings, keyfun is identity, and equality is by character identity, the operation can be done with an efficient loop over the wchar_t strings. * tests/012/seq.tl: Tests for string case of mismatch, via starts-with function. Test mismatch via ends-with, and also directly for vectors and strings.
* New functions: long-suffix, short-suffix.Kaz Kylheku2021-06-221-0/+34
| | | | | | | | | | | | | | * stream.c (short_suffix, long_suffix): New functions. (stream_init): short-suffix and long-suffix intrinsics registered. * stream.c (short_suffix, long_suffix): Declared. * tests/018/path.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* Dubious new functions cxr/cyr.Kaz Kylheku2021-06-211-0/+14
| | | | | | | | | | | | | | * lib.c (cxr, cyr): New functions. * lib.h (cxr, cyr): Declared. * eval.c (eval_init): Intrinsics cxr and cyr registered. * tests/012/cadr.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* subprocesses: cygwin fixes.Kaz Kylheku2021-06-201-3/+9
| | | | | | | | | | | | | | * stream.c (fds_subst, fds_swizzle, fds_restore): These functions are used on Cygwin by some functions that are based on spawn, and so must be avaiable. * tests/018/process.tl: Two fixes here. Firstly, the 1>&1 redirection in one of the tests should be 1>&2 on all platforms. That a temporary edit left behind from massaging the tests and the code. Secondly, some weird results are observed on Cygwin. The communication with the child sees an extra carriage return and space sneak in. I'm just codifying this as Cygwin's way of passing the test case; it's likely unfixable at the application level.
* subprocesses: a few test cases.Kaz Kylheku2021-06-201-0/+18
| | | | * tests/018/process.tl: New file.
* read/get-json: reject trailing junk in string input.Kaz Kylheku2021-06-202-1/+73
| | | | | | | | | | | | | | | | | * parser.c (lisp_parse_impl): If parsing from string, check for trailing junk and diagnose. JSON parsing doesn't use lookahead because it doesn't have a.b syntax, so the recent_tok gives the last token that actually went into the syntax, and not a lookahead token. So in the case of JSON, we call yylex to see if there is any trailing token. * tests/010/json.tl: Extend get-json tests to more kinds of objects, and then replicate with trailing whitespace and trailing junk to provide coverage for these cases. * tests/012/parse.t: Slew of new read tests and iread also. * txr.1: Documented.
* op: tests, and fix (op progn ...) situationKaz Kylheku2021-06-171-0/+71
| | | | | | | | | | * share/txr/stdlib/op.tl (op-expand): For the sake of special processing applied to support the lop operator, the code assumes that the expanded syntax-2 is a list with at least two elements, such that we can do (cddr syntax-2). This is not true for instance in (op progn). * tests/012/op.tl: New file.
* txr-case: upkeep.Kaz Kylheku2021-06-162-0/+13
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/txr-case.tl (txr-case-impl): If the input is a stream, then convert it to a lazy list of lines, so that running multiple functions against it produces sane, backtracking behavior, like a @(cases) construct. * tests/011/txr-case.expected: Updated. * tests/011/txr-case.txr: Now actually contains a test case for txr-case. * txr.1: Address an issue reported by Paul A. Patience: the input to match-fun, txr-if and txr-when may be a stream. That has always been the case in the implementation. Also document that when the input is a single string, it is treated as a list. Document the new requirement in txr-case that a stream is converted into lazy list of lines.
* math: forbid dubious inequality comparisons.Kaz Kylheku2021-06-151-0/+56
| | | | | | | | | | | | | | | | | | | The issue, reported by Paul A. Patience, is that code like (< 1 "abc") is successfully producing a result. The root cause is that 1 is an iterable object, and so is treated as a sequence opposite to the "abc" operand. We should allow only true sequences in this situation. * arith.c (seq_lt_compat_check): New static function. Checks that neither of two sequences is SEQ_NOTSEQ or SEQ_HASHLIKE. (seq_lt, seq_le): Use seq_lt_compat_check to reject dubious inputs. * txr.1: Minor wording change in the related documentation, removing a gratuitous adjective. * tests/016/arith.tl: Inequality tests.
* expander: bug: atoms in quasiliteral.Kaz Kylheku2021-06-151-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Via macros, atoms can sneak into a quasiliteral which then blow up because they get treated as strings without being converted. Example: (defmacro two () 2) `@(two)xyz` -> ;; error The expansion produces the invalid form, in which the 2 is subsequently treated as a string. (sys:quasi 2 "xyz") On the other hand, symbol macros don't have this problem: (defsymacro two 2) `@{two}xyz` -> "2xyz" The reason is that the (sys:var two) syntax will expand to (sys:var 2), and not 2. The straightforward, consistent fix is to ensure that the first case will also go to (sys:var 2). * eval.c (expand_quasi): If the expanded form is an atom which is not a bindable symbol, wrap it in a sys:var. * tests/012/quasi.tl: Test cases added. Also adding a compilation test for this file, cribbed from patmatch.tl.
* defsymacro: regression: don't expand replacement.Kaz Kylheku2021-06-151-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a regression that was introduced in 191. The change in 191 was trying to prevent defsymacro from being expanded immediately by the expander except in 190 compatibility. Unfortunately, this caused the whole defsymacro block not to be entered unless in 190 compatibility, otherwise taking the common exit which returns form_ex, containing the expanded replacement form. * eval.c (do_expand): Split up implementation of defvarl and defsymacro. In the defsymacro block, do not do any expanding on entry. Absent of compatibility mode, we just do some sanity checks and pass the entire form through. In 262 compatibility, we do the expansion to obtain form_ex. Then all the previous compat logic is wrapped in that block. * tests/011/macros-3.tl: Add a test case which confirms that symbol macros are lazily expanded. Weakness in the test suite is how these regressions creep in. * txr.1: Improve defsymacro documentation, spelling out clearly that the unexpanded replacement form is associated with the symbol. Eliminate obsolescent text suggesting that defsymacro is evaluated at macro time.
* format: revise numeric handling.Kaz Kylheku2021-06-141-5/+96
| | | | | | | | | | | | | | | | | | | | | | | There are a number of issues, such as left adjustment not working and such. This needs a better treatment from the requirements level, through to a set of test cases. * stream.c (max, min): Macros macros added, in their usual form. (vformat_num): Implement new rules which suppress the zero and space characters used in place of a sign if they overflow the field width. (formatv): Clamp integer precision field to width - 1 for integers, for consistency with floating-point handling. For floating-point values under ~a and ~s, do not force the second stage precision to width - 1; only clamp it if it is greater. * format.tl: Numerous new tests. * txr.1: Significant redocumenting of this area. The handling of numbers is described as a two stage process, clarifying the changing role of "precision" in the two stages.
* format: new precision - character for zero.Kaz Kylheku2021-06-141-0/+5
| | | | | | | | | | | * stream.c (formatv): The - precision option character produces a "sign" that is a zero. If this is used with leading zeros, it will avoid generating a space. The requirements can use improvement here, but one step at a time. * tests/018/format.tl: Some tests. * txr.1: Documented.
* pic: support quasiliteral as format string.Kaz Kylheku2021-06-111-0/+5
| | | | | | | | | | | | * share/txr/stdlib/pic.tl (pic): Refactor string compilation code into local function which has access to the overall argument list. Recognize the quasiliteral case and translate by compiling all the string parts, then forming a recombined quasiliteral where the compiled parts are substituted. * tests/018/format.tl: test case for this. * txr.1: Documented.
* pic: allow trailing exclamation.Kaz Kylheku2021-06-111-0/+5
| | | | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num, expand-pic, pic): Allow ### to be followed by a single !. This is not counted toward the field width. * tests/018/format.tl: Cover with some tests. * txr.1: Doc updated.
* pic: clarification and tests.Kaz Kylheku2021-06-111-0/+6
| | | | | | | | * tests/018/format.tl: Add tests which combine overflow flagging with +/-. The space generated by - contributes to overflow. * txr.1: Clarify overflow issue in documentation.
* tests: remove *stderr* to *stdnull* redirection.Kaz Kylheku2021-06-113-17/+7
| | | | | | | | | | | | | | The recent commit 225ff2fa2fdb9e5169db5e2c06dc3b0053b775bb titled "errors: avoid premature release of deferred warnings." obviates the need for dealing with noise when detecting errors from test cases. * patmatch.tl: Remove macro-time-let around several test cases. * tests/012/ifa.tl: Likewise. * tests/common.tl (macro-time-let): Macro removed.
* pic: test cases and fixes.Kaz Kylheku2021-06-111-0/+88
| | | | | | | | | | | | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num): Bug: when a field overflows, the (rest ...) call truncates the leftmost digit. A failing test case is (pic "#.#" 12) which produces "2.0" instead of "12.0". Firstly, we only need that logic at all in the zero padding case. When the number is positive, we stick in the + request, so we are sure to get a + character. The rest call then predictably chops off the + rather than a digit. (pic-join-opt): Fix two bugs here in the string-string combine case: using s2 instead of s1, and not splicing in rest. (expand-pic, pic): Implement tightening for escape sequences. If ~ is not followed by anything, or not followed by the documented characters for escaping, it is erroneous. * format.tl: Battery of new tests.
* tests: support testing for warnings.Kaz Kylheku2021-06-111-5/+15
| | | | | | | | * tests/common.tl (error-to-sym): Catch warnings, and convert to :warning symbol. (vtest): Support new kinds of expected value: :warning. The test is satisfied if it throws a warning at expansion time or during evaluation.
* arith: switch sum and prod to seq_iter.Kaz Kylheku2021-06-091-0/+24
| | | | | | | | | | | | | | * arith.c (nary_op_keyfun): Static function removed. (nary_op_seq, nary_op_seq_keyfun): New static functions. (sumv, prodv): Static functions removed. (sum, prod): Reimplement using nary_op_seq and nary_op_seq_keyfun. Conversion of sequence to list smuggled via args is gone. * tests/016/arith.tl: new sum and prod tests. * txr.1: Note about sum and prod taking an iterable sequence added.
* reduce-left: rewrite using seq_iter.Kaz Kylheku2021-06-091-0/+10
| | | | | | | * lib.c (reduce_left): Use sequence iteration instead of list operations. * txr.1: Add a note to the documentation.
* lib: new function, fill-vec.Kaz Kylheku2021-06-081-0/+32
| | | | | | | | | | | | | | * eval.c (eval_init): Register fill-vec intrinsic. * lib.c (fill_vec): New function. * lib.h (fill_vec): Declared. * tests/010/vec.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* expander: expand must only ignores unbound warnings.Kaz Kylheku2021-06-071-4/+4
| | | | | | | | | | | | | | | | | | | The expand function must not muffle all deferred warnings. That causes the problem that a form like (inc var a.bar) fails to produce a warning due to bar not being the slot of any structure. The expand function must only muffle warnings about undefined functions and variables. * eval.c (muffle_unbound_warning): New static function. (no_warn_expand): Use muffle_unbound_warning as handler, rather than uw_muffle_warning. * tests/012/struct.tl: Fix two test cases here which test the expand function using a form that references a nonexistent slot. These now generate a warning, so we use the slot name b rather than d, which is defined. * txr.1: Documented change to expand.
* matcher: doc fix, quasiquote examples, new test.Kaz Kylheku2021-06-041-0/+1
| | | | | | | * tests/011/patmatch.tl: New test case. * txr.1: Heading fix: Quasiquote matching notation, not quasiliteral. Examples of quasiquote notation added.
* json: pattern matching test cases and bugfix.Kaz Kylheku2021-06-031-0/+17
| | | | | | | | | | | | | * parser.y (json_val): We must nreverse the json_pairs which were pushed in right to left order. This didn't matter for constructing hashes so it was left out, but under quasiquoting the order matters: it determines the order of evaluation and of pattern matching. * tests/011/patmatch.tl: New quasiquoting pattern matching cases, including JSON. * y.tab.c.shipped: Regenerated.
* json: improve escaping for script tags.Kaz Kylheku2021-06-031-2/+12
| | | | | | | | | | | * lib.c (out_json_str): Strengthen the test for escaping the forward slash. It has to occur in the sequence </script rather than just </. Recognize <!-- and --> in the string, and encode them. * tests/010/json.tl: Cover this area with some tests. * txr.1: Documented.
* json: fix two test cases for Windows.Kaz Kylheku2021-06-021-2/+5
| | | | | | | | | | | | * tests/010/json.tl: on Windows characters are limited to the BMP range 0 to #\xFFFF. The character escape \x10437 is out of range, and so throws an error, simply from that syntax being read. The two test cases which use this character are clumped into their own test form, which is executed conditionally on wide characters being more than two bytes. Because the expression is still parsed on Windows, we read the troublesome character from a string at run-time, and interpolate it.
* json: wrap up: test cases, fixes, tweaks.Kaz Kylheku2021-05-312-0/+135
| | | | | | | | | | | | | | | | | | | | | * /share/txr/stdlib/getput.tl (get-jsons): If the s parameter is a string, convert it to a byte input stream so that. (put-jsons): Add missing t return value. (file-put-json, file-append-json, file-put-jsons, file-append-jsons, command-put-jsons, command-put-jsons): Add missing object argument to all these functions, and a missing "w" open-file mode to several of them. * stream.c (mkstemp_wrap): Calculate length of suff the defaulted argument, not the raw suffix argument. * test/010/json.tl: New file, providing tests that touch every area of the new JSON functionality. * tests/common.tl (mstest, with-temp-file): New macros. * txr.1: Document that get-jsons takes a source which could be a string.
* tests: fix vtest being hindrance to error finding.Kaz Kylheku2021-05-252-10/+13
| | | | | | | | | | | | | * tests/common.tl (vtest): Only if the expected expression is :error or (quote :error) do we wrap the expansion and evaluation of the test expression with exception handling, because only then do we expect an error. When the test expression is anything else, we don't intercept any errors, and so problems in test cases are easier to debug now. * tests/012/struct.tl: In one case we must initialize the *gensym-counter* to 4 to compensate for the change in vtest to get the same gensym numbers in the output.
* window-map: add tests, improve doc, add examples.Kaz Kylheku2021-05-251-0/+19
| | | | | | | * tests/012/seq.tl: New tests. * txr.1: Improve documentation of window-map's :wrap and :reflect. Add examples.
* window-map: broken :wrap and :reflect.Kaz Kylheku2021-05-251-0/+33
| | | | | | | | | | | * lib.c (window_map_list): Rewrite :wrap and :reflect support. The main issue with these is that they only sample items from the front of the input list and generate both flanks of the boundary from that prefix; :reflect is additionaly buggy due to applying nreverse to a sub which can return the original sequence. * tests/012/seq.tl: Some test coverage for window-map.
* matcher: allow hash pattern to omit values.Kaz Kylheku2021-05-241-0/+7
| | | | | | | | | | | | The @(hash ...) operator now allows key-only patterns like (42) or (@x), where x could be bound or unbound. This has separate semantics from when a value is present. * share/txr/stdlib/match.tl (compile-hash-match): Implement. * tests/011/patmatch.tl: Test. * txr.1: Document.
* match: binary-integer conv tests for #x-8000...Kaz Kylheku2021-05-211-0/+21
| | | | | | * tests/016/arith.tl: Test providing coverage for the most negative two's complement integer, #x-800...00 in various sizes. The 64 bit cases are failing.
* math: add some tests related to integer conversion.Kaz Kylheku2021-05-211-0/+50
| | | | | | * tests/016/arith.tl: Add tests covering the fixnum/bignum knee, and ffi operations of various sizes that provide coverage of various conversion routines.
* parser: bug: handing of lex state in pushback tokens.Kaz Kylheku2021-05-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is fairly obscure. A repro test case is a file which contains: 3"foo" When the 3 is parsed, the " is also scanned as a lookahead token, and when that happens, the lexer shifts into the STRLIT state. At that point the parse job finishes for that top-level form. The next time the parser is called, it will prime the token stream by pushing the " token into it. But, the lex state is not put into the STRLIT. State. The result is that the parser obtains the " token, and then foo is lexically analyzed in the wrong state as a symbol. A syntax error occurs: symbol token in the middle of a string literal, instead of just a sequence of LITCHAR tokens, as expected. What we can do is associate a lex state with pushback tokens. If a pushback token has a nonzero lex state which is different from the current YYSTATE, then when that pushback token is consumed, we push that state also. * parser.h (struct yy_token): New member, yy_lex_state. * parser.c (parser_common_init): Initialize the new yy_lex_state member of every token member of the parser structure. * parser.l (yylex): When feeding a pushed token to the parser, if that token has a nonzero state, and the state is different from YYSTATE, we push that state. So for instance a pushed back " token will carry the STRLIT state, which is different from the NESTED state that will be in effect at the start of the parse job, and so it will be pushed, as if the " character had been scanned. Also, when we call the real yylex_impl, when we are storing the recenty seen token in recent_tok, we also store the current YYSTATE along with it. That's how tokens get associated with a state. The artificial tokens that are used for priming parsing like SECRET_ESCAPE_E are never associated with a nonzero state. * tests/012/syntax.tl: Some test cases that didn't pass before this. * lex.yy.c.shipped: Regenerated.
* tree: let tree-iter be iterable via generic iteration.Kaz Kylheku2021-05-121-0/+5
| | | | | | | | | | * lib.c (seq_iter_init_with_info): Recognize tree_iter object, and treat using tree iterator function. * tests/010/tree.tl: test case for tree subrange iteration with collect-each. * txr.1: Updated.
* tree: streamline iteration; provide high limit.Kaz Kylheku2021-05-111-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Getting rid of tree-begin-at and tree-reset-at. Now tree-begin takes two optional parameters, for specifying high and low range. * tree.c (struct tree_diter): New members, tree and highkey. We need tree due to requiring access to the less function. If the iterator has no highkey, the iterator itself is stored in that member to indicate this. (tree_iter_mark): Mark the tree and highkey. (tree_begin): Take optional lowkey and highkey arguments, initializing iterator acordingly. (tree_begin_at): Function removed. (copy_tree_iter, replace_tree_iter): Copy tree and highkey members. The latter require special handling due to the funny convention for indicating highkey absence. (tree_reset): Take optional lowkey and highkey arguments, configuring these in the iterator being reset. (tree_reset_at): Function removed. (tree_next, tree_peek): Implement highkey semantics. (sub_tree): Simplified: from and to arguments are just passed through to tree_begin, and there is no need for a separate loop which enforces the upper limit, that now being handled by the iterator itself. (tree_begin): Update registrations of tree-begin and tree-reset; remove tree-begin-at and tree-reset-at intrinsics. * tree.h (tree_begin_at, tree_reset_at): Declarations removed. (tree_begin, tree_reset): Declarations updated. * lib.c (seq_iter_rewind, seq_iter_init_with_info, where, populate_obj_hash): Default new optional arguments in tree_begin and tree_reset calls. * parser.c (circ_backpatch): Likewise. * tests/010/tree.tl: Affected cases updated. * txr.1: Documentation updated. * share/txr/stdlib/doc-syms.tl: Regenerated.
* tree: support indexing and range extraction.Kaz Kylheku2021-05-111-0/+18
| | | | | | | | | | | | | | | | | | | * lib.c (do_generic_funcall): Support tree object invocation with one or two arguments via sub and ref. (sub): Implement for trees via sub_tree. (ref): Implement for trees via tree_lookup. * tree.c (sub_tree): New function. (tree_init): Register sub-tree intrinsic. * tree.h (sub_tree): Declared. * tests/010/tree.tl: New tests. * txr.1: Documented: DWIM bracket syntax on trees, sub and ref support for trees, sub-tree function, * share/txr/stdlib/doc-syms.tl: Regenerated.
* tree: replace-tree-iter function.Kaz Kylheku2021-05-111-0/+11
| | | | | | | | | | | | | * tree.c (replace_tree_iter): New function. (tree_init): Register replace-tree-iter intrinsic. * tree.h (tree_init): Declared. * share/txr/stdlib/doc-syms.tl: Updated. * txr.1: Documented. * tests/010/tree.tl: New test case.
* tree: copy-tree-iter function.Kaz Kylheku2021-05-101-0/+9
| | | | | | | | | | | | | | | * lib.c (copy): Handle tree_iter_s via copy_tree_iter. * tree.c (copy_tree_iter): New function. (tree_init): copy-tree-iter intrinsic registered. * tree.h (copy_tree_iter): Declared. * tests/010/tree.tl: New test case. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* diff/isec: reset hash/tree iter instead making new.Kaz Kylheku2021-05-102-0/+11
| | | | | | | | | | | * lib.c (seq_iter_rewind): Use hash_reset and tree_reset to rewind the existing iterator rather than allocating a new one. * tests/010/hash.tl: New file, covering uni, diff and isec for hash tables. * tests/010/tree.tl: New tests.
* tree: new tree-peek function.Kaz Kylheku2021-05-091-0/+8
| | | | | | | | | | | | | | * tree.c (tn_peek_next): New static function. (tree_peek): New function. (tree_init): Register tree-peek intrinsic. * tree.h (tree_peek): Declared. * txr.1: Documented. * tests/010/tree.c: Work tree-peek into existing test case. * share/txr/stdlib/doc-syms.tl: Updated.
* tree: new make_similar_tree unction.Kaz Kylheku2021-05-091-0/+8
| | | | | | | | | | | * tree.c (make_similar_tree): New function. (tree_init): Register make-similar-tree intrinsic * tree.h (make_similar_tree): Declared. * tests/010/tree.tl: New tests. * txr.1: Documented.