blob: 3f5dbe331d81f6325e2df59e4f43a5f42b622628 [file] [log] [blame]
dan sinclairec007b92020-07-29 18:56:35 +00001// Copyright 2020 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <memory>
16
dan sinclairec007b92020-07-29 18:56:35 +000017#include "src/ast/array_accessor_expression.h"
18#include "src/ast/identifier_expression.h"
19#include "src/ast/module.h"
20#include "src/ast/scalar_constructor_expression.h"
21#include "src/ast/sint_literal.h"
22#include "src/ast/type/i32_type.h"
dan sinclairdf503f02020-08-26 19:05:46 +000023#include "src/writer/hlsl/test_helper.h"
dan sinclairec007b92020-07-29 18:56:35 +000024
25namespace tint {
26namespace writer {
27namespace hlsl {
28namespace {
29
dan sinclair63b007d2020-08-26 20:02:26 +000030using HlslGeneratorImplTest_Expression = TestHelper;
dan sinclairec007b92020-07-29 18:56:35 +000031
dan sinclairdf503f02020-08-26 19:05:46 +000032TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
dan sinclair8b40a672020-12-16 11:49:10 +000033 auto* expr = IndexAccessor("ary", 5);
dan sinclairec007b92020-07-29 18:56:35 +000034
Ben Clayton9df857d2020-12-15 14:11:48 +000035 ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
dan sinclairf4bc0e72021-01-11 16:24:32 +000036 EXPECT_EQ(result(), "test_ary[5]");
dan sinclairec007b92020-07-29 18:56:35 +000037}
38
dan sinclairdf503f02020-08-26 19:05:46 +000039TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
dan sinclair8b40a672020-12-16 11:49:10 +000040 auto* expr = IndexAccessor("ary", "idx");
dan sinclairec007b92020-07-29 18:56:35 +000041
Ben Clayton9df857d2020-12-15 14:11:48 +000042 ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
dan sinclairf4bc0e72021-01-11 16:24:32 +000043 EXPECT_EQ(result(), "test_ary[test_idx]");
dan sinclairec007b92020-07-29 18:56:35 +000044}
45
46} // namespace
47} // namespace hlsl
48} // namespace writer
49} // namespace tint