@@ -5,7 +5,7 @@ import js.externals.jquery.JQueryXHR
55import js.externals.jquery .`$`
66import kotlinx.serialization.json.Json
77import kotlinx.serialization.json.JsonConfiguration
8- import org.jetbrains.kotlin.spec.entity.SectionTestMap
8+ import org.jetbrains.kotlin.spec.entity.TestsLoadingInfo
99import org.jetbrains.kotlin.spec.entity.SpecSection
1010import org.jetbrains.kotlin.spec.entity.test.SpecTest
1111import org.jetbrains.kotlin.spec.entity.test.TestPlace
@@ -25,8 +25,13 @@ interface GithubTestsLoader {
2525 private const val LINKED_SPEC_TESTS_FOLDER = " linked"
2626 private const val HELPERS_FOLDER = " helpers"
2727
28+ private const val SECTIONS_MAP_FILENAME = " sectionsMap.json"
29+ private const val TESTS_MAP_FILENAME = " testsMap.json"
30+
2831 const val DEFAULT_BRANCH = " spec-tests"
2932
33+ protected val testAreasToLoad = TestArea .values()
34+
3035 fun getBranch () = window.localStorage.getItem(" spec-tests-branch" ) ? : DEFAULT_BRANCH
3136
3237 fun loadHelperFromRawGithub (fileName : String , testArea : TestArea ): Promise <String > {
@@ -54,28 +59,61 @@ interface GithubTestsLoader {
5459
5560
5661 fun loadTestMapFileFromRawGithub (
62+ mainSectionName : String ,
5763 path : String ,
5864 testType : TestOrigin ,
59- testAreasToLoad : List <TestArea >
60- ): Promise <Map <TestArea , SectionTestMap >> = Promise { resolve, _ ->
61- val resultMap = mutableMapOf<TestArea , SectionTestMap >()
65+ sectionsMapByTestArea : Map <TestArea , TestsLoadingInfo .Sections >
66+ ): Promise <Map <TestArea , TestsLoadingInfo .Tests >> = Promise { resolve, _ ->
67+ val resultMap = mutableMapOf<TestArea , TestsLoadingInfo .Tests >()
68+ val loadableTestAreas: MutableSet <TestArea > = mutableSetOf ()
69+ testAreasToLoad.forEach {
70+ if (sectionsMapByTestArea.isTestsMapExists(testArea = it, requestedMainSection = mainSectionName, requestedSubsectionPath = path)) {
71+ loadableTestAreas.add(it)
72+ }
73+ }
6274 `$`.`when `(
63- * (testAreasToLoad .associateWith {
64- `$`.ajax(getFullTestMapPath(testType, it, path), jQueryAjaxSettings { })
75+ * (loadableTestAreas .associateWith {
76+ `$`.ajax(getFullTestMapPath(testType, it, mainSectionName, path), jQueryAjaxSettings { })
6577 .then({ response: Any? , _: Any ->
66- resultMap[it] = SectionTestMap (parseJsonText(response.toString()))
78+ resultMap[it] = TestsLoadingInfo . Tests (parseJsonText(response.toString()))
6779 })
6880 }.values.toTypedArray())
6981 ).then({ _: Any? , _: Any -> resolve(resultMap) }, { resolve(resultMap) })
7082 }
7183
72- private fun getFullTestMapPath (testOrigin : TestOrigin , testArea : TestArea , path : String ) =
84+ private fun Map <TestArea , TestsLoadingInfo .Sections >.isTestsMapExists (testArea : TestArea , requestedMainSection : String , requestedSubsectionPath : String ): Boolean {
85+ val subsectionsArray = this [testArea]?.json?.jsonObject?.get(requestedMainSection) ? : return false
86+ subsectionsArray.jsonArray.forEach { jsonElement ->
87+ if (jsonElement.primitive.content == requestedSubsectionPath)
88+ return true
89+ }
90+ return false
91+ }
92+
93+ private fun getFullTestMapPath (testOrigin : TestOrigin , testArea : TestArea , mainSectionName : String , path : String ) =
7394 when (testOrigin) {
74- TestOrigin .SPEC_TEST -> " {1}/{2}/{3}/{4}/{5}/{6}"
75- .format(RAW_GITHUB_URL , getBranch(), SPEC_TEST_DATA_PATH , testArea.path, LINKED_SPEC_TESTS_FOLDER , path)
76- TestOrigin .IMPLEMENTATION_TEST -> " {1}/{2}/{3}" .format(RAW_GITHUB_URL , getBranch(), path)
95+ TestOrigin .SPEC_TEST -> " {1}/{2}/{3}/{4}/{5}/{6}/{7}/{8} "
96+ .format(RAW_GITHUB_URL , getBranch(), SPEC_TEST_DATA_PATH , testArea.path, LINKED_SPEC_TESTS_FOLDER , mainSectionName, path, TESTS_MAP_FILENAME )
97+ TestOrigin .IMPLEMENTATION_TEST -> " {1}/{2}/{3}/{4}/{5} " .format(RAW_GITHUB_URL , getBranch(), mainSectionName, path, TESTS_MAP_FILENAME )
7798 }
7899
100+
101+ fun loadSectionsMapFileFromRawGithub (): Promise <Map <TestArea , TestsLoadingInfo .Sections >> = Promise { resolve, _ ->
102+ val resultMap = mutableMapOf<TestArea , TestsLoadingInfo .Sections >()
103+ `$`.`when `(
104+ * (testAreasToLoad.asList().associateWith {
105+ `$`.ajax(getFullSectionsMapPath(it), jQueryAjaxSettings { })
106+ .then({ response: Any? , _: Any ->
107+ resultMap[it] = TestsLoadingInfo .Sections (parseJsonText(response.toString()))
108+ })
109+ }.values.toTypedArray())
110+ ).then({ _: Any? , _: Any -> resolve(resultMap) }, { resolve(resultMap) })
111+ }
112+
113+ private fun getFullSectionsMapPath (testArea : TestArea ) = " {1}/{2}/{3}/{4}/{5}/{6}"
114+ .format(RAW_GITHUB_URL , getBranch(), SPEC_TEST_DATA_PATH , testArea.path, LINKED_SPEC_TESTS_FOLDER , SECTIONS_MAP_FILENAME )
115+
116+
79117 private fun getFullHelperPath (testArea : TestArea , helperFile : String ) =
80118 " {1}/{2}/{3}/{4}/{5}/{6}"
81119 .format(RAW_GITHUB_URL , getBranch(), SPEC_TEST_DATA_PATH , testArea.path, HELPERS_FOLDER , helperFile)
@@ -97,5 +135,5 @@ interface GithubTestsLoader {
97135
98136 }
99137
100- fun loadTestFiles (sectionName : String , sectionsPath : List <String >, testAreasToLoad : Array <TestArea >): Promise <Promise <SpecSection >>
101- }
138+ fun loadTestFiles (sectionName : String , mainSectionName : String , sectionsPath : List <String >, sectionsMapsByTestArea : Map <TestArea , TestsLoadingInfo . Sections >): Promise <Promise <SpecSection >>
139+ }
0 commit comments