TEST_F(TypeParserTests, ClosureWithTupleReturn) { this->setInput("{} -> (Int, Int) a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Kind::Closure, type.kind()); ASSERT_EQ(0, type.subtypeCount()); ASSERT_EQ(DataType::Kind::Tuple, type.returnType().kind()); ASSERT_EQ(2, type.returnType().subtypeCount()); ASSERT_EQ("a", this->peek().str()); }
TEST_F(TypeParserTests, ClosureWithNonVoidReturn) { this->setInput("{} -> Int a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Kind::Closure, type.kind()); ASSERT_EQ(0, type.subtypeCount()); ASSERT_EQ(DataType::Kind::Integer, type.returnType().kind()); ASSERT_EQ("a", this->peek().str()); }
TEST_F(TypeParserTests, Function) { this->setInput("() -> Void a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Function, type.kind()); ASSERT_EQ(0, type.subtypeCount()); ASSERT_EQ(DataType::Kind::Void, type.returnType().kind()); ASSERT_EQ("a", this->peek().str()); }
TEST_F(TypeParserTests, ClosureWithOneParam) { this->setInput("{Int} -> Void a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Kind::Closure, type.kind()); ASSERT_EQ(0, type.subtypeCount()); ASSERT_EQ(2, type.parameterCount()); ASSERT_EQ(DataType::Integer, type.parameterAtIndex(1).kind()); ASSERT_EQ(DataType::Kind::Void, type.returnType().kind()); ASSERT_EQ("a", this->peek().str()); }
TEST_F(TypeParserTests, FunctionWithOnePointerParam) { this->setInput("(*Int) -> Void a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Function, type.kind()); ASSERT_EQ(1, type.parameterCount()); ASSERT_EQ(DataType::Pointer, type.parameterAtIndex(0).kind()); ASSERT_EQ(DataType::Integer, type.parameterAtIndex(0).subtypeAtIndex(0).kind()); ASSERT_EQ(DataType::Kind::Void, type.returnType().kind()); ASSERT_EQ("a", this->peek().str()); }
TEST_F(TypeParserTests, FunctionWithTwoParams) { this->setInput("(Int, Float) -> Void a\n"); DataType type = this->typeParser()->parseType(); ASSERT_EQ(DataType::Function, type.kind()); ASSERT_EQ(2, type.parameterCount()); ASSERT_EQ(DataType::Integer, type.parameterAtIndex(0).kind()); ASSERT_EQ(DataType::Float, type.parameterAtIndex(1).kind()); ASSERT_EQ(DataType::Kind::Void, type.returnType().kind()); ASSERT_EQ("a", this->peek().str()); }