forked from dart-archive/dart-protoc-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepeated_field_test.dart
69 lines (56 loc) · 1.99 KB
/
repeated_field_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env dart
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library repeated_field_test;
import 'package:protobuf/protobuf.dart';
import 'package:test/test.dart';
import '../out/protos/google/protobuf/unittest.pb.dart';
import 'test_util.dart';
// Suppress an analyzer warning for a deliberate type mismatch.
cast(x) => x;
void main() {
test("checkItems works for messages", () {
expect(() {
TestAllTypes.$checkItem(new TestAllTypes());
}, returnsNormally);
expect(() {
TestAllTypes.$checkItem(cast(new TestAllTypes_NestedMessage()));
}, throwsATypeError);
});
test("checkItems works for groups", () {
expect(() {
TestAllTypes_RepeatedGroup.$checkItem(new TestAllTypes_RepeatedGroup());
}, returnsNormally);
expect(() {
TestAllTypes_RepeatedGroup.$checkItem(
cast(new TestAllTypes_OptionalGroup()));
}, throwsATypeError);
});
test("checkItems works for enums", () {
expect(() {
TestAllTypes_NestedEnum.$checkItem(TestAllTypes_NestedEnum.FOO);
}, returnsNormally);
expect(() {
TestAllTypes_NestedEnum.$checkItem(cast(ForeignEnum.FOREIGN_FOO));
}, throwsATypeError);
});
test("check properties are initialized for repeated fields", () {
var msg = new TestAllTypes();
expect(
(msg.info_.byName["repeatedNestedMessage"]
as FieldInfo<TestAllTypes_NestedMessage>)
.check,
same(TestAllTypes_NestedMessage.$checkItem));
expect(
(msg.info_.byName["repeatedGroup"]
as FieldInfo<TestAllTypes_RepeatedGroup>)
.check,
same(TestAllTypes_RepeatedGroup.$checkItem));
expect(
(msg.info_.byName["repeatedNestedEnum"]
as FieldInfo<TestAllTypes_NestedEnum>)
.check,
same(TestAllTypes_NestedEnum.$checkItem));
});
}