Coder Social home page Coder Social logo

Jot tests fail on JavaScript about gleam HOT 5 CLOSED

lpil avatar lpil commented on June 25, 2024
Jot tests fail on JavaScript

from gleam.

Comments (5)

lpil avatar lpil commented on June 25, 2024 1

We want them to behave the same here.

from gleam.

BradLewis avatar BradLewis commented on June 25, 2024

So I had a look into this, and it looks like this is due to the difference in behaviour between the string.split_right implementation between erlang and javascript. The test(s) in question use unicode spaces (U+00A0), and the erlang implementation will keep the space, whereas the javascript version will strip it.

The relevant code is in the following function:

// jot.gleam
fn inlines_to_html(html: String, inlines: List(Inline), refs: Refs) -> String {
  case inlines {
    [] -> html
    [inline, ..rest] -> {
      html
      |> inline_to_html(inline, refs)
      |> inlines_to_html(rest, refs)
      |> string.trim_right
    }
  }
}

If we look at the bad test, with javascript we go from

"<p><em> a "
to
"<p><em> a"

whereas in erlang we keep the space.

I'm not sure what the desired behaviour is here though in order to fix it.

Erlang REPL:

❯ erl
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Eshell V14.2.5 (press Ctrl+G to abort, type help(). for help)
1> string:trim("<p><em> a ", trailing).
"<p><em> a "

Node REPL:

❯ node
Welcome to Node.js v18.12.1.
Type ".help" for more information.
> "<p><em> a ".trimRight()
'<p><em> a'

from gleam.

lpil avatar lpil commented on June 25, 2024

Good detective work! That is a rather annoying difference. 🤔

from gleam.

BradLewis avatar BradLewis commented on June 25, 2024

Yeah definitely not ideal. I'm not sure how/if we would want to resolve this difference. Is there precedence elsewhere in the standard library where there is/was different behaviour between JS and Erlang?

from gleam.

BradLewis avatar BradLewis commented on June 25, 2024

In that case I have created a PR to rework the javascript behaviour to match the erlang behaviour.

from gleam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.