Skip to content

Commit 63ec8d0

Browse files
committed
map tests #2 #3
1 parent a651496 commit 63ec8d0

File tree

5 files changed

+137
-4
lines changed

5 files changed

+137
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file was automatically generated from maps.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package example.exampleMapComplex01
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Colour(
10+
val r: UByte,
11+
val g: UByte,
12+
val b: UByte,
13+
val a: UByte,
14+
)
15+
16+
@Serializable
17+
data class CanvasProperties(
18+
val colourNames: Map<Colour, String>
19+
)
20+
21+
fun main() {
22+
val tsGenerator = KxsTsGenerator()
23+
println(tsGenerator.generate(CanvasProperties.serializer().descriptor))
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file was automatically generated from maps.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package example.exampleMapPrimitive02
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Config(
10+
val properties: Map<String?, String?>
11+
)
12+
13+
fun main() {
14+
val tsGenerator = KxsTsGenerator()
15+
println(tsGenerator.generate(Config.serializer().descriptor))
16+
}

docs/knit/test/MapsTests.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,35 @@ class MapsTests {
1515
"}"
1616
)
1717
}
18+
19+
@Test
20+
fun testExampleMapPrimitive02() {
21+
captureOutput("ExampleMapPrimitive02") {
22+
example.exampleMapPrimitive02.main()
23+
}.verifyOutputLines(
24+
"interface Config {",
25+
" properties: { [key: string | null]: string | null };",
26+
"}"
27+
)
28+
}
29+
30+
@Test
31+
fun testExampleMapComplex01() {
32+
captureOutput("ExampleMapComplex01") {
33+
example.exampleMapComplex01.main()
34+
}.verifyOutputLines(
35+
"type UByte = number;",
36+
"",
37+
"interface Colour {",
38+
" r: UByte;",
39+
" g: UByte;",
40+
" b: UByte;",
41+
" a: UByte;",
42+
"}",
43+
"",
44+
"interface CanvasProperties {",
45+
" colourNames: { [key: Colour]: string };",
46+
"}"
47+
)
48+
}
1849
}

docs/maps.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import kotlinx.serialization.*
55
import dev.adamko.kxstsgen.*
66
-->
77

8-
### Primitive lists
9-
8+
### Primitive maps
109

1110
```kotlin
1211
@Serializable
@@ -29,3 +28,68 @@ interface Config {
2928
```
3029

3130
<!--- TEST -->
31+
32+
### Nullable keys and values
33+
34+
```kotlin
35+
@Serializable
36+
data class Config(
37+
val properties: Map<String?, String?>
38+
)
39+
40+
fun main() {
41+
val tsGenerator = KxsTsGenerator()
42+
println(tsGenerator.generate(Config.serializer().descriptor))
43+
}
44+
```
45+
46+
> You can get the full code [here](./knit/example/example-map-primitive-02.kt).
47+
48+
```typescript
49+
interface Config {
50+
properties: { [key: string | null]: string | null };
51+
}
52+
```
53+
54+
<!--- TEST -->
55+
56+
### Maps with complex keys
57+
58+
```kotlin
59+
@Serializable
60+
data class Colour(
61+
val r: UByte,
62+
val g: UByte,
63+
val b: UByte,
64+
val a: UByte,
65+
)
66+
67+
@Serializable
68+
data class CanvasProperties(
69+
val colourNames: Map<Colour, String>
70+
)
71+
72+
fun main() {
73+
val tsGenerator = KxsTsGenerator()
74+
println(tsGenerator.generate(CanvasProperties.serializer().descriptor))
75+
}
76+
```
77+
78+
> You can get the full code [here](./knit/example/example-map-complex-01.kt).
79+
80+
```typescript
81+
type UByte = number;
82+
83+
interface Colour {
84+
r: UByte;
85+
g: UByte;
86+
b: UByte;
87+
a: UByte;
88+
}
89+
90+
interface CanvasProperties {
91+
colourNames: { [key: Colour]: string };
92+
}
93+
```
94+
95+
<!--- TEST -->

modules/kxs-ts-gen-core/src/commonMain/kotlin/dev.adamko.kxstsgen/KxsTsSourceCodeGenerator.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ class KxsTsSourceCodeGenerator(
103103
}
104104
}
105105

106-
// private fun generateTypeReference(typeRefs: Collection<TsTyping>) =
107-
// generateTypeReference(*typeRefs.toTypedArray())
108106

109107
/**
110108
* A type-reference, be it for the field of an interface, a type alias, or a generic type

0 commit comments

Comments
 (0)