From 8cf56dae7043c25b152e10aa02d0a7ead7454380 Mon Sep 17 00:00:00 2001 From: MainShayne233 Date: Sun, 7 Apr 2019 00:24:24 -0400 Subject: Implement parse_float --- src/str.gleam | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/str.gleam') diff --git a/src/str.gleam b/src/str.gleam index 6ee8235..bd027a1 100644 --- a/src/str.gleam +++ b/src/str.gleam @@ -121,6 +121,34 @@ test parse_int { |> expect:equal(_, Error(ParseError)) } +pub external fn parse_float(String) -> Result(Float, ParseError) = "gleam__stdlib" "parse_float"; + +test parse_float { + "1.23" + |> parse_float + |> expect:equal(_, Ok(1.23)) + + "5.0" + |> parse_float + |> expect:equal(_, Ok(5.0)) + + "0.123456789" + |> parse_float + |> expect:equal(_, Ok(0.123456789)) + + "" + |> parse_float + |> expect:equal(_, Error(ParseError)) + + "what" + |> parse_float + |> expect:equal(_, Error(ParseError)) + + "1" + |> parse_float + |> expect:equal(_, Error(ParseError)) +} + pub external fn base_from_int(Int, Int) -> String = "erlang" "integer_to_binary" test base_from_int { -- cgit v1.2.3