Davio
03/22/2024, 8:31 AMshouldBe
? It's all too easy to accidentally compare apples and oranges since shouldBe
just accepts any type as its argumentCLOVIS
03/22/2024, 8:50 AMMervyn McCreight
03/22/2024, 9:25 AMKlitos Kyriacou
03/22/2024, 9:47 AMMervyn McCreight
03/22/2024, 9:54 AMinfix fun <A : Any> A.shouldBeEqual(expected: A): A
Looks type safe to me though. Or am I missing something now?Klitos Kyriacou
03/22/2024, 9:57 AMA
will become the closest common superclass/interface between the two arguments. And all types have at least Any
as a superclass.Davio
03/22/2024, 10:08 AM"foo".shouldBeEqual<String>("foo")
But that doesn't look really appealingCLOVIS
03/22/2024, 10:09 AMexpectThat(foo) isEqualTo "bar"
the first function "captures" the type, so the compiler is not allowed to up-cast to Any to match the second argument.Davio
03/22/2024, 10:14 AMKlitos Kyriacou
03/22/2024, 10:20 AMexpectThat
and AssertK's assertThat
because they clearly show the start of an assertion on any particular line. With Kotest, you need to scan with your eye to find a shouldXxx somewhere in the middle of a line, and only then do you know that it's an assertion.CLOVIS
03/22/2024, 10:23 AMDavio
03/22/2024, 10:23 AMEmil Kantis
03/22/2024, 11:35 AMshouldBe
when comparing definitely incompatible types. Would that be an acceptable middle ground?Emil Kantis
03/22/2024, 11:35 AMshouldBe
actually treats different types as compatible, for instance comparing an array with a listDavio
03/22/2024, 12:32 PMEmil Kantis
03/22/2024, 12:39 PMDavio
03/22/2024, 1:14 PMLeoColman
03/22/2024, 1:40 PMLeoColman
03/22/2024, 1:42 PMtoString()
is the same for both classes, but usually I catch the type unsafety pretty quicklyLeoColman
03/22/2024, 1:43 PMshouldBe
kinda sacrifices type safety for being more dynamicKlitos Kyriacou
03/22/2024, 1:52 PMDavio
03/22/2024, 1:57 PMshouldBe
is that it's basically the most concise, yet still clear, version of if(this != that) throw Something()