From 88640e677fa0695783eac68014d7d8d5bc42d117 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Feb 2024 12:23:10 +0200 Subject: Add string_set buildfile value type This exposes the std::set type to buildfiles. New functions: $size() 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 ... --- tests/type/set/buildfile | 4 ++++ tests/type/set/testscript | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/type/set/buildfile create mode 100644 tests/type/set/testscript (limited to 'tests/type') diff --git a/tests/type/set/buildfile b/tests/type/set/buildfile new file mode 100644 index 0000000..55b37bb --- /dev/null +++ b/tests/type/set/buildfile @@ -0,0 +1,4 @@ +# file : tests/type/set/buildfile +# license : MIT; see accompanying LICENSE file + +./: testscript $b diff --git a/tests/type/set/testscript b/tests/type/set/testscript new file mode 100644 index 0000000..3897220 --- /dev/null +++ b/tests/type/set/testscript @@ -0,0 +1,52 @@ +# file : tests/type/set/testscript +# license : MIT; see accompanying LICENSE file + +# See also tests in function/*/ (size()). + +.include ../../common.testscript + +: basics +: +$* <>EOO +s = [string_set] a b a +print $s +s += c b +print $s +s =+ d b +print $s +EOI +a b +a b c +a b c d +EOO + +: type +: +$* <>EOO +s = [string_set] +print $type($s) +EOI +string_set +EOO + +: subscript +: +$* <>EOO +s = [string_set] a b c +print ($s[b]) +print ($s[z]) +EOI +true +false +EOO + +: iteration +: +$* <>EOO +for s: [string_set] a b c + print $s +EOI +a +b +c +EOO -- cgit v1.1