dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 1 | // 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 sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 17 | #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 sinclair | df503f0 | 2020-08-26 19:05:46 +0000 | [diff] [blame] | 23 | #include "src/writer/hlsl/test_helper.h" |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 24 | |
| 25 | namespace tint { |
| 26 | namespace writer { |
| 27 | namespace hlsl { |
| 28 | namespace { |
| 29 | |
dan sinclair | 63b007d | 2020-08-26 20:02:26 +0000 | [diff] [blame] | 30 | using HlslGeneratorImplTest_Expression = TestHelper; |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 31 | |
dan sinclair | df503f0 | 2020-08-26 19:05:46 +0000 | [diff] [blame] | 32 | TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) { |
dan sinclair | 8b40a67 | 2020-12-16 11:49:10 +0000 | [diff] [blame] | 33 | auto* expr = IndexAccessor("ary", 5); |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 34 | |
Ben Clayton | 9df857d | 2020-12-15 14:11:48 +0000 | [diff] [blame] | 35 | ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); |
dan sinclair | f4bc0e7 | 2021-01-11 16:24:32 +0000 | [diff] [blame] | 36 | EXPECT_EQ(result(), "test_ary[5]"); |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 37 | } |
| 38 | |
dan sinclair | df503f0 | 2020-08-26 19:05:46 +0000 | [diff] [blame] | 39 | TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) { |
dan sinclair | 8b40a67 | 2020-12-16 11:49:10 +0000 | [diff] [blame] | 40 | auto* expr = IndexAccessor("ary", "idx"); |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 41 | |
Ben Clayton | 9df857d | 2020-12-15 14:11:48 +0000 | [diff] [blame] | 42 | ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error(); |
dan sinclair | f4bc0e7 | 2021-01-11 16:24:32 +0000 | [diff] [blame] | 43 | EXPECT_EQ(result(), "test_ary[test_idx]"); |
dan sinclair | ec007b9 | 2020-07-29 18:56:35 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | } // namespace hlsl |
| 48 | } // namespace writer |
| 49 | } // namespace tint |