Add asserts for Version parameter ranges.

This commit is contained in:
Dain Nilsson 2022-06-02 09:45:48 +02:00
parent 627e6bdadd
commit 4c34b69c8d
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 14 additions and 1 deletions

View File

@ -107,6 +107,12 @@ enum UsbPid {
@freezed @freezed
class Version with _$Version implements Comparable<Version> { class Version with _$Version implements Comparable<Version> {
const Version._(); const Version._();
@Assert('major >= 0')
@Assert('major < 256')
@Assert('minor >= 0')
@Assert('minor < 256')
@Assert('patch >= 0')
@Assert('patch < 256')
const factory Version(int major, int minor, int patch) = _Version; const factory Version(int major, int minor, int patch) = _Version;
factory Version.fromJson(List<dynamic> values) { factory Version.fromJson(List<dynamic> values) {

View File

@ -106,7 +106,14 @@ class __$$_VersionCopyWithImpl<$Res> extends _$VersionCopyWithImpl<$Res>
/// @nodoc /// @nodoc
class _$_Version extends _Version { class _$_Version extends _Version {
const _$_Version(this.major, this.minor, this.patch) : super._(); const _$_Version(this.major, this.minor, this.patch)
: assert(major >= 0),
assert(major < 256),
assert(minor >= 0),
assert(minor < 256),
assert(patch >= 0),
assert(patch < 256),
super._();
@override @override
final int major; final int major;