Ejemplo n.º 1
0
TEST(TestDeclaration, testLet)
{
    PARSE_STATEMENT(L"let a : Int[] = [1, 2, 3]");
    ValueBindingsPtr c;
    IdentifierPtr id;
    ValueBindingPtr a;
    ArrayLiteralPtr value;
    ArrayTypePtr type;
    TypeIdentifierPtr Int;
    ASSERT_NOT_NULL(c = std::dynamic_pointer_cast<ValueBindings>(root));
    ASSERT_TRUE(c->isReadOnly());
    ASSERT_EQ(1, c->numBindings());
    ASSERT_NOT_NULL(a = c->get(0));
    ASSERT_NOT_NULL(id = std::dynamic_pointer_cast<Identifier>(a->getName()));
    ASSERT_EQ(L"a", id->getIdentifier());
    ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<ArrayType>(a->getDeclaredType()));
    ASSERT_NOT_NULL(Int = std::dynamic_pointer_cast<TypeIdentifier>(type->getInnerType()));
    ASSERT_EQ(L"Int", Int->getName());

    ASSERT_NOT_NULL(value = std::dynamic_pointer_cast<ArrayLiteral>(c->get(0)->getInitializer()));
    ASSERT_EQ(3, value->numElements());
    ASSERT_EQ(L"1", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(0))->valueAsString);
    ASSERT_EQ(L"2", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(1))->valueAsString);
    ASSERT_EQ(L"3", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(2))->valueAsString);

}
Ejemplo n.º 2
0
TEST(TestLiteralExpression, testArrayLiteral4)
{
    PARSE_STATEMENT(L"[5,6]");
    ASSERT_NOT_NULL(root);
    ArrayLiteralPtr a = std::dynamic_pointer_cast<ArrayLiteral>(root);
    ASSERT_NOT_NULL(a);
    ASSERT_EQ(2, a->numElements());

}
Ejemplo n.º 3
0
TEST(TestLiteralExpression, testArrayLiteral3)
{
    PARSE_STATEMENT(L"[\"a\",]");
    ASSERT_NOT_NULL(root);
    ArrayLiteralPtr a = std::dynamic_pointer_cast<ArrayLiteral>(root);
    ASSERT_NOT_NULL(a);
    ASSERT_EQ(1, a->numElements());
    StringLiteralPtr s = std::dynamic_pointer_cast<StringLiteral>(a->getElement(0));
    ASSERT_NOT_NULL(s);
    ASSERT_EQ(L"a", s->value);

}
Ejemplo n.º 4
0
TEST(TestLiteralExpression, testArrayLiteral2)
{
    PARSE_STATEMENT(L"[5]");
    ASSERT_NOT_NULL(root);
    ArrayLiteralPtr a = std::dynamic_pointer_cast<ArrayLiteral>(root);
    ASSERT_NOT_NULL(a);
    ASSERT_EQ(1, a->numElements());
    IntegerLiteralPtr i = std::dynamic_pointer_cast<IntegerLiteral>(a->getElement(0));
    ASSERT_NOT_NULL(i);
    ASSERT_EQ(L"5", i->valueAsString);


}