Skip to content

Commit 9b4c46f

Browse files
authored
More clearExtension tests: (#1064)
Mutation testing discovered that removing the `_ensureWritable` line in `FieldSet.clearExtension` doesn't cause any test failures. Add a test that fails when the line is removed.
1 parent 5a44489 commit 9b4c46f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

protoc_plugin/test/extension_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ void main() {
7373
expect(message.hasExtension(Unittest.optionalInt32Extension), isFalse);
7474
});
7575

76+
test(
77+
'clearing extension throws when the message is frozen, without extension field set',
78+
() {
79+
final message = TestAllExtensions()..freeze();
80+
expect(
81+
() => message.clearExtension(Unittest.optionalInt32Extension),
82+
throwsA(TypeMatcher<UnsupportedError>()),
83+
);
84+
},
85+
);
86+
87+
test(
88+
'clearing extension throws when the message is frozen, with extension field set',
89+
() {
90+
final message =
91+
TestAllExtensions()
92+
..setExtension(Unittest.optionalInt32Extension, 1)
93+
..freeze();
94+
expect(
95+
() => message.clearExtension(Unittest.optionalInt32Extension),
96+
throwsA(TypeMatcher<UnsupportedError>()),
97+
);
98+
},
99+
);
100+
76101
test('can clear a repeated extension', () {
77102
final message = TestAllExtensions();
78103
message.addExtension(Unittest.repeatedInt32Extension, 1);

0 commit comments

Comments
 (0)