Skip to content

Commit 3868484

Browse files
committed
move code block search to a separate function
1 parent 1472309 commit 3868484

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

dspec_tester.d

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,24 @@ unittest
7171
assert("aa $(foo $(bar)foobar)".untilClosingParentheses.equal("aa $(foo $(bar)foobar)"));
7272
}
7373

74-
auto findDdocMacro(string text, string ddocKey)
74+
auto findDdocMacro(R)(R text, string ddocKey)
7575
{
7676
return text.splitter(ddocKey).map!untilClosingParentheses.dropOne;
7777
}
7878

79+
auto ddocMacroToCode(R)(R text)
80+
{
81+
import std.ascii : newline;
82+
import std.conv : to;
83+
return text.find("---")
84+
.findSplitAfter(newline)[1]
85+
.findSplitBefore("---")[0]
86+
.to!string;
87+
}
88+
7989
int main(string[] args)
8090
{
81-
import std.conv, std.file, std.getopt, std.path;
91+
import std.file, std.getopt, std.path;
8292
import std.parallelism : parallel;
8393
import std.process : environment;
8494

@@ -102,17 +112,12 @@ int main(string[] args)
102112
// Find all examples in the specification
103113
foreach (file; specDir.dirEntries("*.dd", SpanMode.depth).parallel(1))
104114
{
105-
import std.ascii : newline;
106115
import std.uni : isWhite;
107116
auto allTests =
108117
file
109118
.readText
110119
.findDdocMacro("$(SPEC_RUNNABLE_EXAMPLE")
111-
.map!(a => a
112-
.find("---")
113-
.findSplitAfter(newline)[1]
114-
.findSplitBefore("---")[0]
115-
.to!string)
120+
.map!ddocMacroToCode
116121
.map!compileAndCheck;
117122

118123
if (!allTests.empty)

0 commit comments

Comments
 (0)