OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dev_compiler.test.utils_test; | 5 library dev_compiler.test.utils_test; |
6 | 6 |
7 import 'package:dev_compiler/src/utils.dart'; | 7 import 'package:dev_compiler/src/utils.dart'; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 | 9 |
10 enum Foo { | 10 enum Foo { first, second } |
11 first, second | |
12 } | |
13 | 11 |
14 void main() { | 12 void main() { |
15 group('getEnumValue', () { | 13 group('getEnumValue', () { |
16 test('gets simple names', () { | 14 test('gets simple names', () { |
17 expect(getEnumName(Foo.first), 'first'); | 15 expect(getEnumName(Foo.first), 'first'); |
18 }); | 16 }); |
19 test('chokes on invalid values', () { | 17 test('chokes on invalid values', () { |
20 expect(() => getEnumName(null), throws); | 18 expect(() => getEnumName(null), throws); |
21 expect(() => getEnumName(''), throws); | 19 expect(() => getEnumName(''), throws); |
22 expect(() => getEnumName('.'), throws); | 20 expect(() => getEnumName('.'), throws); |
23 expect(() => getEnumName('.a'), throws); | 21 expect(() => getEnumName('.a'), throws); |
24 expect(() => getEnumName('a.'), throws); | 22 expect(() => getEnumName('a.'), throws); |
25 }); | 23 }); |
26 }); | 24 }); |
27 group('parseEnum', () { | 25 group('parseEnum', () { |
28 Foo parseFoo(String s) => parseEnum(s, Foo.values); | 26 Foo parseFoo(String s) => parseEnum(s, Foo.values); |
29 test('parses enums', () { | 27 test('parses enums', () { |
30 expect(parseFoo('first'), Foo.first); | 28 expect(parseFoo('first'), Foo.first); |
31 expect(parseFoo('second'), Foo.second); | 29 expect(parseFoo('second'), Foo.second); |
32 }); | 30 }); |
33 test('chokes on unknown enums', () { | 31 test('chokes on unknown enums', () { |
34 expect(() => parseFoo(''), throws); | 32 expect(() => parseFoo(''), throws); |
35 expect(() => parseFoo('what'), throws); | 33 expect(() => parseFoo('what'), throws); |
36 }); | 34 }); |
37 }); | 35 }); |
38 } | 36 } |
OLD | NEW |