-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathConstraintSystemDumpTests.cpp
70 lines (58 loc) · 2.28 KB
/
ConstraintSystemDumpTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//===--- ConstraintSystemDumpTests.cpp ------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "SemaFixture.h"
#include "swift/Sema/ConstraintSystem.h"
using namespace swift;
using namespace swift::unittest;
TEST_F(SemaTest, DumpConstraintSystemBasic) {
ConstraintSystemOptions options;
ConstraintSystem cs(DC, options);
auto *emptyLoc = cs.getConstraintLocator({});
auto *t0 = cs.createTypeVariable(emptyLoc, TVO_CanBindToLValue);
auto *t1 = cs.createTypeVariable(emptyLoc, 0);
auto *t2 = cs.createTypeVariable(
cs.getConstraintLocator(emptyLoc, ConstraintLocator::GenericArgument),
TVO_CanBindToHole | TVO_CanBindToPack);
cs.addUnsolvedConstraint(Constraint::create(
cs, ConstraintKind::Bind, t2,
TupleType::get({Type(t0), Type(t1)}, Context), emptyLoc));
std::string expectedOutput =
R"(Score: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>
Type Variables:
$T0 [can bind to: lvalue] [adjacent to: $T1, $T2] [potential bindings: <none>] @ locator@ []
$T1 [adjacent to: $T0, $T2] [potential bindings: <none>] @ locator@ []
$T2 [can bind to: hole, pack] [potential bindings: <none>] @ locator@ [ → generic argument #0]
Inactive Constraints:
$T2 bind ($T0, $T1) @ locator@ []
)";
std::string actualOutput;
{
llvm::raw_string_ostream os(actualOutput);
cs.print(os);
// Remove locator addresses.
std::string adjustedOutput;
const auto size = actualOutput.size();
size_t pos = 0;
while (pos < size) {
auto addr_pos = actualOutput.find("0x", pos);
if (addr_pos == std::string::npos) {
adjustedOutput += actualOutput.substr(pos, std::string::npos);
break;
} else {
adjustedOutput += actualOutput.substr(pos, addr_pos - pos);
}
pos = actualOutput.find(' ', addr_pos);
}
actualOutput = adjustedOutput;
}
EXPECT_EQ(expectedOutput, actualOutput);
}