#`pretty_diff` - ⚖ pretty printing the difference between Gleam values

1 messages · Page 1 of 1 (latest)

quartz estuary
#

I've published a package that can be used to pretty print a rich diff between two Gleam values
For example:

let jak_likes = ["FP", "Gleam", "programming"]
let jak_langs = dict.from_list([#("Italian", Native), #("English", C2), #("Spanish", A1)])
let jak = User("Giacomo", 25, jak_likes, jak_langs)

let tom_likes = ["OOP", "Java", "programming", "playing the piano"]
let tom_langs = dict.from_list([#("Italian", Native), #("English", C1), #("Japanese", C1)])
let other = User("Tommaso", 25, tom_likes, tom_langs)

pretty_diff.from(one, and: other)
``` 
Will result in this pretty printed diff!

https://github.com/giacomocavalieri/pretty_diff/tree/v1.0.0
GitHub

⚖️ Pretty printing the difference between Gleam values - GitHub - giacomocavalieri/pretty_diff at v1.0.0

#

@umbral quail would you accept a PR to use this in startest? 🥺

pulsar flax
#

Awesome!!

umbral quail
quartz estuary
#

Lmk if there's anything you wish it did differently

pulsar flax
#

It looks a lot like the clojure deep-diff2 output

quartz estuary
#

It was very much inspired by that!

pulsar flax
#

i figured ...i will have to try this later today for the quickcheck library

#

though it would be nice if it could be included in gleeunit somehow

umbral quail
#

I don't think Gleeunit is getting many updates these days 😅

pulsar flax
quartz estuary
#

@whole salmon would you accept a PR to add this to gleeunit?

pulsar flax
#

im interested in startest at least

#

especially if you put the diffing in

lament wadi
#

i'm curious how this compares to gap: https://hexdocs.pm/gap/

#

pretty_diff seems more generic in that it does all the things?

quartz estuary
#

Gap only works with lists and strings, pretty_diff works with any gleam value

lament wadi
#

okay cool that's what i figured

#

i dig it

quartz estuary
#

gap is way more useful in general because you have access to the Diff data structure

#

While I intentionally only expose the from function that returns a String and not the internal representation of diffs

lament wadi
#

interesting tradeoff

broken silo
#

are you using this as part of birdie?

quartz estuary
lament wadi
quartz estuary
lament wadi
#

because yes if you make crimes possible, i will commit them

broken silo
#

but could birdie also take a gleam value instead of a string and then use pretty_diff? different function simply?

#

if that makes sense at all

quartz estuary
#

Well, that isn't possible because the comparison is made with the textual content of the snapshot, not another in-memory value

broken silo
#

oh that makes total sense!

quartz estuary
#

And even if that were possible I wouldn't want birdie to ever take something that is not a string as input, the less magic hidden inside birdie the better!

#

I think there's a lot of advantages in birdie only allowing the content of a snapshot to be a plain String

broken silo
#

it is fine, I love pprint+birdie

lament wadi
#

i agree, though i'm sure someone is gonna come along and just string.inspect piped to birdie

broken silo
#

btw would you consider accepting a PR that auto sets the snapshot name to the test function name it is run from (prefixed by the module name/path)?

quartz estuary
broken silo
quartz estuary
broken silo
quartz estuary
#

Ah so you mean another snap function

broken silo
#

yes (as we do not have optional args :D)

lament wadi
broken silo
#

@quartz estuary IN CASE you come to the conclusion that it is worth it (in addition and backwards compatible), let me know and I can try to do the plumbing/chore.

broken silo
whole salmon
#

@quartz estuary if we add this to gleeunit and publish it we'll break the tests for glam, classify, and pretty_diff

#

Dep loop