plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
c459df0
— Peter John
2026-11-11T00:02:15+05:30
std: one equality method, eq; equals is gone from Slice, List, Time, Duration and Uuid
- compiler/core/src/prune.rs +2 -2
- compiler/core/src/uniqueness.rs +2 -2
- compiler/wasm-codegen/src/matching.rs +1 -1
- examples/recursion.plum +7 -7
- std/Slice.plum +7 -10
- std/Time.plum +2 -8
- std/Uuid.plum +5 -8
- std/collections/FenwickTree.plum +6 -6
- std/collections/LeftistHeap.plum +4 -4
- std/collections/List.plum +3 -6
- std/collections/PairingHeap.plum +3 -3
- std/collections/SegmentTree.plum +10 -10
- std/testing.plum +11 -13
compiler/core/src/prune.rs
CHANGED
|
@@ -18,9 +18,9 @@ use std::fmt::Write;
|
|
|
18
18
|
|
|
19
19
|
/// Method names the compiler calls with no call site in the source: interpolation, a
|
|
20
20
|
/// constructor's `init`, hashing and equality, the operators, the frame entry.
|
|
21
|
-
const IMPLICIT: [&str;
|
|
21
|
+
const IMPLICIT: [&str; 18] = [
|
|
22
22
|
"concat",
|
|
23
|
-
"toStr", "init", "
|
|
23
|
+
"toStr", "init", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
|
|
24
24
|
"ge", "update", "draw",
|
|
25
25
|
];
|
|
26
26
|
|
compiler/core/src/uniqueness.rs
CHANGED
|
@@ -447,8 +447,8 @@ fn varName(e: &Expr) -> Option<&str> {
|
|
|
447
447
|
/// Method names the compiler may call without a visible call site (interpolation,
|
|
448
448
|
/// constructors, hashing, the operators `a + b`, `-a`, `a == b`, `a < b`): their `self` and
|
|
449
449
|
/// parameters are never proved.
|
|
450
|
-
const IMPLICIT: [&str;
|
|
450
|
+
const IMPLICIT: [&str; 15] = [
|
|
451
|
-
"toStr", "init", "
|
|
451
|
+
"toStr", "init", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
|
|
452
452
|
"ge",
|
|
453
453
|
];
|
|
454
454
|
|
compiler/wasm-codegen/src/matching.rs
CHANGED
|
@@ -1238,7 +1238,7 @@ pub(crate) fn plumTypeFromValtypeHint(vt: ValType) -> PlumType {
|
|
|
1238
1238
|
/// checker's `op_calls` entry is shared by every instantiation of a generic body, so
|
|
1239
1239
|
/// the operand's type in THIS unit decides.
|
|
1240
1240
|
/// `==`/`!=` keep their built-in meaning on a type with no `eq` (as the checker decides
|
|
1241
|
-
/// per operand type): `h != h2` in `List<T>.
|
|
1241
|
+
/// per operand type): `h != h2` in `List<T>.eq` calls `eq` for `List<List<Int>>` and
|
|
1242
1242
|
/// not for `List<Pt>`.
|
|
1243
1243
|
pub(crate) fn isOpCall(expr: &ast::Expr, operand: &ast::Expr, ctx: &LocalCtx) -> bool {
|
|
1244
1244
|
let Some(call) = ctx.op_calls.get(&expr.id) else { return false };
|
examples/recursion.plum
CHANGED
|
@@ -173,7 +173,7 @@ test "reverse_append"
|
|
|
173
173
|
assert xs.get(0).unwrapOr(-1) == 3
|
|
174
174
|
assert xs.get(2).unwrapOr(-1) == 1
|
|
175
175
|
ys := [1, 2].append([3, 4])
|
|
176
|
-
assert ys.
|
|
176
|
+
assert ys.eq([1, 2, 3, 4])
|
|
177
177
|
|
|
178
178
|
test "for_range"
|
|
179
179
|
total := Tally(n: 0)
|
|
@@ -187,8 +187,8 @@ test "for_range"
|
|
|
187
187
|
|
|
188
188
|
test "to_slice_round_trip"
|
|
189
189
|
s := [1, 2, 3].map(|x| x * 2).toSlice()
|
|
190
|
-
assert s.
|
|
190
|
+
assert s.eq([2, 4, 6].toSlice())
|
|
191
|
-
assert List.fromSlice(s).
|
|
191
|
+
assert List.fromSlice(s).eq([2, 4, 6])
|
|
192
192
|
|
|
193
193
|
test "to_array"
|
|
194
194
|
a := [7, 8, 9].toArray()
|
|
@@ -207,10 +207,10 @@ test "cons_fold_million"
|
|
|
207
207
|
assert xs.reverse().get(0).unwrapOr(-1) == 999999
|
|
208
208
|
|
|
209
209
|
test "equals_and_toStr"
|
|
210
|
-
assert [1, 2, 3].
|
|
210
|
+
assert [1, 2, 3].eq([1, 2, 3])
|
|
211
|
-
assert ![1, 2, 3].
|
|
211
|
+
assert ![1, 2, 3].eq([1, 2])
|
|
212
|
-
assert ![1, 2].
|
|
212
|
+
assert ![1, 2].eq([1, 2, 3])
|
|
213
|
-
assert ![1, 2, 3].
|
|
213
|
+
assert ![1, 2, 3].eq([1, 2, 4])
|
|
214
214
|
assert [1, 2, 3].toStr() == "[1,2,3]"
|
|
215
215
|
|
|
216
216
|
# ==== own list tests ====
|
std/Slice.plum
CHANGED
|
@@ -110,13 +110,10 @@ struct Slice<T>(mut data: Array<T>, mut start: Int, mut size: Int, mut cap: Int)
|
|
|
110
110
|
fun length(self) -> Int =
|
|
111
111
|
self.size
|
|
112
112
|
|
|
113
|
-
# `==` and `!=`: the same length and the elements `==` in order
|
|
113
|
+
# `==` and `!=`: the same length and the elements `==` in order. Without it `==` on two
|
|
114
|
-
#
|
|
114
|
+
# slices would ask whether they are the same object. For a struct `T` without its own
|
|
115
|
-
fun eq(self, other: Slice<T>) -> Bool = self.equals(other)
|
|
116
|
-
|
|
117
|
-
# Elementwise comparison via `==`; for a struct `T` without its own `eq`, `==` is
|
|
118
|
-
# reference identity (the same object)
|
|
115
|
+
# `eq`, the elements' `==` is reference identity (the same object).
|
|
119
|
-
fun
|
|
116
|
+
fun eq(self, other: Slice<T>) -> Bool =
|
|
120
117
|
self.length() == other.length() && self.sameFrom(other, 0)
|
|
121
118
|
|
|
122
119
|
# Whether `self` and `other` (same length) agree from index `i` on.
|
|
@@ -477,8 +474,8 @@ test "list equals compares elementwise"
|
|
|
477
474
|
c := Slice<Int>()
|
|
478
475
|
c.push(1)
|
|
479
476
|
c.push(2)
|
|
480
|
-
assert a.
|
|
477
|
+
assert a.eq(b)
|
|
481
|
-
assert !a.
|
|
478
|
+
assert !a.eq(c)
|
|
482
479
|
|
|
483
480
|
test "list sort orders elements correctly"
|
|
484
481
|
l := Slice<Int>()
|
|
@@ -633,7 +630,7 @@ test "every method indexes from the view's start"
|
|
|
633
630
|
w.push(5)
|
|
634
631
|
w.push(3)
|
|
635
632
|
w.push(7)
|
|
636
|
-
assert v.
|
|
633
|
+
assert v.eq(w)
|
|
637
634
|
assert v.sublist(1, 3).toStr() == "[5,3]"
|
|
638
635
|
assert v.drop(2).toStr() == "[3,7]"
|
|
639
636
|
assert v.chunk(3).length() == 2
|
std/Time.plum
CHANGED
|
@@ -40,10 +40,7 @@ struct Time(value: Int) =
|
|
|
40
40
|
fun isAfter(self, other: Time) -> Bool =
|
|
41
41
|
self.value > other.value
|
|
42
42
|
|
|
43
|
-
fun equals(self, other: Time) -> Bool =
|
|
44
|
-
self.value == other.value
|
|
45
|
-
|
|
46
|
-
# `==` and `!=`:
|
|
43
|
+
# `==` and `!=`: the same value.
|
|
47
44
|
fun eq(self, other: Time) -> Bool = self.value == other.value
|
|
48
45
|
|
|
49
46
|
# The proleptic-Gregorian calendar date this instant falls on, in UTC.
|
|
@@ -161,10 +158,7 @@ struct Duration(value: Int) =
|
|
|
161
158
|
fun isAfter(self, other: Duration) -> Bool =
|
|
162
159
|
self.value > other.value
|
|
163
160
|
|
|
164
|
-
fun equals(self, other: Duration) -> Bool =
|
|
165
|
-
self.value == other.value
|
|
166
|
-
|
|
167
|
-
# `==` and `!=`:
|
|
161
|
+
# `==` and `!=`: the same value.
|
|
168
162
|
fun eq(self, other: Duration) -> Bool = self.value == other.value
|
|
169
163
|
|
|
170
164
|
test "Time.toStr formats the epoch as ISO 8601 in UTC"
|
std/Uuid.plum
CHANGED
|
@@ -17,10 +17,7 @@ struct Uuid(value: Str) =
|
|
|
17
17
|
fun toStr(self) -> Str =
|
|
18
18
|
self.value
|
|
19
19
|
|
|
20
|
-
fun equals(self, other: Uuid) -> Bool =
|
|
21
|
-
self.value == other.value
|
|
22
|
-
|
|
23
|
-
# `==` and `!=`:
|
|
20
|
+
# `==` and `!=`: the same value.
|
|
24
21
|
fun eq(self, other: Uuid) -> Bool = self.value == other.value
|
|
25
22
|
|
|
26
23
|
fun isNil(self) -> Bool =
|
|
@@ -153,12 +150,12 @@ test "fromStr rejects malformed input"
|
|
|
153
150
|
assert Uuid.isValid("550e8400-e29b-41d4-a716-44665544000") == false
|
|
154
151
|
assert Uuid.isValid("550e8400xe29b-41d4-a716-446655440000") == false
|
|
155
152
|
|
|
156
|
-
test "
|
|
153
|
+
test "eq compares by value"
|
|
157
154
|
a := Uuid(value: "550e8400-e29b-41d4-a716-446655440000")
|
|
158
155
|
b := Uuid(value: "550e8400-e29b-41d4-a716-446655440000")
|
|
159
|
-
assert a.
|
|
156
|
+
assert a.eq(b) == true
|
|
160
|
-
assert a.
|
|
157
|
+
assert a.eq(Uuid.nil()) == false
|
|
161
158
|
|
|
162
|
-
test "== is
|
|
159
|
+
test "== is eq"
|
|
163
160
|
a := Uuid.fromStr("123e4567-e89b-12d3-a456-426614174000")!
|
|
164
161
|
assert a == Uuid.fromStr("123E4567-E89B-12D3-A456-426614174000")! && a != Uuid.nil()
|
std/collections/FenwickTree.plum
CHANGED
|
@@ -254,7 +254,7 @@ test "ofList, get, set and toList"
|
|
|
254
254
|
g := f.set(2, 10)
|
|
255
255
|
assert g.get(2)! == 10
|
|
256
256
|
assert g.prefixSum(5) == 21
|
|
257
|
-
assert g.toList().
|
|
257
|
+
assert g.toList().eq([5, 1, 10, 2, 3])
|
|
258
258
|
assert fenValid(g)
|
|
259
259
|
|
|
260
260
|
test "edge cases: empty tree, out of range and clamped ranges"
|
|
@@ -292,9 +292,9 @@ test "persistence: old versions answer old queries"
|
|
|
292
292
|
assert c.prefixSum(3) == 7
|
|
293
293
|
assert b.rangeSum(2, 3) == 0
|
|
294
294
|
assert c.rangeSum(2, 3) == 5
|
|
295
|
-
assert a.toList().
|
|
295
|
+
assert a.toList().eq([0, 0, 0])
|
|
296
|
-
assert b.toList().
|
|
296
|
+
assert b.toList().eq([0, 7, 0])
|
|
297
|
-
assert c.toList().
|
|
297
|
+
assert c.toList().eq([0, 2, 5])
|
|
298
298
|
assert fenValid(a) && fenValid(b) && fenValid(c)
|
|
299
299
|
|
|
300
300
|
test "invariants_after_random_ops: adds and sets match a brute-force slice"
|
|
@@ -328,7 +328,7 @@ test "invariants_after_random_ops: adds and sets match a brute-force slice"
|
|
|
328
328
|
assert st.f.prefixSum(i) == st.pre
|
|
329
329
|
if i < n
|
|
330
330
|
st.pre = st.pre + brute.at(i)
|
|
331
|
-
assert st.f.toList().
|
|
331
|
+
assert st.f.toList().eq(List.fromSlice(brute))
|
|
332
332
|
|
|
333
333
|
test "ofList matches repeated add on 10,000 elements, and old versions keep their sums"
|
|
334
334
|
n := 10000
|
|
@@ -352,7 +352,7 @@ test "ofList matches repeated add on 10,000 elements, and old versions keep thei
|
|
|
352
352
|
c := a.set(0, 0).add(n - 1, 5)
|
|
353
353
|
assert c.prefixSum(n) == st.pre - xs.at(0) + 5
|
|
354
354
|
assert a.prefixSum(n) == st.pre
|
|
355
|
-
assert a.toList().
|
|
355
|
+
assert a.toList().eq(List.fromSlice(xs))
|
|
356
356
|
|
|
357
357
|
test "ofSize shares its nodes: a huge size with alternating bits builds in O(log n)"
|
|
358
358
|
# 0b1010...10 (50 bits): unshared halves made ~4e10 nodes and ran out of memory.
|
std/collections/LeftistHeap.plum
CHANGED
|
@@ -250,8 +250,8 @@ test "heapsort of pseudo-random lists matches Slice.sort"
|
|
|
250
250
|
xs := lhRandList(300, seed * 7919)
|
|
251
251
|
h := lhPushAll(lhInts(), xs)
|
|
252
252
|
assert lhValid(h)
|
|
253
|
-
assert h.toList().
|
|
253
|
+
assert h.toList().eq(lhSorted(xs))
|
|
254
|
-
assert LeftistHeap.fromList(xs, |a, b| a < b).toList().
|
|
254
|
+
assert LeftistHeap.fromList(xs, |a, b| a < b).toList().eq(lhSorted(xs))
|
|
255
255
|
|
|
256
256
|
test "fromList builds a valid heap"
|
|
257
257
|
h := LeftistHeap.fromList([4, 1, 3, 1, 5, 9, 2, 6], |a, b| a < b)
|
|
@@ -272,7 +272,7 @@ test "merge two heaps"
|
|
|
272
272
|
assert m.length() == 350
|
|
273
273
|
assert lhValid(m)
|
|
274
274
|
all := lhRandList(200, 3).append(lhRandList(150, 4))
|
|
275
|
-
assert m.toList().
|
|
275
|
+
assert m.toList().eq(lhSorted(all))
|
|
276
276
|
assert a.merge(lhInts()).toStr() == a.toStr()
|
|
277
277
|
assert lhInts().merge(a).toStr() == a.toStr()
|
|
278
278
|
assert a.length() == 200 && b.length() == 150
|
|
@@ -325,7 +325,7 @@ test "invariants hold through pseudo-random pushes and pops"
|
|
|
325
325
|
assert lhValid(s.h)
|
|
326
326
|
assert s.h.length() == model.length()
|
|
327
327
|
assert lhValid(s.h)
|
|
328
|
-
assert s.h.toList().
|
|
328
|
+
assert s.h.toList().eq(List.fromSlice(model.sort(|a, b| a < b)))
|
|
329
329
|
|
|
330
330
|
test "100,000 pushes then pops come out sorted"
|
|
331
331
|
s := LhRun(h: lhInts(), x: 99)
|
std/collections/List.plum
CHANGED
|
@@ -119,15 +119,12 @@ enum List<T> =
|
|
|
119
119
|
fun toStr(self) -> Str =
|
|
120
120
|
"[{self.join(",")}]"
|
|
121
121
|
|
|
122
|
-
# `==` and `!=`: the elements compare equal
|
|
122
|
+
# `==` and `!=`: the elements compare equal (`==`), in order.
|
|
123
|
-
fun eq(self, other: List<T>) -> Bool = self.equals(other)
|
|
124
|
-
|
|
125
|
-
# Elementwise comparison via `==`.
|
|
126
|
-
fun
|
|
123
|
+
fun eq(self, other: List<T>) -> Bool = match self
|
|
127
124
|
Nil => other.isEmpty()
|
|
128
125
|
Cons(h, t) => match other
|
|
129
126
|
Nil => false
|
|
130
|
-
Cons(h2, t2) => if h != h2 then false else t.
|
|
127
|
+
Cons(h2, t2) => if h != h2 then false else t.eq(t2)
|
|
131
128
|
|
|
132
129
|
# `fromSlice`'s loop: conses `xs[i]`, `xs[i-1]`, ... down to index 0 onto `out`.
|
|
133
130
|
fun consFrom<A>(xs: Slice<A>, i: Int, out: List<A>) -> List<A> =
|
std/collections/PairingHeap.plum
CHANGED
|
@@ -253,7 +253,7 @@ test "heapsort of pseudo-random lists matches Slice.sort"
|
|
|
253
253
|
xs := phRandList(300, seed * 7919)
|
|
254
254
|
h := phPushAll(phInts(), xs)
|
|
255
255
|
assert phValid(h)
|
|
256
|
-
assert h.toList().
|
|
256
|
+
assert h.toList().eq(phSorted(xs))
|
|
257
257
|
|
|
258
258
|
test "fromList builds a valid heap"
|
|
259
259
|
h := PairingHeap.fromList([4, 1, 3, 1, 5, 9, 2, 6], |a, b| a < b)
|
|
@@ -270,7 +270,7 @@ test "merge two heaps"
|
|
|
270
270
|
assert m.length() == 350
|
|
271
271
|
assert phValid(m)
|
|
272
272
|
all := phRandList(200, 3).append(phRandList(150, 4))
|
|
273
|
-
assert m.toList().
|
|
273
|
+
assert m.toList().eq(phSorted(all))
|
|
274
274
|
assert a.merge(phInts()).toStr() == a.toStr()
|
|
275
275
|
assert phInts().merge(a).toStr() == a.toStr()
|
|
276
276
|
assert a.length() == 200 && b.length() == 150
|
|
@@ -323,7 +323,7 @@ test "invariants hold through pseudo-random pushes and pops"
|
|
|
323
323
|
assert phValid(s.h)
|
|
324
324
|
assert s.h.length() == model.length()
|
|
325
325
|
assert phValid(s.h)
|
|
326
|
-
assert s.h.toList().
|
|
326
|
+
assert s.h.toList().eq(List.fromSlice(model.sort(|a, b| a < b)))
|
|
327
327
|
|
|
328
328
|
test "10,000 inserts then repeated deleteMin"
|
|
329
329
|
h := phPushAll(phInts(), phRandList(10000, 5))
|
std/collections/SegmentTree.plum
CHANGED
|
@@ -274,16 +274,16 @@ test "sum tree: query, get, set, length and all"
|
|
|
274
274
|
assert u.get(3)! == 10
|
|
275
275
|
assert u.query(3, 5) == 13
|
|
276
276
|
assert u.all() == 23
|
|
277
|
-
assert u.toList().
|
|
277
|
+
assert u.toList().eq([5, 1, 4, 10, 3])
|
|
278
278
|
assert segValid(u)
|
|
279
279
|
|
|
280
280
|
test "update applies a function to one element"
|
|
281
281
|
s := segSum([1, 2, 3, 4])
|
|
282
282
|
u := s.update(2, |x| x * 10).update(0, |x| x - 1)
|
|
283
|
-
assert u.toList().
|
|
283
|
+
assert u.toList().eq([0, 2, 30, 4])
|
|
284
284
|
assert u.all() == 36
|
|
285
285
|
assert u.query(1, 3) == 32
|
|
286
|
-
assert s.update(4, |x| x + 1).toList().
|
|
286
|
+
assert s.update(4, |x| x + 1).toList().eq(s.toList())
|
|
287
287
|
assert s.update(-1, |x| x + 1).all() == 10
|
|
288
288
|
assert segValid(u)
|
|
289
289
|
|
|
@@ -324,7 +324,7 @@ test "ofSize starts at identity, and ofList over a product"
|
|
|
324
324
|
w := z.set(5, 4).set(0, 1)
|
|
325
325
|
assert w.query(0, 6) == 5
|
|
326
326
|
assert w.query(1, 5) == 0
|
|
327
|
-
assert w.toList().
|
|
327
|
+
assert w.toList().eq([1, 0, 0, 0, 0, 4])
|
|
328
328
|
assert segValid(w)
|
|
329
329
|
assert z.all() == 0
|
|
330
330
|
|
|
@@ -362,9 +362,9 @@ test "persistence: old versions answer old queries"
|
|
|
362
362
|
assert c.all() == 7
|
|
363
363
|
assert b.query(2, 3) == 0
|
|
364
364
|
assert c.query(2, 3) == 5
|
|
365
|
-
assert a.toList().
|
|
365
|
+
assert a.toList().eq([0, 0, 0])
|
|
366
|
-
assert b.toList().
|
|
366
|
+
assert b.toList().eq([0, 7, 0])
|
|
367
|
-
assert c.toList().
|
|
367
|
+
assert c.toList().eq([0, 2, 5])
|
|
368
368
|
assert segValid(a) && segValid(b) && segValid(c)
|
|
369
369
|
|
|
370
370
|
test "invariants_after_random_ops: sets and queries match brute force for sum, min, max and concat"
|
|
@@ -400,7 +400,7 @@ test "invariants_after_random_ops: sets and queries match brute force for sum, m
|
|
|
400
400
|
assert st.mx.query(lo, hi) == want.mx
|
|
401
401
|
assert st.cat.query(lo, hi) == want.cat
|
|
402
402
|
assert segValid(st.sum)
|
|
403
|
-
assert st.sum.toList().
|
|
403
|
+
assert st.sum.toList().eq(List.fromSlice(brute))
|
|
404
404
|
|
|
405
405
|
test "10,000 elements: build, every prefix, random updates and the old version"
|
|
406
406
|
n := 10000
|
|
@@ -428,10 +428,10 @@ test "10,000 elements: build, every prefix, random updates and the old version"
|
|
|
428
428
|
_ := xs.set(j, v)
|
|
429
429
|
seed.s = seed.s.set(j, v)
|
|
430
430
|
assert seed.s.all() == seed.pre
|
|
431
|
-
assert seed.s.toList().
|
|
431
|
+
assert seed.s.toList().eq(List.fromSlice(xs))
|
|
432
432
|
assert segValid(seed.s)
|
|
433
433
|
assert first.all() == firstAll
|
|
434
|
-
assert first.toList().
|
|
434
|
+
assert first.toList().eq(firstList)
|
|
435
435
|
|
|
436
436
|
test "ofList over struct elements"
|
|
437
437
|
vs := Cons(head: Vec2(x: 1.0, y: 2.0), tail: Cons(head: Vec2(x: 3.0, y: 4.0), tail: Cons(head: Vec2(x: 5.0, y: 6.0), tail: Nil)))
|
std/testing.plum
CHANGED
|
@@ -25,14 +25,12 @@ import std/Result
|
|
|
25
25
|
# `unwrapOr` (`r.unwrapOr(0)`, `r!`); `expectFailureNamed` also checks which error it is
|
|
26
26
|
# (the error enum provides `fun name(self) -> Str`).
|
|
27
27
|
#
|
|
28
|
-
# CAVEAT on `expectEq`/`expectNotEq`/`expectObject`/`
|
|
28
|
+
# CAVEAT on `expectEq`/`expectNotEq`/`expectObject`/`expectArray`: `==`/`!=`
|
|
29
|
-
# `
|
|
29
|
+
# call the type's `eq(self, other)` method when it has one (Int/Str/Bool/Float,
|
|
30
|
-
# they do real value comparison (Str is content-compared, not
|
|
31
|
-
#
|
|
30
|
+
# `Slice`, `List`, `Map`, `Uuid`, `Time`, ...). A struct or enum without an
|
|
32
|
-
#
|
|
31
|
+
# `eq` compares by reference identity, so `expectEq` on two
|
|
33
|
-
# separately-constructed-but-equal
|
|
32
|
+
# separately-constructed-but-equal values of such a type reports `false`:
|
|
34
|
-
# those types, prefer the type's own `equals(self, other)` method (e.g.
|
|
35
|
-
#
|
|
33
|
+
# give the type an `eq`.
|
|
36
34
|
|
|
37
35
|
fun expectTrue(cond: Bool) -> Bool =
|
|
38
36
|
cond
|
|
@@ -53,9 +51,9 @@ fun expectObject<T>(a: T, b: T) -> Bool =
|
|
|
53
51
|
a == b
|
|
54
52
|
|
|
55
53
|
# Elementwise `Slice<T>` comparison — see the module-level CAVEAT above for
|
|
56
|
-
# what
|
|
54
|
+
# what the elements' `==` means when `T` is a struct/enum.
|
|
57
55
|
fun expectArray<T>(a: Slice<T>, b: Slice<T>) -> Bool =
|
|
58
|
-
a.
|
|
56
|
+
a.eq(b)
|
|
59
57
|
|
|
60
58
|
fun expectSuccess<T, E>(r: Result<T, E>) -> Bool = match r
|
|
61
59
|
Ok(_) => true
|
|
@@ -88,12 +86,12 @@ test "expectEq and expectNotEq"
|
|
|
88
86
|
assert expectEq("ab".concat("c"), "abc")
|
|
89
87
|
assert expectNotEq(2 + 2, 5)
|
|
90
88
|
|
|
91
|
-
test "list equality via the Slice.
|
|
89
|
+
test "list equality via the Slice.eq method"
|
|
92
90
|
a := [1, 2, 3].toSlice()
|
|
93
91
|
b := [1, 2, 3].toSlice()
|
|
94
92
|
c := [1, 2].toSlice()
|
|
95
|
-
assert a.
|
|
93
|
+
assert a.eq(b)
|
|
96
|
-
assert expectFalse(a.
|
|
94
|
+
assert expectFalse(a.eq(c))
|
|
97
95
|
|
|
98
96
|
test "Results are inspected with unwrapOr and !"
|
|
99
97
|
ok: Result<Int, Oops> := Ok(5)
|