aboutsummaryrefslogtreecommitdiff
path: root/api/tables.yaml
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-21 23:23:59 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-21 23:23:59 -0400
commit5824a2ef19879c59866667aced6b3f90e5925648 (patch)
treea18ddeadb0c164c7a544b571c3968f86afb759ba /api/tables.yaml
parentbf067544e98f4085c26161953e301aaa00a904df (diff)
Update docs with proper assertions
Diffstat (limited to 'api/tables.yaml')
-rw-r--r--api/tables.yaml54
1 files changed, 20 insertions, 34 deletions
diff --git a/api/tables.yaml b/api/tables.yaml
index ce56c77e..e03805dc 100644
--- a/api/tables.yaml
+++ b/api/tables.yaml
@@ -12,7 +12,9 @@ Table.clear:
description: >
The reference to the table.
example: |
- >> t.clear()
+ t := &{"A":1}
+ t.clear()
+ assert t == {}
Table.difference:
short: return a table using keys not present in both tables
@@ -58,18 +60,11 @@ Table.get:
description: >
The key whose associated value is to be retrieved.
example: |
- >> t := {"A": 1, "B": 2}
- >> t.get("A")
- = 1?
-
- >> t.get("????")
- = none
-
- >> t.get("A")!
- = 1
-
- >> t.get("????") or 0
- = 0
+ t := {"A": 1, "B": 2}
+ assert t.get("A") == 1
+ assert t.get("????") == none
+ assert t.get("A")! == 1
+ assert t.get("????") or 0 == 0
Table.get_or_set:
short: get an item or set a default if absent
@@ -100,16 +95,13 @@ Table.get_or_set:
description: >
The default value to insert and return if the key is not present in the table.
example: |
- >> t := &{"A": @[1, 2, 3]; default=@[]}
- >> t.get_or_set("A").insert(4)
- >> t.get_or_set("B").insert(99)
- >> t
- = &{"A": @[1, 2, 3, 4], "B": @[99]}
+ t := &{"A": @[1, 2, 3]; default=@[]}
+ t.get_or_set("A").insert(4)
+ t.get_or_set("B").insert(99)
+ assert t == &{"A": @[1, 2, 3, 4], "B": @[99]}
- >> t.get_or_set("C", @[0, 0, 0])
- = @[0, 0, 0]
- >> t
- = &{"A": @[1, 2, 3, 4], "B": @[99], "C": @[0, 0, 0]}
+ assert t.get_or_set("C", @[0, 0, 0]) == @[0, 0, 0]
+ assert t == &{"A": @[1, 2, 3, 4], "B": @[99], "C": @[0, 0, 0]}
Table.has:
short: check for a key
@@ -129,10 +121,8 @@ Table.has:
description: >
The key to check for presence.
example: |
- >> {"A": 1, "B": 2}.has("A")
- = yes
- >> {"A": 1, "B": 2}.has("xxx")
- = no
+ assert {"A": 1, "B": 2}.has("A") == yes
+ assert {"A": 1, "B": 2}.has("xxx") == no
Table.intersection:
short: return a table with common key/value pairs from two tables
@@ -177,8 +167,7 @@ Table.remove:
example: |
t := {"A": 1, "B": 2}
t.remove("A")
- >> t
- = {"B": 2}
+ assert t == {"B": 2}
Table.set:
short: set a table entry
@@ -204,8 +193,7 @@ Table.set:
example: |
t := {"A": 1, "B": 2}
t.set("C", 3)
- >> t
- = {"A": 1, "B": 2, "C": 3}
+ assert t == {"A": 1, "B": 2, "C": 3}
Table.with:
short: return a table with values added from another table
@@ -273,8 +261,6 @@ Table.with_fallback:
example: |
t := {"A": 1; fallback={"B": 2}}
t2 = t.with_fallback({"B": 3"})
- >> t2["B"]
- = 3?
+ assert t2["B"] == 3
t3 = t.with_fallback(none)
- >> t2["B"]
- = none
+ assert t2["B"] == none