diff --git a/source/fluentasserts/results/source/scopes.d b/source/fluentasserts/results/source/scopes.d index 40f5178..e332a0c 100644 --- a/source/fluentasserts/results/source/scopes.d +++ b/source/fluentasserts/results/source/scopes.d @@ -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; @@ -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); }); + +}`); +} diff --git a/testdata/values.d b/testdata/values.d index 02d050d..bc94775 100644 --- a/testdata/values.d +++ b/testdata/values.d @@ -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); }); +}