Skip to content

Commit 93cc467

Browse files
committed
fix: clamp begin for lambda and if block in SourceResult tests
1 parent fc7735c commit 93cc467

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

source/fluentasserts/results/source/result.d

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct SourceResult {
7272
auto result = getScope(fileTokensCache[pathToUse], line);
7373

7474
auto begin = getPreviousIdentifier(fileTokensCache[pathToUse], result.begin);
75+
begin = max(begin, result.begin);
7576
begin = extendToLineStart(fileTokensCache[pathToUse], begin);
7677
auto end = getFunctionEnd(fileTokensCache[pathToUse], begin) + 1;
7778

@@ -226,3 +227,28 @@ struct SourceResult {
226227
printer.primary("\n");
227228
}
228229
}
230+
231+
version(unittest) {
232+
import fluent.asserts;
233+
import fluentasserts.results.source.tokens;
234+
}
235+
236+
@("ensureTokensLoaded clamps begin for lambda inside map")
237+
unittest {
238+
auto source = SourceResult.create("testdata/values.d", 108);
239+
auto toks = source.tokens;
240+
auto output = source.toString();
241+
242+
output.should.not.contain("auto a = 1");
243+
output.should.contain("iota");
244+
}
245+
246+
@("ensureTokensLoaded clamps begin for if block")
247+
unittest {
248+
auto source = SourceResult.create("testdata/values.d", 114);
249+
auto toks = source.tokens;
250+
auto output = source.toString();
251+
252+
output.should.not.contain("auto a = 1");
253+
output.should.contain("if");
254+
}

testdata/values.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,15 @@ unittest {
102102
});
103103
});
104104
}
105+
106+
unittest {
107+
auto a = 1;
108+
iota(1).map!((a) { a.should.equal(2); return a + 1; }).array;
109+
}
110+
111+
unittest {
112+
auto a = 1;
113+
if (a == 1) {
114+
a.should.equal(2);
115+
}
116+
}

0 commit comments

Comments
 (0)