-
Notifications
You must be signed in to change notification settings - Fork 437
/
LensTests.kt
executable file
·66 lines (60 loc) · 1.61 KB
/
LensTests.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package arrow.optics.plugin
import arrow.optics.plugin.internals.typeParametersErrorMessage
import org.junit.jupiter.api.Test
class LensTests {
@Test
fun `Lenses will be generated for data class`() {
"""
|$imports
|@optics
|data class LensData(
| val field1: String
|) { companion object }
|
|val i: Lens<LensData, String> = LensData.field1
|val r = i != null
""".evals("r" to true)
}
@Test
fun `Lenses will be generated for data class with secondary constructors`() {
"""
|$imports
|@optics
|data class LensesSecondaryConstructor(val fieldNumber: Int, val fieldString: String) {
| constructor(number: Int) : this(number, number.toString())
| companion object
|}
|
|val i: Lens<LensesSecondaryConstructor, String> = LensesSecondaryConstructor.fieldString
|val r = i != null
""".evals("r" to true)
}
@Test
fun `Lenses which mentions imported elements`() {
"""
|$imports
|import kotlin.time.Duration
|
|@optics
|data class OpticsTest(val time: Duration) {
| companion object
|}
|
|val i: Lens<OpticsTest, Duration> = OpticsTest.time
|val r = i != null
""".evals("r" to true)
}
@Test
fun `Lenses which mentions type arguments`() {
"""
|$imports
|@optics
|data class OpticsTest<A>(val field: A) {
| companion object
|}
|
|val i: Lens<OpticsTest, Int> = OpticsTest<Int>.time
|val r = i != null
""".failsWith { it.contains("OpticsTest".typeParametersErrorMessage) }
}
}