lsug / lsug-website

Source code of the London Scala User Group Website (yet to be hosted)
GNU General Public License v3.0
3 stars 20 forks source link

added Functor law tests for Result & Parser #91

Closed kxa14 closed 3 years ago

zainab-ali commented 3 years ago

@kxa14, this is the error I have on my end:

Expected: lsug.markup.Parser$Map@3aacf32a
Received: lsug.markup.Parser$Map@4fdfa676
> ARG_0: lsug.markup.Parser$Map@82c57b3
> ARG_1: lsug.markup.Parser$Map@5be82d43

It looks as though the test compares two instances of Map. We haven't defined equality for Map (it's not a case class, and it doesn't have an equals method), so the test probably falls back to object equality.

Looking in the cats law code, the test that fails is:

  def semigroupalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): (F[(A, (B, C))], F[((A, B), C)]) =
    (F.product(fa, F.product(fb, fc)), F.product(F.product(fa, fb), fc))

Now the problem is that the parser is lazy:

private final class Map[A, B](f: A => B, pa: => Parser[A])

Since any instance of Eq would be eager, I don't think it's possible to define an instance for it.

Unfortunately, this means that law tests for the parser would be impossible to write. Apologies for not spotting this earlier!

There are many improvements that need to be made to the parser, for example investigating using cats-parse for it instead. Now that you're familiar with the code, would you be interested in looking into it?