Skip to content

Commit e35b5a6

Browse files
committed
move SpectTestsMap and SectionsMap to sealed class SpecMap
1 parent e217400 commit e35b5a6

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.jetbrains.kotlin.spec.entity
2+
3+
import kotlinx.serialization.json.JsonElement
4+
5+
sealed class SpecMap() {
6+
class Tests(val json: JsonElement)
7+
class Sections(val json: JsonElement)
8+
}

web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/TestMap.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/GithubTestsLoader.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import js.externals.jquery.JQueryXHR
55
import js.externals.jquery.`$`
66
import kotlinx.serialization.json.Json
77
import kotlinx.serialization.json.JsonConfiguration
8-
import org.jetbrains.kotlin.spec.entity.SectionsMap
8+
import org.jetbrains.kotlin.spec.entity.SpecMap
99
import org.jetbrains.kotlin.spec.entity.SpecSection
10-
import org.jetbrains.kotlin.spec.entity.TestMap
1110
import org.jetbrains.kotlin.spec.entity.test.SpecTest
1211
import org.jetbrains.kotlin.spec.entity.test.TestPlace
1312
import org.jetbrains.kotlin.spec.entity.test.parameters.TestInfo
@@ -63,9 +62,9 @@ interface GithubTestsLoader {
6362
mainSectionName: String,
6463
path: String,
6564
testType: TestOrigin,
66-
sectionsMapByTestArea: Map<TestArea, SectionsMap>
67-
): Promise<Map<TestArea, TestMap>> = Promise { resolve, _ ->
68-
val resultMap = mutableMapOf<TestArea, TestMap>()
65+
sectionsMapByTestArea: Map<TestArea, SpecMap.Sections>
66+
): Promise<Map<TestArea, SpecMap.Tests>> = Promise { resolve, _ ->
67+
val resultMap = mutableMapOf<TestArea, SpecMap.Tests>()
6968
val loadableTestAreas: MutableSet<TestArea> = mutableSetOf()
7069
testAreasToLoad.forEach {
7170
if (sectionsMapByTestArea.isTestsMapExists(testArea = it, requestedMainSection = mainSectionName, requestedSubsectionPath = path)) {
@@ -76,14 +75,14 @@ interface GithubTestsLoader {
7675
*(loadableTestAreas.associateWith {
7776
`$`.ajax(getFullTestMapPath(testType, it, mainSectionName, path), jQueryAjaxSettings { })
7877
.then({ response: Any?, _: Any ->
79-
resultMap[it] = TestMap(parseJsonText(response.toString()))
78+
resultMap[it] = SpecMap.Tests(parseJsonText(response.toString()))
8079
})
8180
}.values.toTypedArray())
8281
).then({ _: Any?, _: Any -> resolve(resultMap) }, { resolve(resultMap) })
8382
}
8483

85-
private fun Map<TestArea, SectionsMap>.isTestsMapExists(testArea: TestArea, requestedMainSection: String, requestedSubsectionPath: String): Boolean {
86-
val subsectionsArray = this[testArea]?.sectionTestMap?.jsonObject?.get(requestedMainSection) ?: return false
84+
private fun Map<TestArea, SpecMap.Sections>.isTestsMapExists(testArea: TestArea, requestedMainSection: String, requestedSubsectionPath: String): Boolean {
85+
val subsectionsArray = this[testArea]?.json?.jsonObject?.get(requestedMainSection) ?: return false
8786
subsectionsArray.jsonArray.forEach { jsonElement ->
8887
if (jsonElement.primitive.content == requestedSubsectionPath)
8988
return true
@@ -99,13 +98,13 @@ interface GithubTestsLoader {
9998
}
10099

101100

102-
fun loadSectionsMapFileFromRawGithub(): Promise<Map<TestArea, SectionsMap>> = Promise { resolve, _ ->
103-
val resultMap = mutableMapOf<TestArea, SectionsMap>()
101+
fun loadSectionsMapFileFromRawGithub(): Promise<Map<TestArea, SpecMap.Sections>> = Promise { resolve, _ ->
102+
val resultMap = mutableMapOf<TestArea, SpecMap.Sections>()
104103
`$`.`when`(
105104
*(testAreasToLoad.asList().associateWith {
106105
`$`.ajax(getFullSectionsMapPath(it), jQueryAjaxSettings { })
107106
.then({ response: Any?, _: Any ->
108-
resultMap[it] = SectionsMap(parseJsonText(response.toString()))
107+
resultMap[it] = SpecMap.Sections(parseJsonText(response.toString()))
109108
})
110109
}.values.toTypedArray())
111110
).then({ _: Any?, _: Any -> resolve(resultMap) }, { resolve(resultMap) })
@@ -136,5 +135,5 @@ interface GithubTestsLoader {
136135

137136
}
138137

139-
fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List<String>, sectionsMapsByTestArea: Map<TestArea, SectionsMap>): Promise<Promise<SpecSection>>
138+
fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List<String>, sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>): Promise<Promise<SpecSection>>
140139
}

web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/LoaderByTestsMapFile.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jetbrains.kotlin.spec.loader
22

3-
import org.jetbrains.kotlin.spec.entity.TestMap
4-
import org.jetbrains.kotlin.spec.entity.SectionsMap
3+
import org.jetbrains.kotlin.spec.entity.SpecMap
54
import org.jetbrains.kotlin.spec.entity.SpecSection
65
import org.jetbrains.kotlin.spec.entity.test.SpecTest
76
import org.jetbrains.kotlin.spec.entity.test.TestPlace
@@ -17,8 +16,8 @@ import kotlin.js.Promise
1716

1817
class LoaderByTestsMapFile : GithubTestsLoader {
1918

20-
private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map<TestArea, SectionsMap>
21-
): Promise<Map<TestArea, TestMap>> {
19+
private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map<TestArea, SpecMap.Sections>
20+
): Promise<Map<TestArea, SpecMap.Tests>> {
2221
return loadTestMapFileFromRawGithub(
2322
mainSectionName = mainSectionName,
2423
path = sectionsPath,
@@ -30,9 +29,9 @@ class LoaderByTestsMapFile : GithubTestsLoader {
3029
private fun loadSectionsMapFile() = loadSectionsMapFileFromRawGithub()
3130

3231

33-
private fun getPromisesForTestFilesFromTestMap(testsMap: TestMap?, testArea: TestArea): Array<Promise<SpecTest>> {
32+
private fun getPromisesForTestFilesFromTestMap(testsMap: SpecMap.Tests?, testArea: TestArea): Array<Promise<SpecTest>> {
3433
val promises = mutableListOf<Promise<SpecTest>>()
35-
val testsMap = testsMap?.sectionTestMap ?: return promises.toTypedArray()
34+
val testsMap = testsMap?.json ?: return promises.toTypedArray()
3635

3736
for ((paragraph, testsByParagraphs) in testsMap.jsonObject) {
3837
for ((testType, testsByTypes) in testsByParagraphs.jsonObject) {
@@ -53,7 +52,7 @@ class LoaderByTestsMapFile : GithubTestsLoader {
5352
override fun loadTestFiles(sectionToLoadName: String,
5453
mainSectionPath: String,
5554
sectionsPath: List<String>,
56-
sectionsMapsByTestArea: Map<TestArea, SectionsMap>
55+
sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>
5756
) = loadTestsMapFile(mainSectionName = mainSectionPath,
5857
sectionsPath = if (mainSectionPath == sectionToLoadName && sectionsPath.isEmpty()) ""
5958
else if (sectionsPath.isNotEmpty()) sectionsPath.joinToString("/") + "/" + sectionToLoadName
@@ -71,7 +70,7 @@ class LoaderByTestsMapFile : GithubTestsLoader {
7170

7271
private fun getPromiseForTests(
7372
testArea: TestArea,
74-
testMaps: Map<TestArea, TestMap>,
73+
testMaps: Map<TestArea, SpecMap.Tests>,
7574
mapOfTests: MutableMap<TestArea, List<SpecTest>>
7675
) = Promise.all(
7776
getPromisesForTestFilesFromTestMap(testMaps[testArea], testArea))

web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/SpecTestsLoader.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.spec.loader
22

33
import js.externals.jquery.JQuery
44
import js.externals.jquery.`$`
5-
import org.jetbrains.kotlin.spec.entity.SectionsMap
5+
import org.jetbrains.kotlin.spec.entity.SpecMap
66
import org.jetbrains.kotlin.spec.entity.SpecSection
77
import org.jetbrains.kotlin.spec.entity.test.parameters.testArea.TestArea
88
import org.jetbrains.kotlin.spec.utils.format
@@ -169,11 +169,12 @@ class SpecTestsLoader {
169169

170170
fun onTestsLoadingLinkClick(link: JQuery) {
171171
loader.loadSectionsMapFiles()
172-
.then { sectionsMapsByTestArea -> loadTests(link, sectionsMapsByTestArea)
173-
}
172+
.then { sectionsMapsByTestArea ->
173+
loadTests(link, sectionsMapsByTestArea)
174+
}
174175
}
175176

176-
private fun loadTests(link: JQuery, sectionsMapsByTestArea: Map<TestArea, SectionsMap>){
177+
private fun loadTests(link: JQuery, sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>) {
177178
val section = link.parent("h2, h3, h4, h5")
178179
val paragraphsInfo = getParagraphsInfo(section)
179180
val nestedSections = getNestedSections(section)
@@ -196,9 +197,9 @@ class SpecTestsLoader {
196197
}
197198

198199
loader.loadTestFiles(
199-
sectionToLoadName= sectionToLoadName,
200+
sectionToLoadName = sectionToLoadName,
200201
mainSectionPath = mainSectionsPath,
201-
sectionsPath= sectionsPath,
202+
sectionsPath = sectionsPath,
202203
sectionsMapsByTestArea = sectionsMapsByTestArea)
203204
.then { sectionTestSet ->
204205

0 commit comments

Comments
 (0)