-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestModel.test.scala
More file actions
217 lines (191 loc) · 5.41 KB
/
TestModel.test.scala
File metadata and controls
217 lines (191 loc) · 5.41 KB
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
package org.encalmo.writer.xml
import org.encalmo.writer.xml.annotation.*
import java.time.LocalDate
case class Person(
@xmlAttribute @xmlTag("ID") id: String,
name: Name,
age: Int,
stature: Double,
email: Option[String],
address: Option[Address],
addresses: Option[Map[String, Address]],
isStudent: Boolean,
tags: List[tag],
citizenship: Citizenship,
immigrationStatus: Option[ImmigrationStatus],
@xmlTag("marital") maritalStatus: Array[
MaritalStatus
],
@xmlItemTag("Hobby") hobbies: List[Hobby],
hobby: Hobby,
passportNumber: Option[PassportNumber],
driverLicense: Option[DriverLicense],
disabilities: List[Disability],
disability: Disability,
benefits1: List[Benefit] | false,
benefits2: List[Benefit] | false,
@xmlItemTag("skill") skills: Skills,
@xmlItemTag("item") wallet: (Int, String, LocalDate),
assets: (Cars, Boats, Planes),
@xmlItemTag("book") books: List[(author: String, title: String)],
bookAtDesk: (author: String, title: String),
hand1: Either[String, String],
hand2: Either[String, String],
status: Status,
active: YesNo
)
enum Citizenship {
@xmlValue("United Kingdom") case UK
case other
}
case class tag(
@xmlAttribute name: String,
@xmlContent value: String
)
case class Address(
street: String,
city: String,
@xmlTag("zipcode") postcode: String
)
trait ImmigrationStatus {
def status: String
def validUntil: LocalDate
}
enum MaritalStatus {
case Single
case CivilPartnership(partnerName: String, from: LocalDate)
case Married(partnerName: String, from: LocalDate)
case Divorced(from: LocalDate)
case Widowed(from: LocalDate)
}
enum Hobby {
case Reading
case Swimming
case Cycling
case Cooking
@xmlContent @xmlValueSelector("name") case Other(name: String)
}
object ImmigrationStatus {
given XmlWriter[ImmigrationStatus] =
new XmlWriter[ImmigrationStatus] {
def write(name: Option[String], value: ImmigrationStatus, createTag: Boolean)(using
builder: XmlOutputBuilder
): Unit = {
builder.appendElementStart("current-immigration-status")
builder.appendText(value.status)
builder.appendElementEnd("current-immigration-status")
builder.appendElementStart("immigration-status-valid-until")
builder.appendText(value.validUntil.toString)
builder.appendElementEnd("immigration-status-valid-until")
}
}
}
opaque type PassportNumber = String
object PassportNumber {
def apply(value: String): PassportNumber = value
}
case class SensitiveData[T](value: T)
opaque type Disability = SensitiveData[String]
object Disability {
def apply(value: String): Disability = SensitiveData(value)
given XmlWriter[Disability] =
new XmlWriter[Disability] {
def write(name: Option[String], value: Disability, createTag: Boolean)(using
builder: XmlOutputBuilder
): Unit = {
if createTag then builder.appendElementStart(name.getOrElse("Disability"))
builder.appendText(value.value)
if createTag then builder.appendElementEnd(name.getOrElse("Disability"))
}
}
}
opaque type DriverLicense <: Document = Document
object DriverLicense {
def apply(number: String, expiryDate: LocalDate): DriverLicense = Document(number, expiryDate)
}
case class Document(
@xmlContent number: String,
@xmlAttribute expiryDate: LocalDate
)
opaque type Skills <: Set[String] = Set[String]
object Skills {
def apply(values: String*): Skills = values.toSet
}
type Name = String
enum TestEnum {
case Foo
case Bar(name: String)
}
@xmlAdditionalTag("Benefit")
@xmlEnumCaseValuePlain
enum Benefit {
case ChildBenefit
case UniversalCredit
case JobSeekersAllowance
case EmploymentSupportAllowance
case HousingBenefit
case PensionCredit
case Other(name: String)
}
@xmlAdditionalTag("Cars")
@xmlEnumCaseValuePlain
enum Cars {
case Ford
case Toyota
case Honda
case Nissan
case Other(name: String)
}
@xmlItemTag("boat") opaque type Boats <: Set[String] = Set[String]
object Boats {
def apply(values: String*): Boats = values.toSet
}
@xmlAdditionalTag("Planes")
sealed trait Planes
case class Boeing(model: String) extends Planes
case class Airbus(model: String) extends Planes
class Row extends Selectable {
type Fields <: Any
}
class FactsRow extends Row {
type Fields = (name: String, age: Int, email: String)
transparent inline def selectDynamic(name: String): Any =
name match {
case "name" => "John Doe"
case "age" => 30
case "email" => "john.doe@example.com"
case _ => throw new NoSuchElementException(s"Field $name not found")
}
}
case class ExampleLargeCaseClass(
field1: String,
field2: Int,
field3: Double,
field4: Boolean,
field5: Option[String],
field6: Long,
field7: Float,
field8: Char,
field9: Short,
field10: Byte,
field11: BigDecimal,
field12: List[Int],
field13: Map[String, Int],
field14: Set[Double],
field15: Vector[Boolean],
field16: Array[Char],
field17: Seq[String],
field18: Either[String, Int],
field19: Option[Double],
field20: (String, Int),
field21: List[String],
field22: Option[List[Double]],
field23: Map[Int, String],
field24: Set[String],
field25: Option[Boolean],
field26: BigInt,
field27: Option[BigDecimal],
field28: Array[Byte],
field29: Option[Char],
field30: String
) derives XmlWriter