summaryrefslogtreecommitdiff
path: root/guide/test/JsonTest.kt
blob: 0c5ed85e800f9ec3a482845f3c22ce4d2f98917d (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// This file was automatically generated from json.md by Knit tool. Do not edit.
package example.test

import org.junit.Test
import kotlinx.knit.test.*

class JsonTest {
    @Test
    fun testExampleJson01() {
        captureOutput("ExampleJson01") { example.exampleJson01.main() }.verifyOutputLines(
            "{",
            "    \"name\": \"kotlinx.serialization\",",
            "    \"language\": \"Kotlin\"",
            "}"
        )
    }

    @Test
    fun testExampleJson02() {
        captureOutput("ExampleJson02") { example.exampleJson02.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization, status=SUPPORTED, votes=9000)"
        )
    }

    @Test
    fun testExampleJson03() {
        captureOutput("ExampleJson03") { example.exampleJson03.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization)"
        )
    }

    @Test
    fun testExampleJson04() {
        captureOutput("ExampleJson04") { example.exampleJson04.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization)",
            "Project(name=kotlinx.coroutines)"
        )
    }

    @Test
    fun testExampleJson05() {
        captureOutput("ExampleJson05") { example.exampleJson05.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization, language=Kotlin)"
        )
    }

    @Test
    fun testExampleJson06() {
        captureOutput("ExampleJson06") { example.exampleJson06.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"language\":\"Kotlin\",\"website\":null}"
        )
    }

    @Test
    fun testExampleJson07() {
        captureOutput("ExampleJson07") { example.exampleJson07.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"language\":\"Kotlin\"}",
            "Project(name=kotlinx.serialization, language=Kotlin, version=1.2.2, website=null, description=null)"
        )
    }

    @Test
    fun testExampleJson08() {
        captureOutput("ExampleJson08") { example.exampleJson08.main() }.verifyOutputLines(
            "[{\"name\":\"kotlinx.serialization\"},\"Serialization\",{\"name\":\"kotlinx.coroutines\"},\"Coroutines\"]"
        )
    }

    @Test
    fun testExampleJson09() {
        captureOutput("ExampleJson09") { example.exampleJson09.main() }.verifyOutputLines(
            "{\"value\":NaN}"
        )
    }

    @Test
    fun testExampleJson10() {
        captureOutput("ExampleJson10") { example.exampleJson10.main() }.verifyOutputLines(
            "{\"#class\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExampleJson11() {
        captureOutput("ExampleJson11") { example.exampleJson11.main() }.verifyOutputLines(
            "{\"message\":{\"message_type\":\"my.app.BaseMessage\",\"message\":\"not found\"},\"error\":{\"message_type\":\"my.app.GenericError\",\"error_code\":404}}"
        )
    }

    @Test
    fun testExampleJson12() {
        captureOutput("ExampleJson12") { example.exampleJson12.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExampleJson13() {
        captureOutput("ExampleJson13") { example.exampleJson13.main() }.verifyOutputLines(
            "CasesList(cases=[VALUE_A, VALUE_B])"
        )
    }

    @Test
    fun testExampleJson14() {
        captureOutput("ExampleJson14") { example.exampleJson14.main() }.verifyOutputLines(
            "{\"project_name\":\"kotlinx.serialization\",\"project_owner\":\"Kotlin\"}"
        )
    }

    @Test
    fun testExampleJson15() {
        captureOutput("ExampleJson15") { example.exampleJson15.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"language\":\"Kotlin\"}"
        )
    }

    @Test
    fun testExampleJson16() {
        captureOutput("ExampleJson16") { example.exampleJson16.main() }.verifyOutputLines(
            "9042"
        )
    }

    @Test
    fun testExampleJson17() {
        captureOutput("ExampleJson17") { example.exampleJson17.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"owner\":{\"name\":\"kotlin\"},\"forks\":[{\"votes\":42},{\"votes\":9000}]}"
        )
    }

    @Test
    fun testExampleJson18() {
        captureOutput("ExampleJson18") { example.exampleJson18.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization, language=Kotlin)"
        )
    }

    @Test
    fun testExampleJson19() {
        captureOutput("ExampleJson19") { example.exampleJson19.main() }.verifyOutputLines(
            "{",
            "    \"pi_double\": 3.141592653589793,",
            "    \"pi_string\": \"3.141592653589793238462643383279\"",
            "}"
        )
    }

    @Test
    fun testExampleJson20() {
        captureOutput("ExampleJson20") { example.exampleJson20.main() }.verifyOutputLines(
            "{",
            "    \"pi_literal\": 3.141592653589793238462643383279,",
            "    \"pi_double\": 3.141592653589793,",
            "    \"pi_string\": \"3.141592653589793238462643383279\"",
            "}"
        )
    }

    @Test
    fun testExampleJson21() {
        captureOutput("ExampleJson21") { example.exampleJson21.main() }.verifyOutputLines(
            "3.141592653589793238462643383279"
        )
    }

    @Test
    fun testExampleJson22() {
        captureOutput("ExampleJson22") { example.exampleJson22.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.json.internal.JsonEncodingException: Creating a literal unquoted value of 'null' is forbidden. If you want to create JSON null literal, use JsonNull object, otherwise, use JsonPrimitive"
        )
    }

    @Test
    fun testExampleJson23() {
        captureOutput("ExampleJson23") { example.exampleJson23.main() }.verifyOutputLines(
            "Project(name=kotlinx.serialization, users=[User(name=kotlin)])",
            "Project(name=kotlinx.serialization, users=[User(name=kotlin), User(name=jetbrains)])"
        )
    }

    @Test
    fun testExampleJson24() {
        captureOutput("ExampleJson24") { example.exampleJson24.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"users\":{\"name\":\"kotlin\"}}"
        )
    }

    @Test
    fun testExampleJson25() {
        captureOutput("ExampleJson25") { example.exampleJson25.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.serialization\",\"language\":\"Kotlin\"}",
            "{\"name\":\"kotlinx.serialization\"}"
        )
    }

    @Test
    fun testExampleJson26() {
        captureOutput("ExampleJson26") { example.exampleJson26.main() }.verifyOutputLines(
            "[{\"name\":\"kotlinx.serialization\",\"owner\":\"kotlin\"},{\"name\":\"example\"}]",
            "[OwnedProject(name=kotlinx.serialization, owner=kotlin), BasicProject(name=example)]"
        )
    }

    @Test
    fun testExampleJson27() {
        captureOutput("ExampleJson27") { example.exampleJson27.main() }.verifyOutputLines(
            "[{\"name\":\"kotlinx.serialization\"},{\"error\":\"Not found\"}]",
            "[Ok(data=Project(name=kotlinx.serialization)), Error(message=Not found)]"
        )
    }

    @Test
    fun testExampleJson28() {
        captureOutput("ExampleJson28") { example.exampleJson28.main() }.verifyOutputLines(
            "UnknownProject(name=example, details={\"type\":\"unknown\",\"maintainer\":\"Unknown\",\"license\":\"Apache 2.0\"})"
        )
    }
}