Skip to content

Commit 4c50052

Browse files
committed
fix test
1 parent bbddddc commit 4c50052

File tree

1 file changed

+166
-11
lines changed

1 file changed

+166
-11
lines changed

src/test/kotlin/com/emberjs/gts/GtsFormatIdentTest.kt

Lines changed: 166 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import org.junit.Test
3636
class GtsFormatIdentTest : BasePlatformTestCase() {
3737

3838
@Throws(IncorrectOperationException::class)
39-
fun doStringBasedTest(text: String, textAfter: String) {
40-
doTextTest(text, textAfter, "gts", GtsFileType.INSTANCE)
39+
fun doStringBasedTest(text: String, textAfter: String, withLineIndentTest: Boolean = true) {
40+
doTextTest(text, textAfter, "gts", withLineIndentTest)
4141
}
4242

4343

@@ -48,10 +48,9 @@ class GtsFormatIdentTest : BasePlatformTestCase() {
4848
*
4949
* @param beforeText The text run the formatter on
5050
* @param textAfter The expected result after running the formatter
51-
* @param templateDataLanguageType The templated language of the file
5251
*/
5352
@Throws(IncorrectOperationException::class)
54-
fun doTextTest(beforeText: String, textAfter: String, extension: String, templateDataLanguageType: LanguageFileType) {
53+
fun doTextTest(beforeText: String, textAfter: String, extension: String, withLineIndentTest: Boolean) {
5554
// define action to run "Reformat Code" on the whole "file" defined by beforeText
5655
val fullFormatRunnableFactory = Runnable {
5756
val rangeToUse: TextRange = myFixture.file.textRange
@@ -67,28 +66,28 @@ class GtsFormatIdentTest : BasePlatformTestCase() {
6766
AutoIndentLinesHandler().invoke(myFixture.project, editor, myFixture.file)
6867
}
6968

70-
doFormatterActionTest(fullFormatRunnableFactory, beforeText, textAfter, extension, templateDataLanguageType)
71-
doFormatterActionTest(lineFormatRunnableFactory, beforeText, textAfter, extension, templateDataLanguageType)
69+
if (withLineIndentTest) {
70+
doFormatterActionTest(lineFormatRunnableFactory, beforeText, textAfter, extension)
71+
} else {
72+
doFormatterActionTest(fullFormatRunnableFactory, beforeText, textAfter, extension)
73+
}
7274
}
7375

7476
private fun doFormatterActionTest(
7577
formatAction: Runnable,
7678
beforeText: String,
7779
textAfter: String,
78-
extension: String,
79-
templateDataLanguageType: LanguageFileType
80+
extension: String
8081
) {
8182
val baseFile: PsiFile = myFixture.configureByText("A.$extension", beforeText)
8283

8384
val virtualFile = checkNotNull(baseFile.virtualFile)
84-
TemplateDataLanguageMappings.getInstance(project).setMapping(virtualFile, templateDataLanguageType.language)
8585
IndexingTestUtil.waitUntilIndexesAreReady(project)
8686

8787
// fetch a fresh instance of the file -- the template data mapping creates a new instance,
8888
// which was causing problems in PsiFileImpl.isValid()
8989
val file = checkNotNull(PsiManager.getInstance(project).findFile(virtualFile))
9090
WriteCommandAction.runWriteCommandAction(project, formatAction)
91-
TemplateDataLanguageMappings.getInstance(project).cleanupForNextTest()
9291
assertEquals("Reformat Code failed", prepareText(textAfter), prepareText(file.text))
9392
}
9493

@@ -264,8 +263,164 @@ class GtsFormatIdentTest : BasePlatformTestCase() {
264263
{{demo}}
265264
</template>
266265
""".trimIndent()
267-
doStringBasedTest(gts, gtsAfter)
266+
doStringBasedTest(gts, gtsAfter, false)
268267
}
269268

269+
@Test
270+
fun testGtsLineIndent() {
271+
val gts = """
272+
import {asd} from "xyz";
273+
let x = <template>hello world</template>;
274+
function test() {
275+
const abc = 'xyz'
276+
};
277+
x = <template>
278+
hello world
279+
hello world
280+
hello world
281+
<div>
282+
{{demo}}
283+
</div>
284+
hello world
285+
hello world
286+
{{demo}}
287+
hello world
288+
</template>;
289+
x = <template>
290+
hello world hello world hello world hello world hello world hello world
291+
<div></div>
292+
</template>;
293+
x = <template>
294+
hello world hello world hello world hello world hello world hello world
295+
<div></div>
296+
</template>;
297+
x = <template>
298+
<div></div>
299+
hello world hello world hello world hello world hello world hello world
300+
</template>;
301+
302+
class Foo {
303+
<template>
304+
Hi
305+
</template>
306+
}
307+
308+
class Bar {
309+
<template>
310+
hello world
311+
hello world
312+
hello world
313+
hello world
314+
{{demo}}
315+
hello world
316+
hello world
317+
</template>
318+
}
319+
320+
class Bar {
321+
<template>
322+
<div>
323+
{{demo}}
324+
</div>
325+
hello world
326+
hello world
327+
hello world
328+
hello world
329+
hello world
330+
hello world
331+
</template>
332+
}
333+
334+
<template>
335+
hello world
336+
<div>
337+
{{demo}}
338+
</div>
339+
hello world
340+
hello world
341+
hello world
342+
hello world
343+
hello world
344+
{{demo}}
345+
</template>
346+
""".trimIndent()
270347

348+
val gtsAfter = """
349+
import {asd} from "xyz";
350+
let x = <template>hello world</template>;
351+
function test() {
352+
const abc = 'xyz'
353+
};
354+
x = <template>
355+
hello world
356+
hello world
357+
hello world
358+
<div>
359+
{{demo}}
360+
</div>
361+
hello world
362+
hello world
363+
{{demo}}
364+
hello world
365+
</template>;
366+
x = <template>
367+
hello world hello world hello world hello world hello world hello world
368+
<div></div>
369+
</template>;
370+
x = <template>
371+
hello world hello world hello world hello world hello world hello world
372+
<div></div>
373+
</template>;
374+
x = <template>
375+
<div></div>
376+
hello world hello world hello world hello world hello world hello world
377+
</template>;
378+
379+
class Foo {
380+
<template>
381+
Hi
382+
</template>
383+
}
384+
385+
class Bar {
386+
<template>
387+
hello world
388+
hello world
389+
hello world
390+
hello world
391+
{{demo}}
392+
hello world
393+
hello world
394+
</template>
395+
}
396+
397+
class Bar {
398+
<template>
399+
<div>
400+
{{demo}}
401+
</div>
402+
hello world
403+
hello world
404+
hello world
405+
hello world
406+
hello world
407+
hello world
408+
</template>
409+
}
410+
411+
<template>
412+
hello world
413+
<div>
414+
{{demo}}
415+
</div>
416+
hello world
417+
hello world
418+
hello world
419+
hello world
420+
hello world
421+
{{demo}}
422+
</template>
423+
""".trimIndent()
424+
doStringBasedTest(gts, gtsAfter, true)
425+
}
271426
}

0 commit comments

Comments
 (0)