aboutsummaryrefslogtreecommitdiff
path: root/src/str.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.gleam')
-rw-r--r--src/str.gleam31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/str.gleam b/src/str.gleam
index b09b8dc..6ee8235 100644
--- a/src/str.gleam
+++ b/src/str.gleam
@@ -7,6 +7,9 @@ import list
pub external fn length(String) -> Int = "string" "length"
+pub enum ParseError =
+ | ParseError
+
test length {
length("ß↑e̊")
|> expect:equal(_, 3)
@@ -90,6 +93,34 @@ test from_int {
|> expect:equal(_, "123")
}
+pub external fn parse_int(String) -> Result(Int, ParseError) = "gleam__stdlib" "parse_int";
+
+test parse_int {
+ "123"
+ |> parse_int
+ |> expect:equal(_, Ok(123))
+
+ "-123"
+ |> parse_int
+ |> expect:equal(_, Ok(-123))
+
+ "0123"
+ |> parse_int
+ |> expect:equal(_, Ok(123))
+
+ ""
+ |> parse_int
+ |> expect:equal(_, Error(ParseError))
+
+ "what"
+ |> parse_int
+ |> expect:equal(_, Error(ParseError))
+
+ "1.23"
+ |> parse_int
+ |> expect:equal(_, Error(ParseError))
+}
+
pub external fn base_from_int(Int, Int) -> String = "erlang" "integer_to_binary"
test base_from_int {