[geary/mjog/composer-context-loading-fixes: 1/9] Geary.RFC822.MailboxAddresses: Update equality semantics
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/composer-context-loading-fixes: 1/9] Geary.RFC822.MailboxAddresses: Update equality semantics
- Date: Thu, 13 Aug 2020 01:46:35 +0000 (UTC)
commit beb86c14d28de69803ace4d1f297e2df79cc739c
Author: Michael Gratton <mike vee net>
Date: Wed Aug 12 15:45:31 2020 +1000
Geary.RFC822.MailboxAddresses: Update equality semantics
Although when processing mailbox addresses lists are effectively sets,
the ordering can be important for people. As such, make `equal_to`
comparisons require identical ordering, and add new `contains_all` for
order-independent comparisons.
src/engine/rfc822/rfc822-mailbox-addresses.vala | 19 +++++++++++-
.../rfc822/rfc822-mailbox-addresses-test.vala | 36 ++++++++++++++++++++--
2 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-mailbox-addresses.vala b/src/engine/rfc822/rfc822-mailbox-addresses.vala
index 25591d893..7a40f822d 100644
--- a/src/engine/rfc822/rfc822-mailbox-addresses.vala
+++ b/src/engine/rfc822/rfc822-mailbox-addresses.vala
@@ -215,7 +215,8 @@ public class Geary.RFC822.MailboxAddresses :
return this.hash_value;
}
- public bool equal_to(MailboxAddresses other) {
+ /** Determines if this list contains all of the other's, in any order. */
+ public bool contains_all(MailboxAddresses other) {
return (
this == other ||
(this.addrs.size == other.addrs.size &&
@@ -223,6 +224,22 @@ public class Geary.RFC822.MailboxAddresses :
);
}
+ /** Determines if this list contains all of the other's, in order. */
+ public bool equal_to(MailboxAddresses other) {
+ if (this == other) {
+ return true;
+ }
+ if (this.addrs.size != other.addrs.size) {
+ return false;
+ }
+ for (int i = 0; i < this.addrs.size; i++) {
+ if (!this.addrs[i].equal_to(other.addrs[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* See Geary.MessageData.SearchableMessageData.
*/
diff --git a/test/engine/rfc822/rfc822-mailbox-addresses-test.vala
b/test/engine/rfc822/rfc822-mailbox-addresses-test.vala
index 465a98779..2c969b925 100644
--- a/test/engine/rfc822/rfc822-mailbox-addresses-test.vala
+++ b/test/engine/rfc822/rfc822-mailbox-addresses-test.vala
@@ -12,6 +12,7 @@ class Geary.RFC822.MailboxAddressesTest : TestCase {
add_test("from_rfc822_string_encoded", from_rfc822_string_encoded);
add_test("from_rfc822_string_quoted", from_rfc822_string_quoted);
add_test("to_rfc822_string", to_rfc822_string);
+ add_test("contains_all", contains_all);
add_test("equal_to", equal_to);
add_test("hash", hash);
}
@@ -52,6 +53,38 @@ class Geary.RFC822.MailboxAddressesTest : TestCase {
.to_rfc822_string() == "test1 example com, test2 example com");
}
+ public void contains_all() throws GLib.Error {
+ var mailboxes_a = new_addreses({ "test1 example com" });
+ var mailboxes_b = new_addreses({ "test1 example com" });
+ var mailboxes_c = new_addreses({ "test2 example com" });
+
+ assert_true(mailboxes_a.contains_all(mailboxes_a));
+ assert_true(mailboxes_a.contains_all(mailboxes_b));
+ assert_false(mailboxes_a.contains_all(mailboxes_c));
+
+ assert_true(
+ new_addreses({ "test1 example com", "test2 example com" }).contains_all(
+ new_addreses({ "test1 example com", "test2 example com" })
+ )
+ );
+ assert_true(
+ new_addreses({ "test1 example com", "test2 example com" }).contains_all(
+ new_addreses({ "test2 example com", "test1 example com" })
+ )
+ );
+
+ assert_false(
+ new_addreses({ "test1 example com", "test2 example com" }).contains_all(
+ new_addreses({ "test1 example com" })
+ )
+ );
+ assert_false(
+ new_addreses({ "test1 example com", "test2 example com" }).contains_all(
+ new_addreses({ "test1 example com", "test3 example com" })
+ )
+ );
+ }
+
public void equal_to() throws GLib.Error {
var mailboxes_a = new_addreses({ "test1 example com" });
var mailboxes_b = new_addreses({ "test1 example com" });
@@ -66,12 +99,11 @@ class Geary.RFC822.MailboxAddressesTest : TestCase {
new_addreses({ "test1 example com", "test2 example com" })
)
);
- assert_true(
+ assert_false(
new_addreses({ "test1 example com", "test2 example com" }).equal_to(
new_addreses({ "test2 example com", "test1 example com" })
)
);
-
assert_false(
new_addreses({ "test1 example com", "test2 example com" }).equal_to(
new_addreses({ "test1 example com" })
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]