TEST(TestProtocol, testPropertyRequirements) { PARSE_STATEMENT(L"protocol SomeProtocol {\n" L"var mustBeSettable: Int { get set }\n" L"var doesNotNeedToBeSettable: Int { get }\n" L"}"); ProtocolDefPtr p; ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root)); ASSERT_EQ(2, p->numDeclarations()); ComputedPropertyPtr var; ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0))); ASSERT_EQ(L"mustBeSettable", var->getName()); ASSERT_EQ(0, var->getModifiers()); ASSERT_NOT_NULL(var->getGetter()); ASSERT_NOT_NULL(var->getSetter()); ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(1))); ASSERT_EQ(L"doesNotNeedToBeSettable", var->getName()); ASSERT_NOT_NULL(var->getGetter()); ASSERT_NULL(var->getSetter()); }
TEST(TestProtocol, testOptional) { PARSE_STATEMENT(L"@objc protocol CounterDataSource {\n" L"optional func incrementForCount(count: Int) -> Int\n" L"optional var fixedIncrement: Int { get }\n" L"}"); ProtocolDefPtr p; ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root)); ASSERT_EQ(2, p->numDeclarations()); ASSERT_NOT_NULL(p->getAttribute(L"objc")); FunctionDefPtr f; ASSERT_NOT_NULL(f = std::dynamic_pointer_cast<FunctionDef>(p->getDeclaration(0))); ASSERT_EQ(L"incrementForCount", f->getName()); ASSERT_TRUE(f->getModifiers() & DeclarationModifiers::Optional); ComputedPropertyPtr var; ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(1))); ASSERT_TRUE(f->getModifiers() & DeclarationModifiers::Optional); ASSERT_EQ(L"fixedIncrement", var->getName()); ASSERT_NOT_NULL(var->getGetter()); ASSERT_NULL(var->getSetter()); }
TEST(TestProtocol, testPropertyRequirements2) { PARSE_STATEMENT(L"protocol AnotherProtocol {\n" L"class var someTypeProperty: Int { get set }\n" L"}"); ProtocolDefPtr p; ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root)); ASSERT_EQ(1, p->numDeclarations()); ComputedPropertyPtr var; ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0))); ASSERT_EQ((int)DeclarationModifiers::Class, var->getModifiers()); ASSERT_EQ(L"someTypeProperty", var->getName()); ASSERT_NOT_NULL(var->getGetter()); ASSERT_NOT_NULL(var->getSetter()); }
TEST(TestProtocol, testPropertyRequirements3) { PARSE_STATEMENT(L"protocol FullyNamed {\n" L"var fullName: String { get }\n" L"}"); ProtocolDefPtr p; ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root)); ASSERT_EQ(1, p->numDeclarations()); ComputedPropertyPtr var; ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0))); ASSERT_EQ(0, var->getModifiers()); ASSERT_EQ(L"fullName", var->getName()); ASSERT_NOT_NULL(var->getGetter()); ASSERT_NULL(var->getSetter()); }