Skip to content

Commit

Permalink
[package_config] Fix error when validating the minor parameter of Lan…
Browse files Browse the repository at this point in the history
…guageVersion.new
  • Loading branch information
parlough committed Feb 11, 2025
1 parent 750b4ad commit a470e69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkgs/package_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.2-wip

- Include correct parameter names in errors when validating
the `major` and `minor` versions in the `LanguageVersion.new` constructor.

## 2.1.1

- Require Dart 3.4
Expand Down
8 changes: 7 additions & 1 deletion pkgs/package_config/lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,15 @@ abstract class Package {
abstract class LanguageVersion implements Comparable<LanguageVersion> {
/// The maximal value allowed by [major] and [minor] values;
static const int maxValue = 0x7FFFFFFF;

/// Constructs a [LanguageVersion] with the specified
/// [major] and [minor] version numbers.
///
/// Both [major] and [minor] must be greater than or equal to 0
/// and less than or equal to [maxValue].
factory LanguageVersion(int major, int minor) {
RangeError.checkValueInInterval(major, 0, maxValue, 'major');
RangeError.checkValueInInterval(minor, 0, maxValue, 'major');
RangeError.checkValueInInterval(minor, 0, maxValue, 'minor');
return SimpleLanguageVersion(major, minor, null);
}

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.1.1
version: 2.1.2-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
16 changes: 14 additions & 2 deletions pkgs/package_config/test/package_config_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ void main() {
});

test('negative major', () {
expect(() => LanguageVersion(-1, 1), throwsArgumentError);
expect(
() => LanguageVersion(-1, 1),
throwsA(isA<RangeError>().having(
(e) => e.name,
'message',
contains('major'),
)));
});

test('negative minor', () {
expect(() => LanguageVersion(1, -1), throwsArgumentError);
expect(
() => LanguageVersion(1, -1),
throwsA(isA<RangeError>().having(
(e) => e.name,
'message',
contains('minor'),
)));
});

test('minimal parse', () {
Expand Down

0 comments on commit a470e69

Please sign in to comment.