Skip to content

Commit 5f43ca0

Browse files
committed
fix (revert) toText and add test
1 parent d353e38 commit 5f43ca0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/pure/List.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,13 @@ module {
833833

834834
public func toText<T>(list : List<T>, f : T -> Text) : Text {
835835
var text = "[";
836+
var first = false;
836837
forEach(
837838
list,
838839
func(item : T) {
839-
if (text.size() > 1) {
840+
if first {
841+
first := true
842+
} else {
840843
text #= ", "
841844
};
842845
text #= f item

test/pure/List.test.mo

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,19 @@ let fromIter = Suite.suite(
15671567
]
15681568
);
15691569

1570+
let toText = Suite.suite(
1571+
"fromIter",
1572+
[
1573+
Suite.test(
1574+
"small",
1575+
List.toText<Nat>(?(0, ?(1, null)), Nat.toText),
1576+
M.equals(
1577+
T.text "[0, 1x]"
1578+
)
1579+
)
1580+
]
1581+
);
1582+
15701583
Suite.run(
15711584
Suite.suite(
15721585
"List",
@@ -1603,7 +1616,8 @@ Suite.run(
16031616
zip,
16041617
split,
16051618
chunks,
1606-
fromIter
1619+
fromIter,
1620+
toText
16071621
]
16081622
)
16091623
)

0 commit comments

Comments
 (0)