@@ -25,21 +25,83 @@ import org.w3.xml.xmschematestsuite.*
25
25
26
26
@Serializable
27
27
data class OTSSuite (val testSetOverrides : List <OTSTestSet >) {
28
+
29
+ constructor (compact: CompactOverride ) : this (toTestSets(compact))
30
+
28
31
fun applyTo (original : TSTestSet ): TSTestSet {
29
32
return testSetOverrides
30
33
.firstOrNull { it.name == original.name }
31
34
?.applyTo(original)
32
35
? : return original
33
36
}
37
+
38
+ fun findIgnoredPaths (): List <TestPath > {
39
+ return testSetOverrides.flatMap { it.findIgnoredPaths() }
40
+ }
41
+
42
+ fun findOverrides (): List <ExpectedOverride > {
43
+ return testSetOverrides.flatMap { it.findOverrides() }
44
+ }
45
+
46
+ companion object {
47
+ private fun toTestSets (compact : CompactOverride ): List <OTSTestSet > {
48
+ val ignoreMap = compact.ignores.groupBy { it.testSet }
49
+ val overrideMap = compact.overrides.groupBy { it.path.testSet }
50
+
51
+ val setNames = (ignoreMap.keys + overrideMap.keys).sorted()
52
+
53
+ return setNames.map { tsName ->
54
+ val ignores = ignoreMap[tsName]? : emptyList()
55
+ val isIgnored = ignores.any { it.group== null }
56
+ val overrides = overrideMap[tsName] ? : emptyList()
57
+
58
+ val newOverrides = toGroups(overrides, ignores)
59
+
60
+ OTSTestSet (tsName, newOverrides, isIgnored)
61
+ }
62
+ }
63
+
64
+ private fun toGroups (overrides : List <ExpectedOverride >, ignores : List <TestPath >): List <OTSTestGroup > {
65
+ val ignoreMap = ignores.filter { it.group != null }.groupBy { it.group!! }
66
+ val overrideMap = overrides.filter { it.path.group != null }.groupBy { it.path.group!! }
67
+ val groupNames = (ignoreMap.keys + overrideMap.keys).sorted()
68
+
69
+ return groupNames.map { groupName ->
70
+ val grOverrides = overrideMap[groupName] ? : emptyList()
71
+ val grIgnores = ignoreMap[groupName] ? : emptyList()
72
+ val isIgnored = grIgnores.any { it.test == null }
73
+
74
+ val schemaTest = grOverrides.singleOrNull { it.path.test!= null && ! it.isInstance }?.let {
75
+ val testName = it.path.test!!
76
+ OTSSchemaTest (testName, expecteds = it.expecteds, isIgnored = grIgnores.any { it.test == testName })
77
+ }
78
+
79
+ val instanceTests = grOverrides.filter { it.path.test!= null && it.isInstance }.map {
80
+ val testName = it.path.test!!
81
+ OTSInstanceTest (testName, expecteds = it.expecteds, isIgnored = grIgnores.any { it.test == testName })
82
+ }
83
+
84
+ OTSTestGroup (groupName, schemaTest, instanceTests, isIgnored)
85
+ }
86
+
87
+ return TODO ()
88
+ }
89
+ }
34
90
}
35
91
36
92
@Serializable
37
- data class OTSTestSet (val name : String , val groups : List <OTSTestGroup > = emptyList()) {
93
+ data class OTSTestSet (val name : String , val groups : List <OTSTestGroup > = emptyList(), val isIgnored : Boolean = false ) {
38
94
fun applyTo (original : TSTestSet ): TSTestSet {
39
- val associations = groups.associateBy { it.name }
40
- val newGroups = original.testGroups.map {
41
- associations.get(it.name)?.applyTo(it) ? : it
95
+ val newGroups: List <TSTestGroup > = when {
96
+ isIgnored -> emptyList()
97
+ else -> {
98
+ val associations = groups.associateBy { it.name }
99
+ original.testGroups.map {
100
+ associations.get(it.name)?.applyTo(it) ? : it
101
+ }
102
+ }
42
103
}
104
+
43
105
return TSTestSet (
44
106
original.contributor,
45
107
original.name,
@@ -48,13 +110,25 @@ data class OTSTestSet(val name: String, val groups: List<OTSTestGroup> = emptyLi
48
110
newGroups
49
111
)
50
112
}
113
+
114
+ fun findIgnoredPaths (): Sequence <TestPath > {
115
+ return when {
116
+ isIgnored -> sequenceOf(TestPath (name))
117
+ else -> groups.asSequence().flatMap { it.findIgnoredPaths(TestPath (name)) }
118
+ }
119
+ }
120
+
121
+ fun findOverrides (): Sequence <ExpectedOverride > {
122
+ return groups.asSequence().flatMap { it.findOverrides(TestPath (name)) }
123
+ }
51
124
}
52
125
53
126
@Serializable
54
127
data class OTSTestGroup (
55
128
val name : String ,
56
129
val schemaTest : OTSSchemaTest ? = null ,
57
- val instanceTests : List <OTSInstanceTest > = emptyList()
130
+ val instanceTests : List <OTSInstanceTest > = emptyList(),
131
+ val isIgnored : Boolean = false
58
132
) {
59
133
fun applyTo (original : TSTestGroup ): TSTestGroup {
60
134
val newSchemaTest = original.schemaTest?.let { ot -> schemaTest?.applyTo(ot) ? : ot }
@@ -66,6 +140,29 @@ data class OTSTestGroup(
66
140
instanceTests = newInstanceTests,
67
141
)
68
142
}
143
+
144
+ fun findIgnoredPaths (base : TestPath ): Sequence <TestPath > {
145
+ val newBase = base.copy(group = name)
146
+ return when {
147
+ isIgnored -> sequenceOf(newBase)
148
+ else -> sequence {
149
+ if (schemaTest != null && schemaTest.isIgnored) yield (newBase.copy(test= schemaTest.name, isSchema = true ))
150
+ yieldAll(instanceTests.asSequence().filter { it.isIgnored }.map { newBase.copy(test= it.name, isSchema = false )})
151
+ }
152
+ }
153
+ }
154
+
155
+ fun findOverrides (base : TestPath ): Sequence <ExpectedOverride > {
156
+ val newBase = base.copy(group= name)
157
+ return sequence {
158
+ if (schemaTest != null ) yield (
159
+ ExpectedOverride (newBase.copy(test = schemaTest.name, isSchema = true ), schemaTest.expecteds)
160
+ )
161
+ yieldAll(instanceTests.asSequence().map {
162
+ ExpectedOverride (newBase.copy(test= it.name, isSchema = false ), it.expecteds)
163
+ })
164
+ }
165
+ }
69
166
}
70
167
71
168
private fun mergeExpecteds (originalExpected : List <TSExpected >, overridden : List <TSExpected >): List <TSExpected > {
@@ -104,7 +201,13 @@ private fun mergeExpecteds(originalExpected: List<TSExpected>, overridden: List<
104
201
105
202
106
203
@Serializable
107
- data class OTSSchemaTest (val name : String , val version : String? = null , val expecteds : List <TSExpected > = emptyList()) {
204
+ data class OTSSchemaTest (
205
+ val name : String ,
206
+ val version : String? = null ,
207
+ val expecteds : List <TSExpected > = emptyList(),
208
+ val isIgnored : Boolean = false ,
209
+ ) {
210
+
108
211
fun applyTo (original : TSSchemaTest ): TSSchemaTest {
109
212
val newExpected: List <TSExpected > = mergeExpecteds(original.expected, expecteds)
110
213
return original.copy(version = version ? : original.version, expected = newExpected)
@@ -113,7 +216,12 @@ data class OTSSchemaTest(val name: String, val version: String? = null, val expe
113
216
}
114
217
115
218
@Serializable
116
- data class OTSInstanceTest (val name : String , val version : String? = null , val expecteds : List <TSExpected > = emptyList()) {
219
+ data class OTSInstanceTest (
220
+ val name : String ,
221
+ val version : String? = null ,
222
+ val expecteds : List <TSExpected > = emptyList(),
223
+ val isIgnored : Boolean = false ,
224
+ ) {
117
225
fun applyTo (original : TSInstanceTest ): TSInstanceTest {
118
226
val newExpected: List <TSExpected > = mergeExpecteds(original.expected, expecteds)
119
227
return original.copy(version = version ? : original.version, expected = newExpected)
0 commit comments