stdlib
stdlib copied to clipboard
string.inspect should print non-byte bit strings with Gleam syntax
Values were not equal
expected: "<<251, 3:size(3)>>"
got: "//erl(<<251,3:3>>)"
Is this the syntax for non byte aligned bit strings? I am not sure how to detect this or what to detect (too little experience with erlang/elixir binary syntax)
We'd need to swap is_binary
for is_bitstring
here, and change the logic slightly to be able to print non-byte aligned bit strings.
https://github.com/gleam-lang/stdlib/blob/a5519c33086b3467039dd6d7178da95630d1a68b/src/gleam_stdlib.erl#L384
How would I reproduce this?
You could call string.inspect
on <<251, 3:size(3)>>
Is this the correct test?
@target(erlang)
pub fn inspect_erlang_non_byte_aligned_bit_string() {
<<251, 3:size(3)>>
|> string.inspect
|> should.equal("<<251, 3:size(3)>>")
}
... because this already passes for me on gleam 0.30.5 and otp 26
Yes that looks right. How did I get that string then? 🤔
Let's add that test to the repo to be sure.
the test function above misses the test suffix. the error is as you described.
what about js?
gleam/string_test.inspect_erlang_non_byte_aligned_bit_string_test: Needs to be a byte size3
It's not supported on JS currently so can't test there.