Skip to content

[package_config] Remove unnecessary casts to Uint8List #2041

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 1 commit into from
Mar 17, 2025
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
2 changes: 2 additions & 0 deletions pkgs/package_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 2.3.0-wip

## 2.2.0

- Add relational operators to `LanguageVersion` with extension methods
Expand Down
2 changes: 1 addition & 1 deletion pkgs/package_config/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: package_config
version: 2.2.0
version: 2.3.0-wip
description: Support for reading and writing Dart Package Configuration files.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/package_config
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Apackage_config
Expand Down
44 changes: 14 additions & 30 deletions pkgs/package_config/test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ void main() {
"other": [42]
}
''';
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(packageConfigFile) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
var config = parsePackageConfigBytes(utf8.encode(packageConfigFile),
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect({for (var p in config.packages) p.name},
{'foo', 'bar', 'baz', 'noslash'});
Expand Down Expand Up @@ -192,11 +189,8 @@ void main() {
"configVersion": 2
}
''';
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(packageConfigFile) as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
var config = parsePackageConfigBytes(utf8.encode(packageConfigFile),
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect({for (var p in config.packages) p.name}, {'foo', 'bar', 'baz'});

Expand All @@ -219,11 +213,8 @@ void main() {
var name = '"name":"foo"';
var root = '"rootUri":"/foo/"';
test('minimal', () {
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode('{$cfg,$pkgs}') as Uint8List,
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
var config = parsePackageConfigBytes(utf8.encode('{$cfg,$pkgs}'),
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect(config.packages, isEmpty);
});
Expand All @@ -232,7 +223,7 @@ void main() {
// are optional.
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode('{$cfg,"packages":[{$name,$root}]}') as Uint8List,
utf8.encode('{$cfg,"packages":[{$name,$root}]}'),
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
expect(config.version, 2);
Expand All @@ -249,8 +240,7 @@ void main() {
{'name': 'qux', 'rootUri': '/foo/qux/', 'packageUri': 'lib/'},
]
}));
// ignore: unnecessary_cast
var config = parsePackageConfigBytes(configBytes as Uint8List,
var config = parsePackageConfigBytes(configBytes,
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect(config.packageOf(Uri.parse('file:///foo/lala/lala.dart'))!.name,
Expand Down Expand Up @@ -281,8 +271,7 @@ void main() {
{'name': 'qux', 'rootUri': '/qux/', 'packageUri': 'lib/'},
]
}));
// ignore: unnecessary_cast
var config = parsePackageConfigBytes(configBytes as Uint8List,
var config = parsePackageConfigBytes(configBytes,
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect(
Expand All @@ -308,11 +297,8 @@ void main() {
{'name': 'foo', 'rootUri': 'file:///C:/Foo/', 'packageUri': 'lib/'},
]
}));
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
configBytes as Uint8List,
Uri.parse('file:///C:/tmp/.dart_tool/file.dart'),
throwError);
var config = parsePackageConfigBytes(configBytes,
Uri.parse('file:///C:/tmp/.dart_tool/file.dart'), throwError);
expect(config.version, 2);
expect(
config.packageOf(Uri.parse('file:///C:/foo/lala/lala.dart')), null);
Expand All @@ -325,7 +311,7 @@ void main() {
test(name, () {
expect(
// ignore: unnecessary_cast
() => parsePackageConfigBytes(utf8.encode(source) as Uint8List,
() => parsePackageConfigBytes(utf8.encode(source),
Uri.parse('file:///tmp/.dart_tool/file.dart'), throwError),
throwsA(isA<FormatException>()));
});
Expand All @@ -337,8 +323,7 @@ void main() {
dynamic exception;
try {
parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(source) as Uint8List,
utf8.encode(source),
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError,
);
Expand Down Expand Up @@ -464,12 +449,11 @@ void main() {
// This shouldn't be allowed, but for internal reasons it is.
test('package inside package root', () {
var config = parsePackageConfigBytes(
// ignore: unnecessary_cast
utf8.encode(
'{$cfg,"packages":['
'{"name":"foo","rootUri":"/foo/","packageUri":"lib/"},'
'{"name":"bar","rootUri":"/foo/lib/bar/","packageUri":"lib"}]}',
) as Uint8List,
),
Uri.parse('file:///tmp/.dart_tool/file.dart'),
throwError);
expect(
Expand Down