-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathtext_util_test.dart
64 lines (55 loc) · 2.09 KB
/
text_util_test.dart
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
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:kernel/ast.dart';
import 'package:kernel/src/printer.dart';
import "reference_name_test.dart" show createComponent;
void main() {
testQualifiedCanonicalNameToString();
}
void testQualifiedCanonicalNameToString() {
Component component = createComponent();
component.computeCanonicalNames();
NamedNodeCollector namedNodeCollector = new NamedNodeCollector();
component.accept(namedNodeCollector);
bool foundMismatch = false;
for (NamedNode namedNode in namedNodeCollector.namedNodes) {
for (AstTextStrategy strategy in [
const AstTextStrategy(
includeLibraryNamesInMembers: false,
includeLibraryNamesInTypes: false),
const AstTextStrategy(includeLibraryNamesInMembers: true),
const AstTextStrategy(includeLibraryNamesInTypes: true),
const AstTextStrategy(
includeLibraryNamesInMembers: true, includeLibraryNamesInTypes: true),
]) {
String throughNode = namedNode.toText(strategy);
String throughReference = namedNode.reference.toText(strategy);
String throughCanonicalName =
namedNode.reference.canonicalName!.toText(strategy);
if (throughNode == throughReference &&
throughReference == throughCanonicalName) {
continue;
}
print("${namedNode.runtimeType} "
"(${strategy.includeLibraryNamesInMembers},"
"${strategy.includeLibraryNamesInTypes}): "
"$throughNode <--> $throughReference <--> $throughCanonicalName");
foundMismatch = true;
}
}
if (foundMismatch) throw "Found mismatch.";
}
class NamedNodeCollector extends RecursiveVisitor {
List<NamedNode> namedNodes = [];
@override
void defaultNode(Node node) {
if (node is NamedNode) {
namedNodes.add(node);
}
if (node is Extension) return;
if (node is Typedef) return;
if (node is Member) return;
super.defaultNode(node);
}
}