diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-05-29 21:02:55 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-06-02 21:12:59 +0100 |
commit | 5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31 (patch) | |
tree | 5d0d281c66cf71c6e3ca880e6621138a71b95e7b /test/std/int_test.gleam | |
parent | ee03f5a0465e176e220060164a5ffc408f73ed0d (diff) | |
download | gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.tar.gz gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.zip |
Enable namespaced modules
Diffstat (limited to 'test/std/int_test.gleam')
-rw-r--r-- | test/std/int_test.gleam | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/std/int_test.gleam b/test/std/int_test.gleam new file mode 100644 index 0000000..63e9d50 --- /dev/null +++ b/test/std/int_test.gleam @@ -0,0 +1,73 @@ +import std/expect +import std/int +import std/order + +pub fn to_string() { + 123 + |> int:to_string + |> expect:equal(_, "123") + + -123 + |> int:to_string + |> expect:equal(_, "-123") + + 0123 + |> int:to_string + |> expect:equal(_, "123") +} + +pub fn parse() { + "123" + |> int:parse + |> expect:equal(_, Ok(123)) + + "-123" + |> int:parse + |> expect:equal(_, Ok(-123)) + + "0123" + |> int:parse + |> expect:equal(_, Ok(123)) + + "" + |> int:parse + |> expect:is_error + + "what" + |> int:parse + |> expect:is_error + + "1.23" + |> int:parse + |> expect:is_error +} + +pub fn to_base_string() { + 100 + |> int:to_base_string(_, 16) + |> expect:equal(_, "64") + + -100 + |> int:to_base_string(_, 16) + |> expect:equal(_, "-64") +} + +pub fn compare_test() { + int:compare(0, 0) + |> expect:equal(_, order:Eq) + + int:compare(1, 1) + |> expect:equal(_, order:Eq) + + int:compare(0, 1) + |> expect:equal(_, order:Lt) + + int:compare(-2, -1) + |> expect:equal(_, order:Lt) + + int:compare(2, 1) + |> expect:equal(_, order:Gt) + + int:compare(-1, -2) + |> expect:equal(_, order:Gt) +} |