Debian Codegraph @

llvm-project/mlir/unittests/IR/SubElementInterfaceTest.cpp

raw
1 //===- SubElementInterfaceTest.cpp - SubElementInterface unit tests -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "mlir/IR/Builders.h"
10 #include "mlir/IR/BuiltinAttributes.h"
11 #include "mlir/IR/SubElementInterfaces.h"
12 #include "gtest/gtest.h"
13 #include <cstdint>
14
15 using namespace mlir;
16 using namespace mlir::detail;
17
18 namespace {
19 TEST(SubElementInterfaceTest, Nested) {
20 MLIRContext context;
21 Builder builder(&context);
22
23 BoolAttr trueAttr = builder.getBoolAttr(true);
24 BoolAttr falseAttr = builder.getBoolAttr(false);
25 ArrayAttr boolArrayAttr = builder.getArrayAttr({trueAttr, falseAttr});
26 StringAttr strAttr = builder.getStringAttr("array");
27 DictionaryAttr dictAttr =
28 builder.getDictionaryAttr(builder.getNamedAttr(strAttr, boolArrayAttr));
29
30 SmallVector<Attribute> subAttrs;
31 dictAttr.walkSubAttrs([&](Attribute attr) { subAttrs.push_back(attr); });
32 EXPECT_EQ(llvm::ArrayRef(subAttrs),
33 ArrayRef<Attribute>({strAttr, trueAttr, falseAttr, boolArrayAttr}));
34 }
35
36 } // namespace