Skip to content

Commit eb54dbb

Browse files
author
huanghongkai
committed
feat: add sort module to stdlib
1 parent 82b543f commit eb54dbb

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

stdlib/source_modules.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stdlib/stdlib_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ func TestGetModules(t *testing.T) {
9494
require.NotNil(t, mods.Get("text"))
9595
}
9696

97+
func TestSortModule(t *testing.T) {
98+
// sort.sort
99+
expect(t, `
100+
out := ""
101+
data := [
102+
{"name": "Alice", "score": 125},
103+
{"name": "Bol", "score": -30},
104+
{"name": "Charlie", "score": 125},
105+
{"name": "Dave", "score": 35},
106+
{"name": "Eva", "score": 25}
107+
]
108+
sort := import("sort")
109+
sort.sort(data, func(i, j) {
110+
return data[i]["score"] < data[j]["score"]
111+
})
112+
for item in data {
113+
out += item["name"] + ": " + item["score"] + "\n"
114+
}
115+
`, "Bol: -30\nEva: 25\nDave: 35\nAlice: 125\nCharlie: 125\n")
116+
}
117+
97118
type callres struct {
98119
t *testing.T
99120
o interface{}

0 commit comments

Comments
 (0)