Skip to content

Commit

Permalink
update model tests, they now work for duplicate or re-used nodes, uns…
Browse files Browse the repository at this point in the history
…ure if this is a good thing
  • Loading branch information
jakemac53 committed Oct 24, 2024
1 parent 3ba1c6f commit 5d9b5ed
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkgs/dart_model/test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,37 @@ void main() {
});
});

test('path to Members throws on cycle', () {
test('path to Members works for cycles', () {
final copiedModel = Model.fromJson(_copyMap(model.node));
// Add an invalid link creating a loop in the map structure.
(copiedModel.node['uris'] as Map<String, Object?>)['loop'] = copiedModel;
final member = copiedModel.uris['package:dart_model/dart_model.dart']!
.scopes['JsonData']!.members['_root']!;
expect(() => copiedModel.qualifiedNameOf(member.node), throwsStateError);
expect(
copiedModel.qualifiedNameOf(member.node),
QualifiedName(
uri: 'package:dart_model/dart_model.dart',
scope: 'JsonData',
name: '_root',
isStatic: false,
));
});

test('path to Members throws on reused node', () {
test('path to Members works for reused node', () {
final copiedModel = Model.fromJson(_copyMap(model.node));
// Reuse a node.
copiedModel.uris['duplicate'] =
copiedModel.uris['package:dart_model/dart_model.dart']!;
final member = copiedModel.uris['package:dart_model/dart_model.dart']!
.scopes['JsonData']!.members['_root']!;
expect(() => copiedModel.qualifiedNameOf(member.node), throwsStateError);
expect(
copiedModel.qualifiedNameOf(member.node),
QualifiedName(
uri: 'package:dart_model/dart_model.dart',
scope: 'JsonData',
name: '_root',
isStatic: false,
));
});

test('path to Member returns null for Member in wrong Map', () {
Expand Down

0 comments on commit 5d9b5ed

Please sign in to comment.