aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2024-11-18 23:17:17 +0100
committerLouis Pilfold <louis@lpil.uk>2024-11-19 14:20:01 +0000
commit62ee45e624408241e38b629d46cb4950f1f09047 (patch)
tree83a8c894edc4f3739b18bb14d364594fb0876d17
parent168397ec512edf2efbb44f0d01ffb914c6398f5c (diff)
downloadgleam_stdlib-62ee45e624408241e38b629d46cb4950f1f09047.tar.gz
gleam_stdlib-62ee45e624408241e38b629d46cb4950f1f09047.zip
regex begone
-rw-r--r--test/gleam/string_test.gleam63
1 files changed, 45 insertions, 18 deletions
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam
index c49f543..b98a4e1 100644
--- a/test/gleam/string_test.gleam
+++ b/test/gleam/string_test.gleam
@@ -1,6 +1,9 @@
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
@@ -595,11 +598,7 @@ pub fn to_graphemes_test() {
"Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞"
|> string.to_graphemes
- |> should.equal([
- "Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍", "A̴̵̜̰͔ͫ͗͢", "L̠ͨͧͩ͘",
- "G̴̻͈͍͔̹̑͗̎̅͛́", "Ǫ̵̹̻̝̳͂̌̌͘",
- "!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞",
- ])
+ |> should.equal(["Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍", "A̴̵̜̰͔ͫ͗͢", "L̠ͨͧͩ͘", "G̴̻͈͍͔̹̑͗̎̅͛́", "Ǫ̵̹̻̝̳͂̌̌͘", "!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞"])
}
pub fn to_utf_codepoints_test() {
@@ -1040,9 +1039,7 @@ pub fn inspect_test() {
|> should.equal("[#(1, 2, 3), #(1, 2, 3)]")
string.inspect(#([1, 2, 3], "🌈", "🏳️‍🌈", #(1, "1", True)))
- |> should.equal(
- "#([1, 2, 3], \"🌈\", \"🏳️‍🌈\", #(1, \"1\", True))",
- )
+ |> should.equal("#([1, 2, 3], \"🌈\", \"🏳️‍🌈\", #(1, \"1\", True))")
string.inspect(Nil)
|> should.equal("Nil")
@@ -1157,8 +1154,6 @@ pub fn target_inspect_test() {
@target(erlang)
import gleam/dynamic.{type Dynamic}
-@target(erlang)
-import gleam/regex
// Test inspect on Erlang atoms valid and invalid in Gleam
@@ -1197,19 +1192,13 @@ pub fn target_inspect_test() {
|> should.equal("#(1.0)")
// Looks like `//erl(<0.83.0>)`.
- let assert Ok(regular_expression) =
- regex.from_string("^\\/\\/erl\\(<[0-9]+\\.[0-9]+\\.[0-9]+>\\)$")
string.inspect(create_erlang_pid())
- |> regex.check(regular_expression, _)
+ |> looks_like_pid
|> should.be_true
// Looks like: `//erl(#Ref<0.1809744150.4035444737.100468>)`.
- let assert Ok(regular_expression) =
- regex.from_string(
- "^\\/\\/erl\\(#Ref<[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+>\\)$",
- )
string.inspect(create_erlang_reference())
- |> regex.check(regular_expression, _)
+ |> looks_like_ref
|> should.be_true
// On Erlang the representation between `String` and `BitArray` is
@@ -1220,6 +1209,44 @@ pub fn target_inspect_test() {
}
@target(erlang)
+fn looks_like_pid(string: String) -> Bool {
+ case string {
+ "//erl(<" <> string ->
+ case string.ends_with(string, ">)") {
+ False -> False
+ True ->
+ case string.drop_end(string, 2) |> string.split(on: ".") {
+ [_, _, _] as numbers ->
+ list.try_map(numbers, int.parse)
+ |> result.is_ok
+
+ _ -> False
+ }
+ }
+ _ -> False
+ }
+}
+
+@target(erlang)
+fn looks_like_ref(string: String) -> Bool {
+ case string {
+ "//erl(#Ref<" <> string ->
+ case string.ends_with(string, ">)") {
+ False -> False
+ True ->
+ case string.drop_end(string, 2) |> string.split(on: ".") {
+ [_, _, _, _] as numbers ->
+ list.try_map(numbers, int.parse)
+ |> result.is_ok
+
+ _ -> False
+ }
+ }
+ _ -> False
+ }
+}
+
+@target(erlang)
pub fn improper_list_inspect_test() {
let list = improper_list_append(1, 2, 3)
let assert "//erl([1, 2 | 3])" = string.inspect(list)