@@ -3,9 +3,15 @@ package com.apurebase.arkenv
33import com.apurebase.arkenv.test.expectThat
44import com.apurebase.arkenv.test.parse
55import com.apurebase.arkenv.util.argument
6+ import com.apurebase.arkenv.util.parse
67import org.junit.jupiter.api.Test
78import org.junit.jupiter.api.TestInstance
9+ import strikt.api.expectThat
810import strikt.assertions.isEqualTo
11+ import java.io.File
12+ import java.net.URI
13+ import java.net.URL
14+ import java.nio.file.Path
915
1016@TestInstance(TestInstance .Lifecycle .PER_CLASS )
1117internal class MappingTests {
@@ -17,8 +23,8 @@ internal class MappingTests {
1723 val list: List <String > by argument()
1824 val collection: Collection <String > by argument()
1925 }.parse(" LIST" , input, " COLLECTION" , input).expectThat {
20- get { list }. isEqualTo( output)
21- get { collection }. isEqualTo( output)
26+ get { list } isEqualTo output
27+ get { collection } isEqualTo output
2228 }
2329 }
2430
@@ -94,6 +100,83 @@ internal class MappingTests {
94100 }
95101 }
96102
103+ @Test fun `Path should map` () {
104+ val expectedPath = " C:\\ "
105+ val configuration = object {
106+ val path: Path by argument()
107+ }
108+
109+ Arkenv .parse(configuration, arrayOf(" --path" , expectedPath))
110+
111+ expectThat(configuration).get { path.toString() } isEqualTo expectedPath
112+ }
113+
114+ @Test fun `File should map` () {
115+ val expectedPath = " C:\\ "
116+ val configuration = object {
117+ val file: File by argument()
118+ }
119+
120+ Arkenv .parse(configuration, arrayOf(" --file" , expectedPath))
121+
122+ expectThat(configuration).get { file.toString() } isEqualTo expectedPath
123+ }
124+
125+ @Test fun url () {
126+ val expectedUrl = " https://arkenv.io/features/mapping/"
127+ val configuration = object {
128+ val url: URL by argument()
129+ }
130+
131+ Arkenv .parse(configuration, arrayOf(" --url" , expectedUrl))
132+
133+ expectThat(configuration).get { url.toString() } isEqualTo expectedUrl
134+ }
135+
136+ @Test fun uri () {
137+ val expectedUri = " arkenv.io/features/mapping"
138+ val configuration = object {
139+ val uri: URI by argument()
140+ }
141+
142+ Arkenv .parse(configuration, arrayOf(" --uri" , expectedUri))
143+
144+ expectThat(configuration).get { uri.toString() } isEqualTo expectedUri
145+ }
146+
147+ @Test fun intRange () {
148+ val expectedRange = - 5 .. 101
149+ val configuration = object {
150+ val range: IntRange by argument()
151+ }
152+
153+ Arkenv .parse(configuration, arrayOf(" --range" , " -5..101" ))
154+
155+ expectThat(configuration).get { range } isEqualTo expectedRange
156+ }
157+
158+ @Test fun longRange () {
159+ val expectedRange = - 5L .. 101
160+ val configuration = object {
161+ val range: LongRange by argument()
162+ }
163+
164+ Arkenv .parse(configuration, arrayOf(" --range" , " -5..101" ))
165+
166+ expectThat(configuration).get { range } isEqualTo expectedRange
167+ }
168+
169+ @Test fun charRange () {
170+ val expectedRange = CharRange (' z' , ' a' )
171+ val configuration = object {
172+ val range: CharRange by argument()
173+ }
174+
175+ Arkenv .parse(configuration, arrayOf(" --range" , " z..a" ))
176+
177+ expectThat(configuration).get { range } isEqualTo expectedRange
178+ }
179+
97180 private val floatingPointInput = " 1.1,29.92,-387.9999"
98181 private val floatingPointOutput = listOf (1.1 , 29.92 , - 387.9999 )
99182 private val numericInput = " 1,-29,387"
0 commit comments