Skip to content

Commit

Permalink
Require uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jun 19, 2024
1 parent 9be8dfe commit d232bcb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 41 deletions.
1 change: 1 addition & 0 deletions pkgs/record_use/lib/record_use_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// 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.

export 'src/data_classes/extensions.dart';
export 'src/proto/usages_read.pb.dart';
export 'src/proto/usages_shared.pb.dart';
19 changes: 10 additions & 9 deletions pkgs/record_use/lib/src/data_classes/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ extension UsagesExt on pb.Usages {
const JsonEncoder.withIndent(' ').convert(_toStorage().writeToJsonMap());

pb_storage.Usages _toStorage() {
final usageList = [...calls, ...instances];
final definitions =
[...calls, ...instances].map((e) => e.definition).toList();
final uris = [...calls, ...instances]
.expand((e) => [
e.definition.identifier.uri,
...e.references.map(
(e) => e.location.uri,
)
usageList.map((usage) => usage.definition).toSet().toList();
final uris = usageList
.expand((usage) => [
usage.definition.identifier.uri,
...usage.references.map((reference) => reference.location.uri)
])
.toSet()
.toList();
return pb_storage.Usages(
metadata: metadata,
definitions: definitions,
uris: uris,
instances: instances.map((e) => e.toStorage(definitions, uris)),
calls: calls.map((e) => e.toStorage(definitions, uris)),
instances:
instances.map((instance) => instance.toStorage(definitions, uris)),
calls: calls.map((call) => call.toStorage(definitions, uris)),
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/record_use/test/storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:io';

import 'package:record_use/record_use_internal.dart';
import 'package:record_use/src/data_classes/extensions.dart';
import 'package:record_use/src/record_use.dart';
import 'package:test/test.dart';

Expand All @@ -23,4 +22,10 @@ void main() {
recordedUses,
);
});
test('empty Object->Buffer->Object', () {
expect(
RecordedUsages.fromFile(emptyUsages.toBuffer()),
emptyUsages,
);
});
}
69 changes: 38 additions & 31 deletions pkgs/record_use/test/testdata/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:pub_semver/pub_semver.dart';
import 'package:record_use/record_use_internal.dart' as pb;

final pb.Usages recordedUses = pb.Usages(
metadata: pb.Metadata(
import 'package:record_use/record_use_internal.dart';

final Usages emptyUsages = Usages(
metadata: Metadata(version: Version(1, 2, 3).toString()),
calls: [],
instances: [],
);

final Usages recordedUses = Usages(
metadata: Metadata(
version: Version(1, 6, 2, pre: 'wip', build: '5.-.2.z').toString(),
comment:
'Recorded references at compile time and their argument values, as far'
' as known, to definitions annotated with @RecordReference',
),
instances: [
pb.Usage(
definition: pb.Definition(
identifier: pb.Identifier(
Usage(
definition: Definition(
identifier: Identifier(
uri: Uri.parse('file://lib/_internal/js_runtime/lib/js_helper.dart')
.toString(),
name: 'MyAnnotation',
Expand All @@ -24,18 +31,18 @@ final pb.Usages recordedUses = pb.Usages(
column: 30,
),
references: [
pb.Reference(
location: pb.Location(
Reference(
location: Location(
uri: Uri.parse('file://lib/_internal/js_runtime/lib/js_helper.dart')
.toString(),
line: 40,
column: 30,
),
fields: pb.Fields(fields: [
pb.Field(
fields: Fields(fields: [
Field(
className: 'className',
name: 'a',
value: pb.FieldValue(intValue: 42),
value: FieldValue(intValue: 42),
),
]),
loadingUnit: '3',
Expand All @@ -44,9 +51,9 @@ final pb.Usages recordedUses = pb.Usages(
),
],
calls: [
pb.Usage(
definition: pb.Definition(
identifier: pb.Identifier(
Usage(
definition: Definition(
identifier: Identifier(
uri: Uri.parse('file://lib/_internal/js_runtime/lib/js_helper.dart')
.toString(),
parent: 'MyClass',
Expand All @@ -57,21 +64,21 @@ final pb.Usages recordedUses = pb.Usages(
loadingUnit: 'part_15.js',
),
references: [
pb.Reference(
arguments: pb.Arguments(
constArguments: pb.ConstArguments(
Reference(
arguments: Arguments(
constArguments: ConstArguments(
positional: {
0: pb.FieldValue(stringValue: 'lib_SHA1'),
1: pb.FieldValue(boolValue: false),
2: pb.FieldValue(intValue: 1),
0: FieldValue(stringValue: 'lib_SHA1'),
1: FieldValue(boolValue: false),
2: FieldValue(intValue: 1),
},
named: {
'leroy': pb.FieldValue(stringValue: 'jenkins'),
'freddy': pb.FieldValue(stringValue: 'mercury'),
'leroy': FieldValue(stringValue: 'jenkins'),
'freddy': FieldValue(stringValue: 'mercury'),
},
),
),
location: pb.Location(
location: Location(
uri: Uri.parse(
'file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart')
.toString(),
Expand All @@ -80,23 +87,23 @@ final pb.Usages recordedUses = pb.Usages(
),
loadingUnit: 'o.js',
),
pb.Reference(
arguments: pb.Arguments(
constArguments: pb.ConstArguments(
Reference(
arguments: Arguments(
constArguments: ConstArguments(
positional: {
0: pb.FieldValue(stringValue: 'lib_SHA1'),
2: pb.FieldValue(intValue: 0),
0: FieldValue(stringValue: 'lib_SHA1'),
2: FieldValue(intValue: 0),
},
named: {
'leroy': pb.FieldValue(stringValue: 'jenkins'),
'leroy': FieldValue(stringValue: 'jenkins'),
},
),
nonConstArguments: pb.NonConstArguments(
nonConstArguments: NonConstArguments(
positional: [1],
named: ['freddy'],
),
),
location: pb.Location(
location: Location(
uri: Uri.parse(
'file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart')
.toString(),
Expand Down

0 comments on commit d232bcb

Please sign in to comment.