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 DictionaryAttr dictAttr = 27 builder.getDictionaryAttr(builder.getNamedAttr("array", boolArrayAttr)); 28 29 SmallVector<Attribute> subAttrs; 30 dictAttr.walkSubAttrs([&](Attribute attr) { subAttrs.push_back(attr); }); 31 EXPECT_EQ(llvm::makeArrayRef(subAttrs), 32 ArrayRef<Attribute>({trueAttr, falseAttr, boolArrayAttr})); 33 } 34 35 } // namespace 36