getFunctionEnd

Undocumented in source. Be warned that the author may not have intended to support it.
@safe
size_t
getFunctionEnd
(
const(Token)[] tokens
,
size_t start
)

Examples

Get the end of a spec function with a lambda

const(Token)[] tokens = [];
splitMultilinetokens(fileToDTokens("test/values.d"), tokens);

auto result = getScope(tokens, 101);
auto identifierStart = getPreviousIdentifier(tokens, result.begin);
auto functionEnd = getFunctionEnd(tokens, identifierStart);

tokens[identifierStart .. functionEnd].toString.strip.should.equal("it(\"should throw an exception if we request 2 android devices\", {
    ({
      auto result = [ device1.idup, device2.idup ].filterBy(RunOptions(\"\", \"android\", 2)).array;
    }).should.throwException!DeviceException.withMessage.equal(\"You requested 2 `androdid` devices, but there is only 1 healthy.\");
  })");

Get the end of an unittest function with a lambda

  const(Token)[] tokens = [];
  splitMultilinetokens(fileToDTokens("test/values.d"), tokens);

  auto result = getScope(tokens, 81);
  auto identifierStart = getPreviousIdentifier(tokens, result.begin);
  auto functionEnd = getFunctionEnd(tokens, identifierStart) + 1;

  tokens[identifierStart .. functionEnd].toString.strip.should.equal("unittest {
  ({
    ({ }).should.beNull;
  }).should.throwException!TestException.msg;

}");

Get tokens from a scope that contains a lambda

  const(Token)[] tokens = [];
  splitMultilinetokens(fileToDTokens("test/values.d"), tokens);

  auto result = getScope(tokens, 81);

  tokens[result.begin .. result.end].toString.strip.should.equal(`{
  ({
    ({ }).should.beNull;
  }).should.throwException!TestException.msg;

}`);

Meta