forked from google/protobuf.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix comparison of empty lists from frozen messages. (google#492)
The existing implementation returns an unmodifiable list, which does not obey the value-comparison semantics expected for protobuf lists. Returning a FrozenPbList instead resolves this. Co-authored-by: Loren Van Spronsen <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Test for ensuring that protobuf lists compare using value semantics. | ||
library list_equality_test; | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import 'mock_util.dart' show T; | ||
|
||
void main() { | ||
test('empty lists compare as equal', () { | ||
final first = T(); | ||
final second = T(); | ||
expect(first.int32s == second.int32s, isTrue); | ||
}); | ||
|
||
test('empty frozen lists compare as equal', () { | ||
final first = T()..freeze(); | ||
final second = T()..freeze(); | ||
expect(first.int32s == second.int32s, isTrue); | ||
}); | ||
|
||
test('non-empty lists compare as equal', () { | ||
final first = T()..int32s.add(1); | ||
final second = T()..int32s.add(1); | ||
expect(first.int32s == second.int32s, isTrue); | ||
}); | ||
|
||
test('non-empty frozen lists compare as equal', () { | ||
final first = T() | ||
..int32s.add(1) | ||
..freeze(); | ||
final second = T() | ||
..int32s.add(1) | ||
..freeze(); | ||
expect(first.int32s == second.int32s, isTrue); | ||
}); | ||
|
||
test('different lists do not compare as equal', () { | ||
final first = T()..int32s.add(1); | ||
final second = T()..int32s.add(2); | ||
expect(first.int32s == second.int32s, isFalse); | ||
}); | ||
|
||
test('different frozen lists do not compare as equal', () { | ||
final first = T() | ||
..int32s.add(1) | ||
..freeze(); | ||
final second = T() | ||
..int32s.add(2) | ||
..freeze(); | ||
expect(first.int32s == second.int32s, isFalse); | ||
}); | ||
} |