aboutsummaryrefslogtreecommitdiff
path: root/tests/function
AgeCommit message (Collapse)AuthorFilesLines
2024-04-01Add $string.replace() functionBoris Kolpackov1-0/+45
2024-02-20Add json_map and json_set buildfile value typesBoris Kolpackov1-1/+12
These expose the std::map<json_value,json_value> and std::set<json_value> types to buildfiles. New functions: $size(<json-set>) $size(<json-map>) $keys(<json-map>) Note that the $keys() function returns the list of map key as a json array. For example: m = [json_map] 2@([json] a@1 b@2) 1@([json] 1 2) s = [json_set] ([json] x@1 y@2) ([json] a@1 b@2) print ($m[2][b]) # 2 print ($s[([json] y@2 x@1)]) # true
2024-02-20Add string_set buildfile value typeBoris Kolpackov1-1/+2
This exposes the std::set<std::string> type to buildfiles. New functions: $size(<string-set>) Subscript returns true if the value is present and false otherwise (so it is mapped to std::set::contains()). For example: set = [string_set] a b c if ($set[b]) ... Note that append (+=) and prepend (=+) have the same semantics (std::set::insert()). For example: set = [string_set] a b set += c b # a b c set =+ d b # a b c d Example of iteration: set = [string_set] a b c for k: $set ...
2024-02-19Add string_map buildfile value typeBoris Kolpackov1-2/+8
This exposes the std::map<std::string,std::string> type to buildfiles. New functions: $size(<string-map>) $keys(<string-map>) Subscript can be used to lookup a value by key. The result is [null] if there is no value associated with the specified key. For example: map = [string_map] a@1 b@2 c@3 b = ($map[b]) # 2 if ($map[z] == [null]) ... Note that append (+=) is overriding (like std::map::insert_or_assign()) while prepend (=+) is not (like std::map::insert()). In a sense, whatever appears last (from left to right) is kept, which is consistent with what we expect to happen when specifying the same key repeatedly in a literal representation. For example: map = [string_map] a@0 b@2 a@1 # a@1 b@2 map += b@0 c@3 # a@1 b@0 c@3 map =+ b@1 d@4 # a@1 b@0 c@3 d@4 Example of iteration: map = [string_map] a@1 b@2 c@3 for p: $map { k = $first($p) v = $second($p) } While the subscript is mapped to key lookup only, index-based access can be implemented (with a bit of overhead) using the $keys() function: map = [string_map] a@1 b@2 c@3 keys = $keys($m) for i: $integer_sequence(0, $size($keys)) { k = ($keys[$i]) v = ($map[$k]) } Also, this commit changes the naming of other template-based value types (not exposed as buildfile value types) to use C++ template id-like names (e.g., map<string,optional<bool>>).
2024-02-07Add $json.object_names() functionBoris Kolpackov1-15/+37
2024-02-07Tweak $json.*() function names and semanticsBoris Kolpackov1-19/+19
2024-02-07Use reverse to fundamental types semantics in $json.member_value()Boris Kolpackov1-1/+1
Feels like this is an equivalent context to subscript/iteration.
2024-02-07Add experimental support for JSON value typesBoris Kolpackov3-0/+231
New types: json json_array json_object New functions: $json.value_type(<json>) $json.value_size(<json>) $json.member_{name,value}(<json-member>) $json.object_names(<json-object>) $json.array_size(<json-array>) $json.array_find(<json-array>, <json>) $json.array_find_index(<json-array>, <json>) $json.load(<path>) $json.parse(<text>) $json.serialize(<json>[, <indentation>]) For example, to load a JSON value from a file: j = $json.load($src_base/board.json) Or to construct it in a buildfile: j = [json] one@1 two@([json] 2 3 4) three@([json] x@1 y@-1) This can also be done incrementally with append/prepend: j = [json_object] j += one@1 j += two@([json] 2 3 4) j += three@([json] x@1 y@-1) Instead of using this JSON-like syntax, one can also specify valid JSON input text: j = [json] '{"one":1, "two":[2, 3, 4], "three":{"x":1, "y":-1}' Besides the above set of functions, other handy ways to access components in a JSON value are iteration and subscript. For example: for m: $j print $member_name($m) $member_value($m) print ($j[three]) A subscript can be nested: print ($j[two][1]) print ($j[three][x]) While a JSON value can be printed directly like any other value, the representation will not be pretty-printed. As a result, for complex JSON values, printing a serialized representation might be a more readable option: info $serialize($j)
2023-11-02Add $first()/$second() pair functionsBoris Kolpackov1-0/+25
2023-05-30Add $path.posix_string() and $path.posix_representation() functionsKaren Arutyunov1-0/+72
2022-12-15Add $regex.filter[_out]_{match,search}() functionsKaren Arutyunov1-0/+116
2022-09-30Move integer and bool function to separate source/testscript filesBoris Kolpackov3-39/+47
2022-09-29Add $find(<sequence>, <value>), $find_index(<sequence>, <value>) functionsBoris Kolpackov4-2/+60
The $find() function returns true if the sequence contains the specified value. The $find_index() function returns the index of the first element in the sequence that is equal to the specified value or $size(<sequence>) if none is found. For string sequences, it's possible to request case- insensitive comparison with a flag.
2022-09-23Add $is_a(<name>, <target-type>), $filter[_out](<names>, <target-types>) ↵Boris Kolpackov1-0/+36
functions $is_a() returns true if the <name>'s target type is-a <target-type>. Note that this is a dynamic type check that takes into account target type inheritance. $filter[_out]() return names with target types which are-a (filter) or not are-a (filter_out) one of <target-types>. In particular, these functions are useful for filtering prerequisite targets ($<) in ad hoc recipes and rules.
2022-09-22Add $integer_sequence(<begin>, <end>[, <step>]) functionBoris Kolpackov1-0/+8
It returns the list of uint64 integers starting from <begin> (including) to <end> (excluding) with the specified <step> or 1 if unspecified. For example: hdr = foo.hxx bar.hxx baz.hxx src = foo.cxx bar.cxx baz.cxx assert ($size($hdr) == $size($src)) "hdr and src expected to be parallel" for i: $integer_sequence(0, $size($hdr)) { h = ($hdr[$i]) s = ($src[$i]) ... }
2022-09-22Add support for hex notation for uint64 typeBoris Kolpackov1-0/+8
Specifically, now we can do: x = [uint64] 0x0000ffff cxx.poptions += "-DOFFSET=$x" # -DOFFSET=65535 cxx.poptions += "-DOFFSET=$string($x, 16)" # -DOFFSET=0xffff cxx.poptions += "-DOFFSET=$string($x, 16, 8)" # -DOFFSET=0x0000ffff Note that there is no hex notation support for the int64 (signed) type.
2021-12-02Fix path function test failure on WindowsBoris Kolpackov1-1/+1
2021-12-02Add $root_directory(<path>) functionBoris Kolpackov1-0/+22
2021-12-02Add $relative(<path>,<dir-path>) functionBoris Kolpackov1-0/+6
2021-11-26Add $size(string), $size(path), and $size(dir_path) functionsBoris Kolpackov2-0/+18
2021-11-04Fix testBoris Kolpackov1-1/+1
2021-11-04Add $size() function to get size of sequence (names, strings, etc)Boris Kolpackov3-5/+24
2021-11-02Add $sort() functionBoris Kolpackov3-1/+34
Available overloads: $sort(<names> [, <flags>]) $sort(<ints> [, <flags>]) $sort(<strings> [, <flags>]) $sort(<paths> [, <flags>]) $sort(<dir_paths> [, <flags>]) The following flag is supported by the all overloads: dedup - in addition to sorting also remove duplicates Additionally, the strings overload also support the following flag: icase - sort ignoring case Note that on case-insensitive filesystem the paths and dir_paths overload's order is case-insensitive.
2021-09-14Consistently install prerequisites from any scope by defaultBoris Kolpackov1-0/+1
It is also now possible to adjust this behavior with global config.install.scope override. Valid values for this variable are: project -- only from project strong -- from strong amalgamation weak -- from weak amalgamation global -- from all projects (default)
2020-12-08Redo $normalize(true) as separate $actualize()Karen Arutyunov1-9/+12
2020-09-28Add $string.trim() functionBoris Kolpackov1-0/+7
2020-07-18Add $regex.find_match() and $regex.find_search() functionsKaren Arutyunov1-0/+84
2020-04-03Skip unmatched lines in $regex.replace_lines() if format_no_copy flag is ↵Karen Arutyunov1-0/+20
specified
2020-03-17Add $defined(<variable>) functionBoris Kolpackov1-2/+17
2020-02-12Add builtins support for $process.run*() functionsKaren Arutyunov1-16/+128
2020-02-07Drop copyright notice from source codeKaren Arutyunov14-14/+0
2019-11-15Generalize attributes to be comma-separated with arbitrary valuesBoris Kolpackov1-3/+3
Before: x = [string null] After: x = [string, null]
2019-11-14Require attributes to be separated from words and similar on RHSBoris Kolpackov1-1/+1
2019-11-08Add $regex.replace_lines() functionKaren Arutyunov1-0/+82
2019-11-05Fix testsBoris Kolpackov5-4/+24
2019-10-01Add support for $string.icasecmp()Karen Arutyunov2-0/+32
2019-10-01Make $regex.{match,search}() to return NULL for no match if return_match or ↵Karen Arutyunov1-4/+4
return_match flag is specified
2019-10-01Rename $filesystem.path_match() to $path.match()Karen Arutyunov2-79/+79
2019-10-01Adapt to swapping of entry and pattern parameters in butl::path_match()Karen Arutyunov1-19/+19
2019-01-16Update copyright yearKaren Arutyunov12-12/+12
2018-09-04Rename .test/test{} to .testscript/testscript{}Boris Kolpackov6-6/+6
2018-07-16Resolve function overload via the argument reversal to untypedBoris Kolpackov2-14/+2
2018-06-20Add $process.run() and $process.run_regex() functionsBoris Kolpackov2-0/+35
$process.run(<prog>[ <args>...]) Return trimmed stdout. $process.run_regex(<prog>[ <args>...], <pat> [, <fmt>]) Return stdout lines matched and optionally processed with regex. Each line of stdout (including the customary trailing blank) is matched (as a whole) against <pat> and, if successful, returned, optionally processed with <fmt>, as an element of a list.
2018-05-19Update copyright yearKaren Arutyunov10-10/+10
2018-05-19Get rid of doc{version} and types for testscript and manifest in buildfilesKaren Arutyunov5-5/+5
2017-11-10Add $directory(), $base(), $leaf() and $extension() functionsKaren Arutyunov1-0/+65
2017-09-11Add ability to pass scope to buildfile functions, add $install.resolve()Boris Kolpackov2-0/+38
2017-08-30Add $regex.split(), $regex.merge() and $regex.apply() functionsKaren Arutyunov1-0/+96
2017-06-27Add support for regex function familyKaren Arutyunov2-0/+260
2017-06-26Add support for $path_search() and $path_match()Karen Arutyunov2-0/+160