Skip to content

Commit

Permalink
String.inspect bitstring tests (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
inoas authored Jun 27, 2022
1 parent f3f9aa5 commit 1513046
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/gleam/string_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ if javascript {

string.inspect(#(1.0))
|> should.equal("#(1)")

// Unlike on Erlang, on JavaScript `BitString` and `String` do have a different runtime representation.
<<"abc":utf8>>
|> string.inspect()
|> should.equal("<<97, 98, 99>>")
}
}

Expand All @@ -742,13 +747,13 @@ if erlang {
"erlang" "make_ref"

pub fn target_inspect_test() {
// Erlang's internal representation does not allow a correct differentiation
// Erlang's internal representation does not allow a correct differentiation.
// |> should.equal("#(InspectTypeZero, InspectTypeZero)")
//
string.inspect(#(InspectTypeZero, InspectTypeZero))
|> should.equal("InspectTypeZero(InspectTypeZero)")

// Unlike JavaScript, Erlang correctly differentiates between 1 and 1.0
// Unlike JavaScript, Erlang correctly differentiates between `1` and `1.0`.
//
string.inspect(-1.0)
|> should.equal("-1.0")
Expand All @@ -765,20 +770,25 @@ if erlang {
string.inspect(#(1.0))
|> should.equal("#(1.0)")

// Looks like `//erl(<0.83.0>)`
// Looks like `//erl(<0.83.0>)`.
assert Ok(regular_expression) =
regex.from_string("^\\/\\/erl\\(<[0-9]+\\.[0-9]+\\.[0-9]+>\\)$")
string.inspect(create_erlang_pid())
|> regex.check(regular_expression, _)
|> should.equal(True)

// Looks like: `//erl(#Ref<0.1809744150.4035444737.100468>)`
// Looks like: `//erl(#Ref<0.1809744150.4035444737.100468>)`.
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, _)
|> should.equal(True)

// On Erlang the runtime representation for `String` and `BitString` is indistinguishable.
<<"abc":utf8>>
|> string.inspect()
|> should.equal("\"abc\"")
}
}

0 comments on commit 1513046

Please sign in to comment.