TEST(TestFunc, testFunc) { PARSE_STATEMENT(L"func stepForward(input: Int) -> Int {" L"return input + 1" L"}"); FunctionDefPtr func; ParametersNodePtr params; ParameterNodePtr param; TypeIdentifierPtr type; CodeBlockPtr cb; ReturnStatementPtr ret; BinaryOperatorPtr add; IdentifierPtr id; IntegerLiteralPtr i; ASSERT_NOT_NULL(func = std::dynamic_pointer_cast<FunctionDef>(root)); ASSERT_EQ(L"stepForward", func->getName()); ASSERT_EQ(1, func->numParameters()); ASSERT_NOT_NULL(params = func->getParameters(0)); ASSERT_EQ(1, params->numParameters()); ASSERT_NOT_NULL(param = params->getParameter(0)); ASSERT_EQ(ParameterNode::None, param->getAccessibility()); ASSERT_FALSE(param->isShorthandExternalName()); ASSERT_FALSE(param->isInout()); ASSERT_NULL(param->getDefaultValue()); ASSERT_EQ(L"", param->getExternalName()); ASSERT_EQ(L"input", param->getLocalName()); ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<TypeIdentifier>(param->getDeclaredType())); ASSERT_EQ(L"Int", type->getName()); ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<TypeIdentifier>(func->getReturnType())); ASSERT_EQ(L"Int", type->getName()); ASSERT_NOT_NULL(cb = func->getBody()); ASSERT_EQ(1, cb->numStatements()); ASSERT_NOT_NULL(ret = std::dynamic_pointer_cast<ReturnStatement>(cb->getStatement(0))); ASSERT_NOT_NULL(add = std::dynamic_pointer_cast<BinaryOperator>(ret->getExpression())); ASSERT_EQ(L"+", add->getOperator()); ASSERT_NOT_NULL(id = std::dynamic_pointer_cast<Identifier>(add->getLHS())); ASSERT_NOT_NULL(i = std::dynamic_pointer_cast<IntegerLiteral>(add->getRHS())); ASSERT_EQ(L"input", id->getIdentifier()); ASSERT_EQ(L"1", i->valueAsString); }