Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions source/fluentasserts/results/source/scopes.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ auto getScope(const(Token)[] tokens, size_t line) nothrow {
}

if (foundScope) {
if (token.text == "should" || token.text == "Assert" || type == "assert" || type == ";") {
if (!foundAssert && (token.text == "should" || token.text == "Assert" || type == "assert" || type == ";")) {
foundAssert = true;
scopeLevel = paranthesisCount;
}

if (type == "}" && paranthesisCount <= scopeLevel) {
if (foundAssert && type == "}" && paranthesisCount < scopeLevel) {
beginToken = paranthesisLevels[paranthesisCount];
endToken = i + 1;

Expand Down Expand Up @@ -112,3 +112,19 @@ unittest {

}`);
}

@("getScope returns full parent scope when it contains other nested blocks")
unittest {
const(Token)[] tokens = [];
splitMultilinetokens(fileToDTokens("testdata/values.d"), tokens);

auto result = getScope(tokens, 120);
auto identifierStart = getPreviousIdentifier(tokens, result.begin);

tokens[identifierStart .. result.end].tokensToString.strip.should.equal(`unittest {
auto a = 1;
a.shoud.equal(1);
receive(2.seconds, (int m) { m.should.equal(1); });

}`);
}
6 changes: 6 additions & 0 deletions testdata/values.d
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ unittest {
a.should.equal(2);
}
}

unittest {
auto a = 1;
a.shoud.equal(1);
receive(2.seconds, (int m) { m.should.equal(1); });
}