[validation] unittest v-0015: runtime array may only appear last in a structs
this CL adds disabled tests to validate v-0015.
Bug: tint:345
Change-Id: I39ec9bc3b44f8f9c9fe241d3492de66509722e4c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33260
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 99e5636..56cda30 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -416,6 +416,7 @@
validator/validator_control_block_test.cc
validator/validator_function_test.cc
validator/validator_test.cc
+ validator/validator_type_test.cc
)
## Tint library
diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc
new file mode 100644
index 0000000..3773738
--- /dev/null
+++ b/src/validator/validator_type_test.cc
@@ -0,0 +1,87 @@
+// Copyright 2020 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "gtest/gtest.h"
+#include "src/ast/array_accessor_expression.h"
+#include "src/ast/struct.h"
+#include "src/ast/struct_member.h"
+#include "src/ast/struct_member_decoration.h"
+#include "src/ast/type/array_type.h"
+#include "src/ast/type/f32_type.h"
+#include "src/ast/type/struct_type.h"
+#include "src/ast/type_constructor_expression.h"
+#include "src/validator/validator_impl.h"
+#include "src/validator/validator_test_helper.h"
+
+namespace tint {
+namespace {
+
+class ValidatorTypeTest : public ValidatorTestHelper, public testing::Test {};
+
+TEST_F(ValidatorTypeTest, RuntimeArrayIsLast_Pass) {
+ // struct Foo {
+ // vf: f32;
+ // rt: array<f32>;
+ // };
+
+ ast::type::F32Type f32;
+ ast::type::ArrayType arr(&f32);
+ ast::StructMemberList members;
+ {
+ ast::StructMemberDecorationList deco;
+ members.push_back(create<ast::StructMember>("vf", &f32, deco));
+ }
+ {
+ ast::StructMemberDecorationList deco;
+ members.push_back(create<ast::StructMember>(
+ Source{Source::Location{12, 34}}, "rt", &arr, deco));
+ }
+ ast::StructDecorationList decos;
+ auto* st = create<ast::Struct>(decos, members);
+ ast::type::StructType struct_type("Foo", st);
+
+ // mod()->AddConstructedType(&struct_type);
+ // EXPECT_TRUE(v()->ValidateConstructedTypes(mod()->constructed_types()));
+}
+
+TEST_F(ValidatorTypeTest, DISABLED_RuntimeArrayIsNotLast_Fail) {
+ // struct Foo {
+ // rt: array<f32>;
+ // vf: f32;
+ // };
+
+ ast::type::F32Type f32;
+ ast::type::ArrayType arr(&f32);
+ ast::StructMemberList members;
+ {
+ ast::StructMemberDecorationList deco;
+ members.push_back(create<ast::StructMember>(
+ Source{Source::Location{12, 34}}, "rt", &arr, deco));
+ }
+ {
+ ast::StructMemberDecorationList deco;
+ members.push_back(create<ast::StructMember>("vf", &f32, deco));
+ }
+ ast::StructDecorationList decos;
+ auto* st = create<ast::Struct>(decos, members);
+ ast::type::StructType struct_type("Foo", st);
+
+ mod()->AddConstructedType(&struct_type);
+ // EXPECT_FALSE(v()->ValidateConstructedTypes(mod()->constructed_types()));
+ // EXPECT_EQ(v()->error(),
+ // "12:34: v-0015: runtime arrays may only appear as the last member
+ // " "of a struct: 'rt'");
+}
+} // namespace
+} // namespace tint