-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cbbfcb
commit d5ba780
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub type Map(key, value) | ||
|
||
@external(javascript, "../../ffi.mjs", "map_new") | ||
pub fn new() -> Map(key, value) | ||
|
||
@external(javascript, "../../ffi.mjs", "map_set") | ||
pub fn set(a: Map(key, value), b: key, c: value) -> Map(key, value) | ||
|
||
@external(javascript, "../../ffi.mjs", "map_get") | ||
pub fn get(a: Map(key, value), b: key) -> Result(value, Nil) | ||
|
||
@external(javascript, "../../ffi.mjs", "map_size") | ||
pub fn size(a: Map(key, value)) -> Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gleam/javascript/map | ||
import gleeunit/should | ||
|
||
pub fn map_size_test() { | ||
let m = map.new() | ||
should.equal(map.size(m), 0) | ||
|
||
map.set(m, "a", 1) | ||
should.equal(map.size(m), 1) | ||
|
||
map.set(m, "b", 1) | ||
should.equal(map.size(m), 2) | ||
|
||
map.set(m, "b", 10) | ||
should.equal(map.size(m), 2) | ||
} | ||
|
||
pub fn map_retrieve_test() { | ||
let m = map.new() | ||
should.equal(map.get(m, "a"), Error(Nil)) | ||
|
||
map.set(m, "a", 1) | ||
should.equal(map.get(m, "a"), Ok(1)) | ||
|
||
map.set(m, "a", 2) | ||
should.equal(map.get(m, "a"), Ok(2)) | ||
} |