@@ -29,17 +29,29 @@ class SnippetTest {
29
29
val snippetMap = mutableMapOf<String , String >()
30
30
snippetNames.forEachIndexed { index, s -> snippetMap[s] = snippetPaths[index] }
31
31
32
- val r1 = Regex (""" getSnippetFile\(\s*"(.+)"""" )
33
- val r2 = Regex (""" arguments\(\s*"([^"]+)"""" )
34
- val r3 = Regex (""" arguments\(\s*"([^"]+)"""" )
35
- val withGetSnippetMethod = snippetNamesFromFiles(r1, " getSnippetFile(" )
36
- val withArgument = snippetNamesFromFiles(r2, " arguments(" ) + snippetNamesFromFiles(r3, " arguments(\n " )
32
+ /*
33
+ Matches calls to the `getSnippetFile` function, capturing the argument passed to it.
34
+ It accounts for any spaces between the function name and the opening parenthesis,
35
+ and captures the entire argument as a string enclosed in quotes e.g. `getSnippetFile("snippetName")`
36
+ */
37
+ val getSnippetFileRegex = Regex (""" getSnippetFile\(\s*"(.+)"""" )
38
+
39
+ /*
40
+ This regex matches calls to the `arguments` function, capturing the argument passed to it.
41
+ It allows for spaces between the function name and the opening parenthesis,
42
+ and captures the argument as a string within quotes e.g. `arguments("snippetName")`
43
+ */
44
+ val argumentsRegex = Regex (""" arguments\(\s*"([^"]+)"""" )
45
+
46
+ val withGetSnippetMethod = snippetNamesFromFiles(getSnippetFileRegex, " getSnippetFile(" )
47
+ val withArgument = snippetNamesFromFiles(argumentsRegex, " arguments(" )
37
48
38
49
val snippetNamesUsedInTests = (withGetSnippetMethod + withArgument).toSet()
39
50
40
- // then
51
+ // when
41
52
val sut = snippetMap.keys.toSet() - snippetNamesUsedInTests
42
53
54
+ // then
43
55
assertSoftly {
44
56
sut shouldBeEqualTo emptySet()
45
57
require(sut.isEmpty()) { " Unused snippets: ${sut.map { snippetMap[it] }} " }
0 commit comments