TEST_F(ParserTests_Types, GlobalUntyped) { ASTNode* node = this->parseNode("value\n"); node = node->childAtIndex(0); ASSERT_EQ("Variable Declaration", node->nodeName()); ASSERT_EQ("value", node->name()); ASSERT_EQ(DataType::Undefined, node->dataType().kind()); }
TEST_F(ParserTests_Types, GlobalMutableBoolean) { ASTNode* node = this->parseNode("Bool! value\n"); node = node->childAtIndex(0); ASSERT_EQ("Variable Declaration", node->nodeName()); ASSERT_EQ("value", node->name()); EXPECT_EQ(DataType::Boolean, node->dataType().kind()); EXPECT_EQ(DataType::Access::ReadWrite, node->dataType().access()); }
TEST_F(ParserTests_Types, GlobalFunction) { ASTNode* node = this->parseNode("() -> Void value\n"); node = node->childAtIndex(0); ASSERT_EQ("value", node->name()); ASSERT_EQ(DataType::Function, node->dataType().kind()); ASSERT_EQ(0, node->dataType().subtypeCount()); ASSERT_EQ(0, node->dataType().parameterCount()); ASSERT_EQ(DataType::Void, node->dataType().returnType().kind()); }
TEST_F(ParserTests_Types, GlobalOptionalMutableBooleanPointer) { ASTNode* node = this->parseNode("Bool!? value\n"); node = node->childAtIndex(0); ASSERT_EQ("Variable Declaration", node->nodeName()); ASSERT_EQ("value", node->name()); EXPECT_EQ(DataType::NullablePointer, node->dataType().kind()); EXPECT_EQ(DataType::Access::Read, node->dataType().access()); ASSERT_EQ(1, node->dataType().subtypeCount()); EXPECT_EQ(DataType::Boolean, node->dataType().subtypeAtIndex(0).kind()); EXPECT_EQ(DataType::Access::ReadWrite, node->dataType().subtypeAtIndex(0).access()); }
TEST_F(ParserTests_Atomics, AtomicStatementWithFallbackFunctions) { ASTNode* node = this->parseNodeWithBodies("def fn_1(*Void ptr) -> Bool\n" " return true\n" "end\n" "def fn_2(*Void ptr) -> Bool\n" " return true\n" "end\n" "def test(*Void ptr)\n" " atomic:fallback(fn_1, fn_2, ptr)\n" " abort\n" " end\n" "end\n"); ASSERT_EQ(3, node->childCount()); node = node->childAtIndex(2); ASSERT_EQ("Function Definition", node->nodeName()); ASSERT_EQ(1, node->childCount()); node = node->childAtIndex(0); ASSERT_EQ("Atomic Statement", node->nodeName()); auto atomicNode = dynamic_cast<AtomicStatementNode*>(node); node = atomicNode->lockFunction(); ASSERT_TRUE(node != nullptr); ASSERT_EQ("Function Variable", node->nodeName()); ASSERT_EQ("fn_1", node->name()); node = atomicNode->unlockFunction(); ASSERT_TRUE(node != nullptr); ASSERT_EQ("Function Variable", node->nodeName()); ASSERT_EQ("fn_2", node->name()); node = atomicNode->lockContext(); ASSERT_TRUE(node != nullptr); ASSERT_EQ("Local Variable", node->nodeName()); ASSERT_EQ("ptr", node->name()); }
TEST_F(ParserTests_Types, GlobalClosure) { ASTNode* node = this->parseNode("{} -> Void value\n"); node = node->childAtIndex(0); ASSERT_EQ("value", node->name()); ASSERT_EQ(DataType::Closure, node->dataType().kind()); ASSERT_EQ(0, node->dataType().subtypeCount()); ASSERT_EQ(1, node->dataType().parameterCount()); ASSERT_EQ(DataType::Kind::Pointer, node->dataType().parameterAtIndex(0).kind()); ASSERT_EQ(1, node->dataType().parameterAtIndex(0).subtypeCount()); ASSERT_EQ(DataType::Kind::Void, node->dataType().parameterAtIndex(0).subtypeAtIndex(0).kind()); ASSERT_EQ(DataType::Void, node->dataType().returnType().kind()); }