Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed Dec 23, 2024
1 parent bb6c420 commit 20aa7e9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkgs/pubspec_parse/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topics:
- dart-pub

environment:
sdk: ^3.2.0
sdk: ^3.6.0

dependencies:
checked_yaml: ^2.0.1
Expand Down
49 changes: 48 additions & 1 deletion pkgs/pubspec_parse/test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ void main() {
expect(value.repository, isNull);
expect(value.issueTracker, isNull);
expect(value.screenshots, isEmpty);
expect(value.workspace, isNull);
expect(value.resolution, isNull);
});

test('all fields set', () async {
final version = Version.parse('1.2.3');
final sdkConstraint = VersionConstraint.parse('>=2.12.0 <3.0.0');
final sdkConstraint = VersionConstraint.parse('>=3.6.0 <4.0.0');
final value = await parse({
'name': 'sample',
'version': version.toString(),
Expand All @@ -56,6 +58,11 @@ void main() {
'screenshots': [
{'description': 'my screenshot', 'path': 'path/to/screenshot'},
],
'workspace': [
'pkg1',
'pkg2',
],
'resolution': 'workspace',
});
expect(value.name, 'sample');
expect(value.version, version);
Expand Down Expand Up @@ -86,6 +93,10 @@ void main() {
expect(value.screenshots, hasLength(1));
expect(value.screenshots!.first.description, 'my screenshot');
expect(value.screenshots!.first.path, 'path/to/screenshot');
expect(value.workspace, hasLength(2));
expect(value.workspace!.first, 'pkg1');
expect(value.workspace!.last, 'pkg2');
expect(value.resolution, 'workspace');
});

test('environment values can be null', () async {
Expand Down Expand Up @@ -712,4 +723,40 @@ line 1, column 1: Not a map
);
});
});

group('workspaces', () {
test('workspace key must be a list', () {
expectParseThrowsContaining(
{
...defaultPubspec,
'workspace': 42,
},
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'List<dynamic>?\' in type cast',
skipTryPub: true,
);
});

test('workspace key must be a list of strings', () {
expectParseThrowsContaining(
{
...defaultPubspec,
'workspace': [42],
},
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'String\' in type cast',
skipTryPub: true,
);
});

test('resolution key must be a string', () {
expectParseThrowsContaining(
{
'name': 'sample',
'environment': {'sdk': '^3.6.0'},
'resolution': 42,
},
'Unsupported value for "resolution". type \'int\' is not a subtype of type \'String?\' in type cast',
skipTryPub: true,
);
});
});
}

0 comments on commit 20aa7e9

Please sign in to comment.