forked from rknell/flutterEnumsToString
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_to_string_test.dart
46 lines (40 loc) · 1.82 KB
/
enum_to_string_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'package:test/test.dart';
import 'package:enum_to_string/enum_to_string.dart';
enum TestEnum { valueOne, Value2, testValue3 }
enum OtherEnumForTesting { helloImAnEnumValue }
void main() {
test('it should convert enums to string', () {
expect(EnumToString.parse(TestEnum.valueOne), "valueOne");
expect(EnumToString.parse(TestEnum.Value2), "Value2");
expect(EnumToString.parse(TestEnum.testValue3), "testValue3");
expect(EnumToString.parse(OtherEnumForTesting.helloImAnEnumValue),
"helloImAnEnumValue");
expect(EnumToString.parse(null), null);
});
test('it should convert camelCase enums to words', () {
expect(EnumToString.parseCamelCase(TestEnum.valueOne), "Value one");
expect(EnumToString.parseCamelCase(TestEnum.Value2), "Value 2");
expect(EnumToString.parseCamelCase(TestEnum.testValue3), "Test value 3");
expect(EnumToString.parseCamelCase(OtherEnumForTesting.helloImAnEnumValue),
"Hello im an enum value");
expect(EnumToString.parseCamelCase(null), null);
});
test('it should convert a string to an enum', () {
expect(EnumToString.fromString<TestEnum>(TestEnum.values, "valueOne"),
TestEnum.valueOne);
expect(EnumToString.fromString(TestEnum.values, "Value2"), TestEnum.Value2);
expect(
EnumToString.fromString(
OtherEnumForTesting.values, "helloImAnEnumValue"),
OtherEnumForTesting.helloImAnEnumValue);
});
test('it should convert a string to an enum ignoring case', () {
expect(EnumToString.fromString<TestEnum>(TestEnum.values, "VaLueONe"),
TestEnum.valueOne);
expect(EnumToString.fromString(TestEnum.values, "vAlUe2"), TestEnum.Value2);
expect(
EnumToString.fromString(
OtherEnumForTesting.values, "hEllOImAnEnUmVAlUE"),
OtherEnumForTesting.helloImAnEnumValue);
});
}