|
| 1 | +//===--- ASTDumperTests.cpp - Tests for ASTDumper -----------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "TestContext.h" |
| 14 | +#include "swift/AST/ASTContext.h" |
| 15 | +#include "swift/AST/GenericSignature.h" |
| 16 | +#include "swift/AST/Types.h" |
| 17 | +#include "llvm/ADT/StringRef.h" |
| 18 | +#include "llvm/Support/raw_ostream.h" |
| 19 | +#include "gtest/gtest.h" |
| 20 | +#include <string> |
| 21 | + |
| 22 | +using namespace swift; |
| 23 | +using namespace swift::unittest; |
| 24 | + |
| 25 | +TEST(ASTDumper, ArchetypeType) { |
| 26 | + TestContext C; |
| 27 | + auto &ctx = C.Ctx; |
| 28 | + |
| 29 | + auto *genericParamTy = GenericTypeParamType::get(false, 0, 0, ctx); |
| 30 | + auto sig = buildGenericSignature(ctx, nullptr, {genericParamTy}, {}); |
| 31 | + |
| 32 | + TypeBase *archetype = nullptr; |
| 33 | + { |
| 34 | + llvm::SmallVector<ProtocolDecl *> protocols; |
| 35 | + archetype = PrimaryArchetypeType::getNew(ctx, sig.getGenericEnvironment(), |
| 36 | + genericParamTy, protocols, Type(), |
| 37 | + nullptr); |
| 38 | + } |
| 39 | + |
| 40 | + std::string fullStr; |
| 41 | + { |
| 42 | + llvm::raw_string_ostream os(fullStr); |
| 43 | + archetype->dump(os); |
| 44 | + } |
| 45 | + |
| 46 | + llvm::StringRef str(fullStr); |
| 47 | + EXPECT_TRUE(str.consume_front("(primary_archetype_type address=0x")); |
| 48 | + { |
| 49 | + intptr_t integer; |
| 50 | + EXPECT_FALSE(str.consumeInteger(16, integer)); |
| 51 | + } |
| 52 | + |
| 53 | + EXPECT_EQ(str, |
| 54 | + " name=\"\\xCF\\x84_0_0\"\n" |
| 55 | + " (interface_type=generic_type_param_type depth=0 index=0))\n"); |
| 56 | +} |
0 commit comments