aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-12-22 14:04:59 +0000
committerLouis Pilfold <louis@lpil.uk>2024-12-22 14:04:59 +0000
commit928f8fb7f6d8c46ebb42c0f71b654afb19a1607e (patch)
tree2ad5659e9d30081ac6b2e80fba5df6e0aa7511bf /test
parentcbec8f5109415882a47e191af2a5e1a7d2b412d7 (diff)
downloadgleam_stdlib-928f8fb7f6d8c46ebb42c0f71b654afb19a1607e.tar.gz
gleam_stdlib-928f8fb7f6d8c46ebb42c0f71b654afb19a1607e.zip
v0.51.0v0.51.0
Diffstat (limited to 'test')
-rw-r--r--test/gleam/dynamic/decode_test.gleam29
-rw-r--r--test/gleam/string_test.gleam10
2 files changed, 30 insertions, 9 deletions
diff --git a/test/gleam/dynamic/decode_test.gleam b/test/gleam/dynamic/decode_test.gleam
index b176c70..a97f597 100644
--- a/test/gleam/dynamic/decode_test.gleam
+++ b/test/gleam/dynamic/decode_test.gleam
@@ -1,9 +1,10 @@
import gleam/dict
-import gleam/dynamic.{type Dynamic, DecodeError}
-import gleam/dynamic/decode
+import gleam/dynamic.{type Dynamic}
+import gleam/dynamic/decode.{DecodeError}
import gleam/float
import gleam/int
import gleam/option
+import gleam/result
import gleam/should
pub type User {
@@ -768,29 +769,45 @@ pub fn documentation_variants_example_test() {
}
pub fn new_primitive_decoder_string_ok_test() {
+ let decoder =
+ decode.new_primitive_decoder("String", fn(x) {
+ dynamic.string(x) |> result.replace_error("")
+ })
dynamic.from("Hello!")
- |> decode.run(decode.new_primitive_decoder(dynamic.string, ""))
+ |> decode.run(decoder)
|> should.be_ok
|> should.equal("Hello!")
}
pub fn new_primitive_decoder_string_error_test() {
+ let decoder =
+ decode.new_primitive_decoder("String", fn(x) {
+ dynamic.string(x) |> result.replace_error("")
+ })
dynamic.from(123)
- |> decode.run(decode.new_primitive_decoder(dynamic.string, ""))
+ |> decode.run(decoder)
|> should.be_error
|> should.equal([DecodeError("String", "Int", [])])
}
pub fn new_primitive_decoder_float_ok_test() {
+ let decoder =
+ decode.new_primitive_decoder("Float", fn(x) {
+ dynamic.float(x) |> result.replace_error(0.0)
+ })
dynamic.from(12.4)
- |> decode.run(decode.new_primitive_decoder(dynamic.float, 0.0))
+ |> decode.run(decoder)
|> should.be_ok
|> should.equal(12.4)
}
pub fn new_primitive_decoder_float_error_test() {
+ let decoder =
+ decode.new_primitive_decoder("Float", fn(x) {
+ dynamic.float(x) |> result.replace_error(0.0)
+ })
dynamic.from("blah")
- |> decode.run(decode.new_primitive_decoder(dynamic.float, 0.0))
+ |> decode.run(decoder)
|> should.be_error
|> should.equal([DecodeError("Float", "String", [])])
}
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam
index ffd2f9b..4eddb9c 100644
--- a/test/gleam/string_test.gleam
+++ b/test/gleam/string_test.gleam
@@ -1,12 +1,16 @@
import gleam/dict
-import gleam/int
-import gleam/list
import gleam/option.{None, Some}
import gleam/order
-import gleam/result
import gleam/should
import gleam/string
+@target(erlang)
+import gleam/int
+@target(erlang)
+import gleam/list
+@target(erlang)
+import gleam/result
+
pub fn length_test() {
string.length("ß↑e̊")
|> should.equal(3)