dawn-cmake/src/writer/wgsl/generator_impl_variable_test.cc
James Price 42f8999af5 writer/wgsl: Ensure that test programs are valid
Make all test programs valid.

Change-Id: Id7eb790519e3dec30a5b826f06585d277995b9b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50720
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-12 10:06:21 +00:00

99 lines
2.7 KiB
C++

// 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 "src/ast/override_decoration.h"
#include "src/writer/wgsl/test_helper.h"
namespace tint {
namespace writer {
namespace wgsl {
namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, EmitVariable) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(gen.result(), R"(var<private> a : f32;
)");
}
TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(gen.result(), R"(var<private> a : f32;
)");
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
ast::DecorationList{
Location(2),
});
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(gen.result(), R"([[location(2)]] var<private> a : f32;
)");
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
ast::DecorationList{
Builtin(ast::Builtin::kPosition),
Location(2),
});
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(
gen.result(),
R"([[builtin(position), location(2)]] var<private> a : f32;
)");
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, Expr(1.0f));
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(gen.result(), R"(var<private> a : f32 = 1.0;
)");
}
TEST_F(WgslGeneratorImplTest, EmitVariable_Const) {
auto* v = Const("a", ty.f32(), Expr(1.0f));
WrapInFunction(Decl(v));
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitVariable(v)) << gen.error();
EXPECT_EQ(gen.result(), R"(let a : f32 = 1.0;
)");
}
} // namespace
} // namespace wgsl
} // namespace writer
} // namespace tint