diff --git a/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/SpecMap.kt b/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/SpecMap.kt new file mode 100644 index 000000000..706f2fefd --- /dev/null +++ b/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/SpecMap.kt @@ -0,0 +1,8 @@ +package org.jetbrains.kotlin.spec.entity + +import kotlinx.serialization.json.JsonElement + +sealed class SpecMap() { + class Tests(val json: JsonElement) + class Sections(val json: JsonElement) +} \ No newline at end of file diff --git a/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/TestMap.kt b/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/TestMap.kt deleted file mode 100644 index c6a4f459a..000000000 --- a/web/src/main/kotlin/org/jetbrains/kotlin/spec/entity/TestMap.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.kotlin.spec.entity - -import kotlinx.serialization.json.JsonElement - -class TestMap(val sectionTestMap: JsonElement) - -class SectionsMap(val sectionTestMap: JsonElement) \ No newline at end of file diff --git a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/GithubTestsLoader.kt b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/GithubTestsLoader.kt index fa3b0312b..738cb4dca 100644 --- a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/GithubTestsLoader.kt +++ b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/GithubTestsLoader.kt @@ -5,9 +5,8 @@ import js.externals.jquery.JQueryXHR import js.externals.jquery.`$` import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration -import org.jetbrains.kotlin.spec.entity.SectionsMap +import org.jetbrains.kotlin.spec.entity.SpecMap import org.jetbrains.kotlin.spec.entity.SpecSection -import org.jetbrains.kotlin.spec.entity.TestMap import org.jetbrains.kotlin.spec.entity.test.SpecTest import org.jetbrains.kotlin.spec.entity.test.TestPlace import org.jetbrains.kotlin.spec.entity.test.parameters.TestInfo @@ -63,9 +62,9 @@ interface GithubTestsLoader { mainSectionName: String, path: String, testType: TestOrigin, - sectionsMapByTestArea: Map - ): Promise> = Promise { resolve, _ -> - val resultMap = mutableMapOf() + sectionsMapByTestArea: Map + ): Promise> = Promise { resolve, _ -> + val resultMap = mutableMapOf() val loadableTestAreas: MutableSet = mutableSetOf() testAreasToLoad.forEach { if (sectionsMapByTestArea.isTestsMapExists(testArea = it, requestedMainSection = mainSectionName, requestedSubsectionPath = path)) { @@ -76,14 +75,14 @@ interface GithubTestsLoader { *(loadableTestAreas.associateWith { `$`.ajax(getFullTestMapPath(testType, it, mainSectionName, path), jQueryAjaxSettings { }) .then({ response: Any?, _: Any -> - resultMap[it] = TestMap(parseJsonText(response.toString())) + resultMap[it] = SpecMap.Tests(parseJsonText(response.toString())) }) }.values.toTypedArray()) ).then({ _: Any?, _: Any -> resolve(resultMap) }, { resolve(resultMap) }) } - private fun Map.isTestsMapExists(testArea: TestArea, requestedMainSection: String, requestedSubsectionPath: String): Boolean { - val subsectionsArray = this[testArea]?.sectionTestMap?.jsonObject?.get(requestedMainSection) ?: return false + private fun Map.isTestsMapExists(testArea: TestArea, requestedMainSection: String, requestedSubsectionPath: String): Boolean { + val subsectionsArray = this[testArea]?.json?.jsonObject?.get(requestedMainSection) ?: return false subsectionsArray.jsonArray.forEach { jsonElement -> if (jsonElement.primitive.content == requestedSubsectionPath) return true @@ -99,13 +98,13 @@ interface GithubTestsLoader { } - fun loadSectionsMapFileFromRawGithub(): Promise> = Promise { resolve, _ -> - val resultMap = mutableMapOf() + fun loadSectionsMapFileFromRawGithub(): Promise> = Promise { resolve, _ -> + val resultMap = mutableMapOf() `$`.`when`( *(testAreasToLoad.asList().associateWith { `$`.ajax(getFullSectionsMapPath(it), jQueryAjaxSettings { }) .then({ response: Any?, _: Any -> - resultMap[it] = SectionsMap(parseJsonText(response.toString())) + resultMap[it] = SpecMap.Sections(parseJsonText(response.toString())) }) }.values.toTypedArray()) ).then({ _: Any?, _: Any -> resolve(resultMap) }, { resolve(resultMap) }) @@ -136,5 +135,5 @@ interface GithubTestsLoader { } - fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List, sectionsMapsByTestArea: Map): Promise> + fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List, sectionsMapsByTestArea: Map): Promise> } diff --git a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/LoaderByTestsMapFile.kt b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/LoaderByTestsMapFile.kt index 7945f8c04..026f1cc13 100644 --- a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/LoaderByTestsMapFile.kt +++ b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/LoaderByTestsMapFile.kt @@ -1,7 +1,6 @@ package org.jetbrains.kotlin.spec.loader -import org.jetbrains.kotlin.spec.entity.TestMap -import org.jetbrains.kotlin.spec.entity.SectionsMap +import org.jetbrains.kotlin.spec.entity.SpecMap import org.jetbrains.kotlin.spec.entity.SpecSection import org.jetbrains.kotlin.spec.entity.test.SpecTest import org.jetbrains.kotlin.spec.entity.test.TestPlace @@ -17,8 +16,8 @@ import kotlin.js.Promise class LoaderByTestsMapFile : GithubTestsLoader { - private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map - ): Promise> { + private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map + ): Promise> { return loadTestMapFileFromRawGithub( mainSectionName = mainSectionName, path = sectionsPath, @@ -30,9 +29,9 @@ class LoaderByTestsMapFile : GithubTestsLoader { private fun loadSectionsMapFile() = loadSectionsMapFileFromRawGithub() - private fun getPromisesForTestFilesFromTestMap(testsMap: TestMap?, testArea: TestArea): Array> { + private fun getPromisesForTestFilesFromTestMap(testsMap: SpecMap.Tests?, testArea: TestArea): Array> { val promises = mutableListOf>() - val testsMap = testsMap?.sectionTestMap ?: return promises.toTypedArray() + val testsMap = testsMap?.json ?: return promises.toTypedArray() for ((paragraph, testsByParagraphs) in testsMap.jsonObject) { for ((testType, testsByTypes) in testsByParagraphs.jsonObject) { @@ -53,7 +52,7 @@ class LoaderByTestsMapFile : GithubTestsLoader { override fun loadTestFiles(sectionToLoadName: String, mainSectionPath: String, sectionsPath: List, - sectionsMapsByTestArea: Map + sectionsMapsByTestArea: Map ) = loadTestsMapFile(mainSectionName = mainSectionPath, sectionsPath = if (mainSectionPath == sectionToLoadName && sectionsPath.isEmpty()) "" else if (sectionsPath.isNotEmpty()) sectionsPath.joinToString("/") + "/" + sectionToLoadName @@ -71,7 +70,7 @@ class LoaderByTestsMapFile : GithubTestsLoader { private fun getPromiseForTests( testArea: TestArea, - testMaps: Map, + testMaps: Map, mapOfTests: MutableMap> ) = Promise.all( getPromisesForTestFilesFromTestMap(testMaps[testArea], testArea)) diff --git a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/SpecTestsLoader.kt b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/SpecTestsLoader.kt index b90afa21a..ac7743dba 100644 --- a/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/SpecTestsLoader.kt +++ b/web/src/main/kotlin/org/jetbrains/kotlin/spec/loader/SpecTestsLoader.kt @@ -2,7 +2,7 @@ package org.jetbrains.kotlin.spec.loader import js.externals.jquery.JQuery import js.externals.jquery.`$` -import org.jetbrains.kotlin.spec.entity.SectionsMap +import org.jetbrains.kotlin.spec.entity.SpecMap import org.jetbrains.kotlin.spec.entity.SpecSection import org.jetbrains.kotlin.spec.entity.test.parameters.testArea.TestArea import org.jetbrains.kotlin.spec.utils.format @@ -169,11 +169,12 @@ class SpecTestsLoader { fun onTestsLoadingLinkClick(link: JQuery) { loader.loadSectionsMapFiles() - .then { sectionsMapsByTestArea -> loadTests(link, sectionsMapsByTestArea) - } + .then { sectionsMapsByTestArea -> + loadTests(link, sectionsMapsByTestArea) + } } - private fun loadTests(link: JQuery, sectionsMapsByTestArea: Map){ + private fun loadTests(link: JQuery, sectionsMapsByTestArea: Map) { val section = link.parent("h2, h3, h4, h5") val paragraphsInfo = getParagraphsInfo(section) val nestedSections = getNestedSections(section) @@ -196,9 +197,9 @@ class SpecTestsLoader { } loader.loadTestFiles( - sectionToLoadName= sectionToLoadName, + sectionToLoadName = sectionToLoadName, mainSectionPath = mainSectionsPath, - sectionsPath= sectionsPath, + sectionsPath = sectionsPath, sectionsMapsByTestArea = sectionsMapsByTestArea) .then { sectionTestSet ->