Skip to content

Commit 22fd31d

Browse files
KON-263 Add withText extensions (#1118)
* upd code * rename files and fix code * upd code * try code * upd code * upd code * upd code * test code * test code * test code * test code * fix code * fix code * fix code * fix code * fix code * fix code * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd logic * upd for base correct version * fix code * fix code * upd code * change kttxt ext to kttest and ktdoc * remove all kttxt from project * upd scripts * rename rest of snippets * upd script * upd script * upd KotestSnippets name * upd scripts * upd scripts * add comments for script * add `check-ktdoc-snippet` script * upd check * upd check * upd check * upd check * upd check * uncomment tests * add extensions and tests * add tests for KoImport and KoFile * add tests * clean code * upd tests * use new functions in Konsist code * upd after rebase
1 parent 6b2b3b0 commit 22fd31d

File tree

36 files changed

+2370
-66
lines changed

36 files changed

+2370
-66
lines changed

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koannotation/KoAnnotationDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koannotation
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -16,13 +17,21 @@ class KoAnnotationDeclarationForKoTextProviderTest {
1617
.first()
1718

1819
// then
19-
sut
20-
.text
21-
.shouldBeEqualTo(
20+
assertSoftly(sut) {
21+
text.shouldBeEqualTo(
2222
"""
2323
@SampleAnnotationWithParameter(sampleParameter = "text")
2424
""".trimIndent(),
2525
)
26+
hasTextStartingWith("@Sample") shouldBeEqualTo true
27+
hasTextStartingWith("Other") shouldBeEqualTo false
28+
hasTextEndingWith("eter = \"text\")") shouldBeEqualTo true
29+
hasTextEndingWith("other") shouldBeEqualTo false
30+
hasTextContaining("Parameter(sample") shouldBeEqualTo true
31+
hasTextContaining("anno") shouldBeEqualTo false
32+
hasTextMatching(Regex("^[^\\d]*\$")) shouldBeEqualTo true
33+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
34+
}
2635
}
2736

2837
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koannotation/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koargument/KoArgumentDeclarationForKoTextProviderTest.kt

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
44
import com.lemonappdev.konsist.api.ext.list.annotations
55
import com.lemonappdev.konsist.api.ext.list.arguments
66
import com.lemonappdev.konsist.api.ext.list.enumConstants
7+
import org.amshove.kluent.assertSoftly
78
import org.amshove.kluent.shouldBeEqualTo
89
import org.junit.jupiter.api.Test
910

@@ -19,7 +20,17 @@ class KoArgumentDeclarationForKoTextProviderTest {
1920
.first()
2021

2122
// then
22-
sut.text shouldBeEqualTo "sampleArgument = 0"
23+
assertSoftly(sut) {
24+
text shouldBeEqualTo "sampleArgument = 0"
25+
hasTextStartingWith("sample") shouldBeEqualTo true
26+
hasTextStartingWith("Other") shouldBeEqualTo false
27+
hasTextEndingWith("= 0") shouldBeEqualTo true
28+
hasTextEndingWith("other") shouldBeEqualTo false
29+
hasTextContaining("Argument =") shouldBeEqualTo true
30+
hasTextContaining("anno") shouldBeEqualTo false
31+
hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
32+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
33+
}
2334
}
2435

2536
@Test
@@ -33,7 +44,17 @@ class KoArgumentDeclarationForKoTextProviderTest {
3344
.first()
3445

3546
// then
36-
sut.text shouldBeEqualTo "sampleParameter = \"text\""
47+
assertSoftly(sut) {
48+
text shouldBeEqualTo "sampleParameter = \"text\""
49+
hasTextStartingWith("sample") shouldBeEqualTo true
50+
hasTextStartingWith("Other") shouldBeEqualTo false
51+
hasTextEndingWith("= \"text\"") shouldBeEqualTo true
52+
hasTextEndingWith("other") shouldBeEqualTo false
53+
hasTextContaining("Parameter =") shouldBeEqualTo true
54+
hasTextContaining("anno") shouldBeEqualTo false
55+
hasTextMatching(Regex("^[^\\d]*\$")) shouldBeEqualTo true
56+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
57+
}
3758
}
3859

3960
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koargument/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koclass/KoClassDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koclass
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -14,15 +15,23 @@ class KoClassDeclarationForKoTextProviderTest {
1415
.first()
1516

1617
// then
17-
sut
18-
.text
19-
.shouldBeEqualTo(
18+
assertSoftly(sut) {
19+
text.shouldBeEqualTo(
2020
"""
2121
class SampleClass {
2222
val sampleProperty = "SampleText"
2323
}
2424
""".trimIndent(),
2525
)
26+
hasTextStartingWith("class Sample") shouldBeEqualTo true
27+
hasTextStartingWith("Other") shouldBeEqualTo false
28+
hasTextEndingWith("\n}") shouldBeEqualTo true
29+
hasTextEndingWith("other") shouldBeEqualTo false
30+
hasTextContaining("sampleProperty = ") shouldBeEqualTo true
31+
hasTextContaining("anno") shouldBeEqualTo false
32+
hasTextMatching(Regex("^[^\\d]*\$")) shouldBeEqualTo true
33+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
34+
}
2635
}
2736

2837
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koclass/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koconstructor/KoConstructorDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koconstructor
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -16,9 +17,17 @@ class KoConstructorDeclarationForKoTextProviderTest {
1617
.first()
1718

1819
// then
19-
sut
20-
.text
21-
.shouldBeEqualTo("(val sampleParameter: Int)")
20+
assertSoftly(sut) {
21+
text shouldBeEqualTo "(val sampleParameter: Int)"
22+
hasTextStartingWith("(val ") shouldBeEqualTo true
23+
hasTextStartingWith("Other") shouldBeEqualTo false
24+
hasTextEndingWith(": Int)") shouldBeEqualTo true
25+
hasTextEndingWith("other") shouldBeEqualTo false
26+
hasTextContaining("sampleParameter: ") shouldBeEqualTo true
27+
hasTextContaining("anno") shouldBeEqualTo false
28+
hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
29+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
30+
}
2231
}
2332

2433
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koconstructor/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koenumconstant/KoEnumConstantDeclarationForKoTextProviderTest.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koenumconstant
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -16,7 +17,17 @@ class KoEnumConstantDeclarationForKoTextProviderTest {
1617
.first()
1718

1819
// then
19-
sut.text shouldBeEqualTo "SAMPLE_CONSTANT_1(sampleArgument = 0)"
20+
assertSoftly(sut) {
21+
text shouldBeEqualTo "SAMPLE_CONSTANT_1(sampleArgument = 0)"
22+
hasTextStartingWith("SAMPLE_CONSTANT") shouldBeEqualTo true
23+
hasTextStartingWith("Other") shouldBeEqualTo false
24+
hasTextEndingWith("= 0)") shouldBeEqualTo true
25+
hasTextEndingWith("other") shouldBeEqualTo false
26+
hasTextContaining("CONSTANT_1(sample") shouldBeEqualTo true
27+
hasTextContaining("anno") shouldBeEqualTo false
28+
hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
29+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
30+
}
2031
}
2132

2233
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koenumconstant/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/kofile/KoFileDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.kofile
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -14,16 +15,24 @@ class KoFileDeclarationForKoTextProviderTest {
1415
.first()
1516

1617
// then
17-
sut
18-
.text
19-
.shouldBeEqualTo(
18+
assertSoftly(sut) {
19+
text.shouldBeEqualTo(
2020
"""
2121
fun sampleFunction() {
2222
"SampleText"
2323
}
2424
2525
""".trimIndent(),
2626
)
27+
hasTextStartingWith("fun sampleF") shouldBeEqualTo true
28+
hasTextStartingWith("Other") shouldBeEqualTo false
29+
hasTextEndingWith("}\n") shouldBeEqualTo true
30+
hasTextEndingWith("other") shouldBeEqualTo false
31+
hasTextContaining("Function() {") shouldBeEqualTo true
32+
hasTextContaining("anno") shouldBeEqualTo false
33+
hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
34+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
35+
}
2736
}
2837

2938
private fun getSnippetFile(fileName: String) =

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/kofunction/KoFunctionDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.kofunction
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -14,15 +15,23 @@ class KoFunctionDeclarationForKoTextProviderTest {
1415
.first()
1516

1617
// then
17-
sut
18-
.text
19-
.shouldBeEqualTo(
18+
assertSoftly(sut) {
19+
text.shouldBeEqualTo(
2020
"""
2121
fun sampleFunction() {
2222
val sampleProperty = "SampleText"
2323
}
2424
""".trimIndent(),
2525
)
26+
hasTextStartingWith("fun sample") shouldBeEqualTo true
27+
hasTextStartingWith("Other") shouldBeEqualTo false
28+
hasTextEndingWith("\n}") shouldBeEqualTo true
29+
hasTextEndingWith("other") shouldBeEqualTo false
30+
hasTextContaining("sampleProperty = ") shouldBeEqualTo true
31+
hasTextContaining("anno") shouldBeEqualTo false
32+
hasTextMatching(Regex("^[^\\d]*\$")) shouldBeEqualTo true
33+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
34+
}
2635
}
2736

2837
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/kofunction/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/kogetter/KoGetterDeclarationForKoTextProviderTest.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.kogetter
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -15,9 +16,17 @@ class KoGetterDeclarationForKoTextProviderTest {
1516
.getter
1617

1718
// then
18-
sut
19-
?.text
20-
.shouldBeEqualTo("get() = \"some text\"")
19+
assertSoftly(sut) {
20+
it?.text shouldBeEqualTo "get() = \"some text\""
21+
it?.hasTextStartingWith("get() =") shouldBeEqualTo true
22+
it?.hasTextStartingWith("Other") shouldBeEqualTo false
23+
it?.hasTextEndingWith("text\"") shouldBeEqualTo true
24+
it?.hasTextEndingWith("other") shouldBeEqualTo false
25+
it?.hasTextContaining("some text") shouldBeEqualTo true
26+
it?.hasTextContaining("anno") shouldBeEqualTo false
27+
it?.hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
28+
it?.hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
29+
}
2130
}
2231

2332
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/kogetter/snippet/forkotextprovider/", fileName)

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koimport/KoImportDeclarationForKoNameProviderTest.kt

+62-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koimport
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -29,5 +30,65 @@ class KoImportDeclarationForKoNameProviderTest {
2930
sut.name shouldBeEqualTo "com.lemonappdev.konsist.testdata.SampleType"
3031
}
3132

32-
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koimport/snippet/forkonameprovider/", fileName)
33+
@Test
34+
fun `import-has-name-with-prefix`() {
35+
// given
36+
val sut =
37+
getSnippetFile("import-has-name-with-prefix")
38+
.imports
39+
.first()
40+
41+
// then
42+
assertSoftly(sut) {
43+
hasNameStartingWith("com.lemonappdev") shouldBeEqualTo true
44+
hasNameStartingWith("wrong-prefix") shouldBeEqualTo false
45+
}
46+
}
47+
48+
@Test
49+
fun `import-has-name-with-suffix`() {
50+
// given
51+
val sut =
52+
getSnippetFile("import-has-name-with-suffix")
53+
.imports
54+
.first()
55+
56+
// then
57+
assertSoftly(sut) {
58+
hasNameEndingWith("testdata.SampleClass") shouldBeEqualTo true
59+
hasNameEndingWith("wrong-suffix") shouldBeEqualTo false
60+
}
61+
}
62+
63+
@Test
64+
fun `import-has-name-containing-text`() {
65+
// given
66+
val sut =
67+
getSnippetFile("import-has-name-containing-text")
68+
.imports
69+
.first()
70+
71+
// then
72+
assertSoftly(sut) {
73+
hasNameContaining("konsist.testdata.") shouldBeEqualTo true
74+
hasNameContaining("not-containing") shouldBeEqualTo false
75+
}
76+
}
77+
78+
@Test
79+
fun `import-has-name-matching-regex`() {
80+
// given
81+
val sut =
82+
getSnippetFile("import-has-name-matching-regex")
83+
.imports
84+
.first()
85+
86+
// then
87+
assertSoftly(sut) {
88+
hasNameMatching(Regex("^[a-zA-Z[^0-9]]+")) shouldBeEqualTo true
89+
hasNameMatching(Regex("[0-9]+")) shouldBeEqualTo false
90+
}
91+
}
92+
93+
private fun getSnippetFile(importName: String) = getSnippetKoScope("core/declaration/koimport/snippet/forkonameprovider/", importName)
3394
}

lib/src/integrationTest/kotlin/com/lemonappdev/konsist/core/declaration/koimport/KoImportDeclarationForKoTextProviderTest.kt

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lemonappdev.konsist.core.declaration.koimport
22

33
import com.lemonappdev.konsist.TestSnippetProvider.getSnippetKoScope
4+
import org.amshove.kluent.assertSoftly
45
import org.amshove.kluent.shouldBeEqualTo
56
import org.junit.jupiter.api.Test
67

@@ -15,6 +16,18 @@ class KoImportDeclarationForKoTextProviderTest {
1516

1617
// then
1718
sut.text shouldBeEqualTo "import com.lemonappdev.konsist.testdata.SampleClass"
19+
20+
assertSoftly(sut) {
21+
text shouldBeEqualTo "import com.lemonappdev.konsist.testdata.SampleClass"
22+
hasTextStartingWith("import com.") shouldBeEqualTo true
23+
hasTextStartingWith("Other") shouldBeEqualTo false
24+
hasTextEndingWith("testdata.SampleClass") shouldBeEqualTo true
25+
hasTextEndingWith("other") shouldBeEqualTo false
26+
hasTextContaining(".konsist.testdata.") shouldBeEqualTo true
27+
hasTextContaining("anno") shouldBeEqualTo false
28+
hasTextMatching(Regex("^[^@]*\$")) shouldBeEqualTo true
29+
hasTextMatching(Regex("[0-9]+")) shouldBeEqualTo false
30+
}
1831
}
1932

2033
private fun getSnippetFile(fileName: String) = getSnippetKoScope("core/declaration/koimport/snippet/forkotextprovider/", fileName)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import com.lemonappdev.konsist.testdata.SampleClass
2+
3+
class SampleTopLevelClass(val sampleProperty2: SampleClass)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import com.lemonappdev.konsist.testdata.SampleClass
2+
3+
class SampleTopLevelClass(val sampleProperty2: SampleClass)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import com.lemonappdev.konsist.testdata.SampleClass
2+
3+
class SampleTopLevelClass(val sampleProperty2: SampleClass)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import com.lemonappdev.konsist.testdata.SampleClass
2+
3+
class SampleTopLevelClass(val sampleProperty2: SampleClass)

0 commit comments

Comments
 (0)