@@ -5,7 +5,7 @@ import js.externals.jquery.JQueryXHR
5
5
import js.externals.jquery .`$`
6
6
import kotlinx.serialization.json.Json
7
7
import kotlinx.serialization.json.JsonConfiguration
8
- import org.jetbrains.kotlin.spec.entity.SectionTestMap
8
+ import org.jetbrains.kotlin.spec.entity.TestsLoadingInfo
9
9
import org.jetbrains.kotlin.spec.entity.SpecSection
10
10
import org.jetbrains.kotlin.spec.entity.test.SpecTest
11
11
import org.jetbrains.kotlin.spec.entity.test.TestPlace
@@ -25,8 +25,13 @@ interface GithubTestsLoader {
25
25
private const val LINKED_SPEC_TESTS_FOLDER = " linked"
26
26
private const val HELPERS_FOLDER = " helpers"
27
27
28
+ private const val SECTIONS_MAP_FILENAME = " sectionsMap.json"
29
+ private const val TESTS_MAP_FILENAME = " testsMap.json"
30
+
28
31
const val DEFAULT_BRANCH = " spec-tests"
29
32
33
+ protected val testAreasToLoad = TestArea .values()
34
+
30
35
fun getBranch () = window.localStorage.getItem(" spec-tests-branch" ) ? : DEFAULT_BRANCH
31
36
32
37
fun loadHelperFromRawGithub (fileName : String , testArea : TestArea ): Promise <String > {
@@ -54,28 +59,61 @@ interface GithubTestsLoader {
54
59
55
60
56
61
fun loadTestMapFileFromRawGithub (
62
+ mainSectionName : String ,
57
63
path : String ,
58
64
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
+ }
62
74
`$`.`when `(
63
- * (testAreasToLoad .associateWith {
64
- `$`.ajax(getFullTestMapPath(testType, it, path), jQueryAjaxSettings { })
75
+ * (loadableTestAreas .associateWith {
76
+ `$`.ajax(getFullTestMapPath(testType, it, mainSectionName, path), jQueryAjaxSettings { })
65
77
.then({ response: Any? , _: Any ->
66
- resultMap[it] = SectionTestMap (parseJsonText(response.toString()))
78
+ resultMap[it] = TestsLoadingInfo . Tests (parseJsonText(response.toString()))
67
79
})
68
80
}.values.toTypedArray())
69
81
).then({ _: Any? , _: Any -> resolve(resultMap) }, { resolve(resultMap) })
70
82
}
71
83
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 ) =
73
94
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 )
77
98
}
78
99
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
+
79
117
private fun getFullHelperPath (testArea : TestArea , helperFile : String ) =
80
118
" {1}/{2}/{3}/{4}/{5}/{6}"
81
119
.format(RAW_GITHUB_URL , getBranch(), SPEC_TEST_DATA_PATH , testArea.path, HELPERS_FOLDER , helperFile)
@@ -97,5 +135,5 @@ interface GithubTestsLoader {
97
135
98
136
}
99
137
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