Skip to content

Commit 7c74c9c

Browse files
well-in-that-caseSainan
authored andcommitted
Document assert.contains
1 parent fa6e668 commit 7c74c9c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/Runtime Environment/Assert.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,19 @@ pluto: test.pluto:4 -> Assertion Error: (assert.searcherror)
328328
Absent String: argument
329329
Error Message: something s
330330
--]]
331+
```
332+
---
333+
### `assert.contains`
334+
Asserts that `element` is contained inside of `container` by using Pluto's modified `in` operator.
335+
It's important to understand the type constraints of `in` to understand the type constraints here.
336+
#### Parameters
337+
1. `element` — The element to search for. If `container` is a string, `element` must be a string. If `container` is a table, `element` can be any type.
338+
2. `container` — The container that `element` should be inside of. The `container` should be a string or table.
339+
#### Errors
340+
An assertion error is thrown if:
341+
1. `element` is not contained inside of `container`.
342+
2. `element` or `container` are of the wrong type and cannot be used with Pluto's modified `in` operator.
343+
```pluto showLineNumbers
344+
assert.contains("hello", { "hello", "world" }) --> Passes.
345+
assert.contains("world", { "hello", "hello" }) --> Fails.
331346
```

0 commit comments

Comments
 (0)