Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2023-10-23 13:13:32 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
535c2bd85f19e1f1f7acadad903d5e28bd68b908
535c2bd8
1 parent
dd6ecbaa
let enums throw if raw value is out of bounds
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
22 deletions
lib/src/enums/address_type.dart
lib/src/enums/barcode_format.dart
lib/src/enums/barcode_type.dart
test/enums/address_type_test.dart
test/enums/barcode_format_test.dart
test/enums/barcode_type_test.dart
test/enums/camera_facing_test.dart
lib/src/enums/address_type.dart
View file @
535c2bd
...
...
@@ -13,13 +13,14 @@ enum AddressType {
factory
AddressType
.
fromRawValue
(
int
value
)
{
switch
(
value
)
{
case
0
:
return
AddressType
.
unknown
;
case
1
:
return
AddressType
.
work
;
case
2
:
return
AddressType
.
home
;
case
0
:
default
:
return
AddressType
.
unknown
;
throw
ArgumentError
.
value
(
value
,
'value'
,
'Invalid raw value.'
)
;
}
}
...
...
lib/src/enums/barcode_format.dart
View file @
535c2bd
...
...
@@ -49,6 +49,8 @@ enum BarcodeFormat {
factory
BarcodeFormat
.
fromRawValue
(
int
value
)
{
switch
(
value
)
{
case
-
1
:
return
BarcodeFormat
.
unknown
;
case
0
:
return
BarcodeFormat
.
all
;
case
1
:
...
...
@@ -77,9 +79,8 @@ enum BarcodeFormat {
return
BarcodeFormat
.
pdf417
;
case
4096
:
return
BarcodeFormat
.
aztec
;
case
-
1
:
default
:
return
BarcodeFormat
.
unknown
;
throw
ArgumentError
.
value
(
value
,
'value'
,
'Invalid raw value.'
)
;
}
}
...
...
lib/src/enums/barcode_type.dart
View file @
535c2bd
...
...
@@ -43,6 +43,8 @@ enum BarcodeType {
factory
BarcodeType
.
fromRawValue
(
int
value
)
{
switch
(
value
)
{
case
0
:
return
BarcodeType
.
unknown
;
case
1
:
return
BarcodeType
.
contactInfo
;
case
2
:
...
...
@@ -67,9 +69,8 @@ enum BarcodeType {
return
BarcodeType
.
calendarEvent
;
case
12
:
return
BarcodeType
.
driverLicense
;
case
0
:
default
:
return
BarcodeType
.
unknown
;
throw
ArgumentError
.
value
(
value
,
'value'
,
'Invalid raw value.'
)
;
}
}
...
...
test/enums/address_type_test.dart
View file @
535c2bd
...
...
@@ -17,12 +17,12 @@ void main() {
}
});
test
(
'invalid raw value creates unknown address type'
,
()
{
final
AddressType
negative
=
AddressType
.
fromRawValue
(-
1
);
final
AddressType
outOfRange
=
AddressType
.
fromRawValue
(
3
);
test
(
'invalid raw value throws argument error'
,
()
{
const
int
negative
=
-
1
;
const
int
outOfRange
=
3
;
expect
(
negative
,
AddressType
.
unknown
);
expect
(
outOfRange
,
AddressType
.
unknown
);
expect
(()
=>
AddressType
.
fromRawValue
(
negative
),
throwsArgumentError
);
expect
(()
=>
AddressType
.
fromRawValue
(
outOfRange
),
throwsArgumentError
);
});
test
(
'can be converted to raw value'
,
()
{
...
...
test/enums/barcode_format_test.dart
View file @
535c2bd
...
...
@@ -29,12 +29,12 @@ void main() {
}
});
test
(
'invalid raw value creates unknown barcode format'
,
()
{
final
BarcodeFormat
negative
=
BarcodeFormat
.
fromRawValue
(-
2
);
final
BarcodeFormat
outOfRange
=
BarcodeFormat
.
fromRawValue
(
4097
);
test
(
'invalid raw value throws argument error'
,
()
{
const
int
negative
=
-
2
;
const
int
outOfRange
=
4097
;
expect
(
negative
,
BarcodeFormat
.
unknown
);
expect
(
outOfRange
,
BarcodeFormat
.
unknown
);
expect
(()
=>
BarcodeFormat
.
fromRawValue
(
negative
),
throwsArgumentError
);
expect
(()
=>
BarcodeFormat
.
fromRawValue
(
outOfRange
),
throwsArgumentError
);
});
test
(
'can be converted to raw value'
,
()
{
...
...
test/enums/barcode_type_test.dart
View file @
535c2bd
...
...
@@ -27,12 +27,12 @@ void main() {
}
});
test
(
'invalid raw value creates unknown barcode type'
,
()
{
final
BarcodeType
negative
=
BarcodeType
.
fromRawValue
(-
1
);
final
BarcodeType
outOfRange
=
BarcodeType
.
fromRawValue
(
13
);
test
(
'invalid raw value throws argument error'
,
()
{
const
int
negative
=
-
1
;
const
int
outOfRange
=
13
;
expect
(
negative
,
BarcodeType
.
unknown
);
expect
(
outOfRange
,
BarcodeType
.
unknown
);
expect
(()
=>
BarcodeType
.
fromRawValue
(
negative
),
throwsArgumentError
);
expect
(()
=>
BarcodeType
.
fromRawValue
(
outOfRange
),
throwsArgumentError
);
});
test
(
'can be converted to raw value'
,
()
{
...
...
test/enums/camera_facing_test.dart
View file @
535c2bd
...
...
@@ -16,7 +16,7 @@ void main() {
}
});
test
(
'invalid raw value throws a
ssertion
error'
,
()
{
test
(
'invalid raw value throws a
rgument
error'
,
()
{
const
int
negative
=
-
1
;
const
int
outOfRange
=
2
;
...
...
Please
register
or
login
to post a comment