Skip to content

Commit

Permalink
move SpectTestsMap and SectionsMap to sealed class SpecMap
Browse files Browse the repository at this point in the history
  • Loading branch information
stasjas committed Sep 13, 2020
1 parent e217400 commit e35b5a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,9 +62,9 @@ interface GithubTestsLoader {
mainSectionName: String,
path: String,
testType: TestOrigin,
sectionsMapByTestArea: Map<TestArea, SectionsMap>
): Promise<Map<TestArea, TestMap>> = Promise { resolve, _ ->
val resultMap = mutableMapOf<TestArea, TestMap>()
sectionsMapByTestArea: Map<TestArea, SpecMap.Sections>
): Promise<Map<TestArea, SpecMap.Tests>> = Promise { resolve, _ ->
val resultMap = mutableMapOf<TestArea, SpecMap.Tests>()
val loadableTestAreas: MutableSet<TestArea> = mutableSetOf()
testAreasToLoad.forEach {
if (sectionsMapByTestArea.isTestsMapExists(testArea = it, requestedMainSection = mainSectionName, requestedSubsectionPath = path)) {
Expand All @@ -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<TestArea, SectionsMap>.isTestsMapExists(testArea: TestArea, requestedMainSection: String, requestedSubsectionPath: String): Boolean {
val subsectionsArray = this[testArea]?.sectionTestMap?.jsonObject?.get(requestedMainSection) ?: return false
private fun Map<TestArea, SpecMap.Sections>.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
Expand All @@ -99,13 +98,13 @@ interface GithubTestsLoader {
}


fun loadSectionsMapFileFromRawGithub(): Promise<Map<TestArea, SectionsMap>> = Promise { resolve, _ ->
val resultMap = mutableMapOf<TestArea, SectionsMap>()
fun loadSectionsMapFileFromRawGithub(): Promise<Map<TestArea, SpecMap.Sections>> = Promise { resolve, _ ->
val resultMap = mutableMapOf<TestArea, SpecMap.Sections>()
`$`.`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) })
Expand Down Expand Up @@ -136,5 +135,5 @@ interface GithubTestsLoader {

}

fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List<String>, sectionsMapsByTestArea: Map<TestArea, SectionsMap>): Promise<Promise<SpecSection>>
fun loadTestFiles(sectionName: String, mainSectionName: String, sectionsPath: List<String>, sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>): Promise<Promise<SpecSection>>
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,8 +16,8 @@ import kotlin.js.Promise

class LoaderByTestsMapFile : GithubTestsLoader {

private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map<TestArea, SectionsMap>
): Promise<Map<TestArea, TestMap>> {
private fun loadTestsMapFile(mainSectionName: String, sectionsPath: String, sectionsMapByTestArea: Map<TestArea, SpecMap.Sections>
): Promise<Map<TestArea, SpecMap.Tests>> {
return loadTestMapFileFromRawGithub(
mainSectionName = mainSectionName,
path = sectionsPath,
Expand All @@ -30,9 +29,9 @@ class LoaderByTestsMapFile : GithubTestsLoader {
private fun loadSectionsMapFile() = loadSectionsMapFileFromRawGithub()


private fun getPromisesForTestFilesFromTestMap(testsMap: TestMap?, testArea: TestArea): Array<Promise<SpecTest>> {
private fun getPromisesForTestFilesFromTestMap(testsMap: SpecMap.Tests?, testArea: TestArea): Array<Promise<SpecTest>> {
val promises = mutableListOf<Promise<SpecTest>>()
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) {
Expand All @@ -53,7 +52,7 @@ class LoaderByTestsMapFile : GithubTestsLoader {
override fun loadTestFiles(sectionToLoadName: String,
mainSectionPath: String,
sectionsPath: List<String>,
sectionsMapsByTestArea: Map<TestArea, SectionsMap>
sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>
) = loadTestsMapFile(mainSectionName = mainSectionPath,
sectionsPath = if (mainSectionPath == sectionToLoadName && sectionsPath.isEmpty()) ""
else if (sectionsPath.isNotEmpty()) sectionsPath.joinToString("/") + "/" + sectionToLoadName
Expand All @@ -71,7 +70,7 @@ class LoaderByTestsMapFile : GithubTestsLoader {

private fun getPromiseForTests(
testArea: TestArea,
testMaps: Map<TestArea, TestMap>,
testMaps: Map<TestArea, SpecMap.Tests>,
mapOfTests: MutableMap<TestArea, List<SpecTest>>
) = Promise.all(
getPromisesForTestFilesFromTestMap(testMaps[testArea], testArea))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TestArea, SectionsMap>){
private fun loadTests(link: JQuery, sectionsMapsByTestArea: Map<TestArea, SpecMap.Sections>) {
val section = link.parent("h2, h3, h4, h5")
val paragraphsInfo = getParagraphsInfo(section)
val nestedSections = getNestedSections(section)
Expand All @@ -196,9 +197,9 @@ class SpecTestsLoader {
}

loader.loadTestFiles(
sectionToLoadName= sectionToLoadName,
sectionToLoadName = sectionToLoadName,
mainSectionPath = mainSectionsPath,
sectionsPath= sectionsPath,
sectionsPath = sectionsPath,
sectionsMapsByTestArea = sectionsMapsByTestArea)
.then { sectionTestSet ->

Expand Down

0 comments on commit e35b5a6

Please sign in to comment.