Test that record types work correctly in outlines
I don't believe there's any way for record literals to show up in the outline, and I think this is a reasonable representative sample, but if you think more tests would be better, let me know. Change-Id: Ia62ad30d860d70a483249879f2ae8bea8e65b6a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257442 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Bot
parent
41b479e32e
commit
c191725dee
@@ -1572,6 +1572,73 @@ set propB(int v) {}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> test_topLevelFunction_recordTypes() async {
|
||||
var unitOutline = await _computeOutline('''
|
||||
(int, int) f((String, String) r) => throw '';
|
||||
''');
|
||||
|
||||
var topOutlines = unitOutline.children!;
|
||||
expect(topOutlines, hasLength(1));
|
||||
|
||||
assertJsonText(topOutlines[0], '''
|
||||
{
|
||||
"element": {
|
||||
"kind": "FUNCTION",
|
||||
"name": "f",
|
||||
"location": {
|
||||
"file": "/home/test/lib/test.dart",
|
||||
"offset": 11,
|
||||
"length": 1,
|
||||
"startLine": 1,
|
||||
"startColumn": 12,
|
||||
"endLine": 1,
|
||||
"endColumn": 13
|
||||
},
|
||||
"flags": 8,
|
||||
"parameters": "((String, String) r)",
|
||||
"returnType": "(int, int)"
|
||||
},
|
||||
"offset": 0,
|
||||
"length": 45,
|
||||
"codeOffset": 0,
|
||||
"codeLength": 45
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topLevelVariable_recordTypes() async {
|
||||
var unitOutline = await _computeOutline('''
|
||||
(int, int)? r = null;
|
||||
''');
|
||||
|
||||
var topOutlines = unitOutline.children!;
|
||||
expect(topOutlines, hasLength(1));
|
||||
|
||||
assertJsonText(topOutlines[0], '''
|
||||
{
|
||||
"element": {
|
||||
"kind": "TOP_LEVEL_VARIABLE",
|
||||
"name": "r",
|
||||
"location": {
|
||||
"file": "/home/test/lib/test.dart",
|
||||
"offset": 12,
|
||||
"length": 1,
|
||||
"startLine": 1,
|
||||
"startColumn": 13,
|
||||
"endLine": 1,
|
||||
"endColumn": 14
|
||||
},
|
||||
"flags": 0,
|
||||
"returnType": "(int, int)?"
|
||||
},
|
||||
"offset": 0,
|
||||
"length": 21,
|
||||
"codeOffset": 12,
|
||||
"codeLength": 8
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
void _expect(Outline outline,
|
||||
{ElementKind? kind,
|
||||
bool leaf = false,
|
||||
|
||||
@@ -915,6 +915,9 @@ class ToSourceVisitor implements AstVisitor<void> {
|
||||
}
|
||||
_visitNode(namedFields);
|
||||
sink.write(')');
|
||||
if (node.question != null) {
|
||||
sink.write('?');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -2852,6 +2852,17 @@ $code f() {}
|
||||
);
|
||||
}
|
||||
|
||||
void test_visitRecordTypeAnnotation_positional_nullable() {
|
||||
final code = '(int, bool)?';
|
||||
var findNode = _parseStringToFindNode('''
|
||||
$code f() {}
|
||||
''');
|
||||
_assertSource(
|
||||
code,
|
||||
findNode.recordTypeAnnotation(code),
|
||||
);
|
||||
}
|
||||
|
||||
void test_visitRedirectingConstructorInvocation_named() {
|
||||
_assertSource(
|
||||
"this.c()", AstTestFactory.redirectingConstructorInvocation2("c"));
|
||||
|
||||
Reference in New Issue
Block a user