Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.inspect should print non-byte bit strings with Gleam syntax #485

Open
lpil opened this issue Aug 15, 2023 · 8 comments
Open

string.inspect should print non-byte bit strings with Gleam syntax #485

lpil opened this issue Aug 15, 2023 · 8 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@lpil
Copy link
Member

lpil commented Aug 15, 2023

     Values were not equal
     expected: "<<251, 3:size(3)>>"
          got: "//erl(<<251,3:3>>)"
@lpil lpil added good first issue Good for newcomers help wanted Extra attention is needed labels Aug 15, 2023
@inoas
Copy link
Contributor

inoas commented Aug 15, 2023

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)

@lpil
Copy link
Member Author

lpil commented Aug 20, 2023

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.

inspect(Binary) when is_binary(Binary) ->

@markholmes
Copy link
Member

How would I reproduce this?

@lpil
Copy link
Member Author

lpil commented Aug 30, 2023

You could call string.inspect on <<251, 3:size(3)>>

@inoas-nbw
Copy link

inoas-nbw commented Sep 4, 2023

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

@lpil
Copy link
Member Author

lpil commented Sep 4, 2023

Yes that looks right. How did I get that string then? 🤔

Let's add that test to the repo to be sure.

@inoas
Copy link
Contributor

inoas commented Sep 4, 2023

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

@lpil
Copy link
Member Author

lpil commented Sep 6, 2023

It's not supported on JS currently so can't test there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants