summaryrefslogtreecommitdiffstats
path: root/tests/010/json.tl
Commit message (Collapse)AuthorAgeFilesLines
* json: flat must override all effects of :standardKaz Kylheku2025-01-161-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | * stream.h (struct json_opts): Member flat removed. I noticed that !jo.flat was always being tested together with jo.fmt == json_fmt_standard. Except for a few places where the code only tested for json_fmt_standard, resulting in flat output, but some extra spaces. What distiguishes flat mode now is simply that we disable stream indentation. * lib.c (out_json_rec): Remove tests for !jo.flat. (out_json): Remove initialization of jo.flat member. In this function we set up indentation on the stream resulting in multi-line mode (existing behavior). (put_json): Remove initialization of jo.flat member. If flat mode is requested, then it overrides the format to json_fmt_default. I.e. json_fmt_standard coresponding to :standard is only in effect if flat is not requested. In this function we set up indentation on the stream if flat mode isn't requested, otherwise we disable indentation (existing behavior, enough to make flat work). * tests/010/json.tl: Tests for flat mode, :standard formatting, and combinaton of both.
* json: new *read-json-int* variable.Kaz Kylheku2024-07-221-0/+15
| | | | | | | | | | | | | | | | | | | | | * parser.h (struct parser): New member, read_json_int. * parser.c (read_json_int_s): New symbol variable for *read-json-int* symbol. (parser_common_init): Look up value of *read-json-int* and store in read_json_int struct member. (parse_init): Initialize read_json_int_s with interned symbol and also register the dynamic variable. * parser.l (grammar): Extend the {JNUM} rule to check the read_json_int flag and produce an integer value if the lexeme does not contain a decimal point, e or E. * tests/010/json.tl: New tests. * txr.1: Documented. * lex.yy.c.shipped: Regenerated.
* json: support Lisp comments.Kaz Kylheku2023-12-201-0/+3
| | | | | | | | | | | | | | | I've run into situations in which I wanted a comment in a big JSON quasiliteral to explain some embedded piece of code. We support only semicolon comments, and no #; ignore notation. * parser.l (grammar): Recognize Lisp comments in the JSON state also. That does it. * tests/010/json.tl: One modest little test. * txr.1: Documented. * lex.yy.c.shipped: Regenerated.
* json: allow integers and lists.Kaz Kylheku2023-09-031-0/+5
| | | | | | | | | | | | * lib.c (out_json_rec): Handle NUM and BGNUM cases same as FLNUM so integers get printed. The restriction against integers has been largely unhelpful and bothersome. Handle LCONS together with CONS. Lists that are not special notation fall through to the VEC case, which now uses seq_iter_t iteration to handle vectors and lists. * tests/010/json.tl: New tests. * txr.1: Documented support for printing integers and lists.
* json: add tests with multi-line literals.Kaz Kylheku2022-01-101-0/+10
| | | | | | * tests/010/json.tl: New tests. These work. Odd; I'm seeing an issue whereby typing multi-line #J expressions into the listener does not work.
* parser: allow trailing commas in json, via opt-in flag.Kaz Kylheku2021-07-291-0/+17
| | | | | | | | | | | | | | | | | | | | | | | * parser.c (read_bad_json_s): New symbol variable. (parser_common_init): Propagate value of *read-bad-json* into read_bad_json flag in parser structure. (parser_init): Initialize read_bad_json_s and register the *read-bad-json* dynamic variable. * parser.h (struct parser): New member, read_bad_json. (read_bad_json_s): Declared. * parser.y (json_val): Support an opt_comma symbol just before the closing bracket or brace. (opt_comma): New nonterminal symbol. Recognizes ',' or nothing. Error is flagged if ',' is recognized, and *read-bad-json* is nil. * y.tab.c.shipped: Updated. * tests/010/json.tl: New tests. * txr.1: Documented.
* tests: guix fixes.Kaz Kylheku2021-07-131-1/+1
| | | | | | | | | | | | | | | | * tests/002/query-1.txr: Skip test if an executable /bin/sh doesn't exist, rather than the bogus reasons. * tests/010/json.tl: Change the condition for the command-put-json tests: not whether cat is found in the search path but whether /bin/sh exists and is executable. * tests/017/realpath.tl: Also quit if /usr/bin doesn't exist. * tests/018/path-test.tl: Exit succesfully if /bin/sh does not exist. Revert the earlier change. * tests/018/process.tl: Quit if no executable /bin/sh exists.
* tests: json: skip tests relying on cat, if missing.Kaz Kylheku2021-07-121-7/+9
| | | | | | | * tests/010/json.tl: skip several test cases which rely on the cat utility for testing command-put-json, if the cat utility is not found in the search path. Reported and investigated by Paul A. Patience.
* tests: json: fix accidentally excluded tests.Kaz Kylheku2021-07-121-2/+2
| | | | | | * tests/010/json.tl: Fix several tests being excluded from the (mtest ...) form to which they are expected to belong, one of them having an extra quote in the expected value, too.
* read/get-json: reject trailing junk in string input.Kaz Kylheku2021-06-201-1/+21
| | | | | | | | | | | | | | | | | * 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.
* 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-311-0/+124
* /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.