Skip to content

Record rendering simplification #3344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/src/render/element_type_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class RecordElementTypeRendererHtml
@override
String renderLinkedName(RecordElementType elementType) {
var buffer = StringBuffer()
..write(elementType.nameWithGenerics)
..write('(')
..write(const RecordTypeFieldListHtmlRenderer()
.renderLinkedFields(elementType)
Expand Down
10 changes: 3 additions & 7 deletions lib/src/render/record_type_field_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ abstract class _RecordTypeFieldListRenderer {
var linkedTypeName = typeName(modelType.linkedName);
if (linkedTypeName.isNotEmpty) {
fieldBuffer.write(linkedTypeName);
}
if (field is RecordTypeNamedField) {
fieldBuffer.write(' ');
fieldBuffer.write(fieldName(field.name));
}
var name = field is RecordTypeNamedField
? field.name
: _fieldName(field, index);
fieldBuffer.write(fieldName(name));
fieldBuffer.write(suffix);

buffer.write(listItem(this.field(fieldBuffer.toString())));
});
}
Expand All @@ -114,6 +112,4 @@ abstract class _RecordTypeFieldListRenderer {
}
return orderedList(buffer.toString());
}

String _fieldName(RecordTypeField field, int index) => '\$$index';
}
29 changes: 12 additions & 17 deletions test/record_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,33 @@ class RecordTest extends DartdocTestBase {
String get libraryName => 'records';

@override
String get sdkConstraint => '>=2.19.0-0 <3.0.0';
String get sdkConstraint => '>=2.19.0-0 <4.0.0';

@override
List<String> get experiments => ['records'];

void test_noFields() async {
var library = await bootPackageWithLibrary('''
void f(() record) {}
void f(() r) {}
''');
var fFunction = library.functions.named('f');
var recordType = fFunction.modelType.parameters.first.modelType;
expect(recordType.linkedName, equals('Record()'));
expect(recordType.linkedName, equals('()'));
expect(recordType.nameWithGenerics, equals('Record'));
}

void test_onePositionalField() async {
var library = await bootPackageWithLibrary('''
void f((int) record) {}
void f((int) r) {}
''');
var fFunction = library.functions.named('f');
var recordType = fFunction.modelType.parameters.first.modelType;
expect(recordType.linkedName, matchesCompressed(r'''
Record\(
\(
<span class="field">
<span class="type-annotation">
<a href=".*/dart-core/int-class.html">int</a>
</span>
<span class="field-name">\$0</span>
</span>
\)
'''));
Expand All @@ -58,23 +57,21 @@ void f((int) record) {}

void test_positionalFields() async {
var library = await bootPackageWithLibrary('''
void f((int, String) record) {}
void f((int, String) r) {}
''');
var fFunction = library.functions.named('f');
var recordType = fFunction.modelType.parameters.first.modelType;
expect(recordType.linkedName, matchesCompressed(r'''
Record\(
\(
<span class="field">
<span class="type-annotation">
<a href=".*/dart-core/int-class.html">int</a>
</span>
<span class="field-name">\$0</span>,
</span>,
</span>
<span class="field">
<span class="type-annotation">
<a href=".*/dart-core/String-class.html">String</a>
</span>
<span class="field-name">\$1</span>
</span>
\)
'''));
Expand All @@ -88,7 +85,7 @@ void f(({int bbb, String aaa}) record) {}
var fFunction = library.functions.named('f');
var recordType = fFunction.modelType.parameters.first.modelType;
expect(recordType.linkedName, matchesCompressed(r'''
Record\(
\(
<span class="field">
\{
<span class="type-annotation">
Expand All @@ -115,18 +112,16 @@ void f((int one, String two, {int ccc, String aaa, int bbb}) record) {}
var fFunction = library.functions.named('f');
var recordType = fFunction.modelType.parameters.first.modelType;
expect(recordType.linkedName, matchesCompressed(r'''
Record\(
\(
<span class="field">
<span class="type-annotation">
<a href=".*/dart-core/int-class.html">int</a>
</span>
<span class="field-name">\$0</span>,
</span>,
</span>
<span class="field">
<span class="type-annotation">
<a href=".*/dart-core/String-class.html">String</a>
</span>
<span class="field-name">\$1</span>,
</span>,
</span>
<span class="field">
\{
Expand Down