Skip to content

Commit

Permalink
feat: add sort module to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghongkai committed Mar 7, 2023
1 parent 82b543f commit eb54dbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/source_modules.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions stdlib/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ func TestGetModules(t *testing.T) {
require.NotNil(t, mods.Get("text"))
}

func TestSortModule(t *testing.T) {
// sort.sort
expect(t, `
out := ""
data := [
{"name": "Alice", "score": 125},
{"name": "Bol", "score": -30},
{"name": "Charlie", "score": 125},
{"name": "Dave", "score": 35},
{"name": "Eva", "score": 25}
]
sort := import("sort")
sort.sort(data, func(i, j) {
return data[i]["score"] < data[j]["score"]
})
for item in data {
out += item["name"] + ": " + item["score"] + "\n"
}
`, "Bol: -30\nEva: 25\nDave: 35\nAlice: 125\nCharlie: 125\n")
}

type callres struct {
t *testing.T
o interface{}
Expand Down

0 comments on commit eb54dbb

Please sign in to comment.