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, 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()); }