From 63bf28de08ec04158d55d43562363bffc3ee7193 Mon Sep 17 00:00:00 2001 From: Craftplacer <22963120+Craftplacer@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:04:38 +0100 Subject: [PATCH] fix: fix name_merging_test.dart --- src/kaiteki/lib/utils/name_merging.dart | 3 +++ src/kaiteki/test/name_merging_test.dart | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/kaiteki/lib/utils/name_merging.dart b/src/kaiteki/lib/utils/name_merging.dart index 7b015a7c..a9fdcaa6 100644 --- a/src/kaiteki/lib/utils/name_merging.dart +++ b/src/kaiteki/lib/utils/name_merging.dart @@ -7,6 +7,9 @@ MergedName? mergeNameOfUser(User user) { return mergeName(user.displayName, user.username, user.host); } +/// Merges a display name with a username and host. +/// +/// Returns `null` if the names cannot be merged. MergedName? mergeName(String? displayName, String username, String host) { final name = displayName ?? username; final normalizedDisplay = name.toLowerCase().trim(); diff --git a/src/kaiteki/test/name_merging_test.dart b/src/kaiteki/test/name_merging_test.dart index 4e85971d..f95536d6 100644 --- a/src/kaiteki/test/name_merging_test.dart +++ b/src/kaiteki/test/name_merging_test.dart @@ -1,15 +1,27 @@ import "package:kaiteki/utils/name_merging.dart"; +import "package:kaiteki_core/model.dart"; import "package:test/test.dart"; void main() { test("separated", () { - final content = mergeName("Wonderful Alice", "alice", "example.org"); - expect(content, isNotNull); - expect(content!.$2, equals("@alice@example.org")); + const user = User( + id: "", + displayName: "Wonderful Alice", + username: "alice", + host: "example.org", + ); + final content = mergeNameOfUser(user); + expect(content, isNull); }); test("unseparated", () { - final content = mergeName("Alice", "alice", "example.org"); + const user = User( + id: "", + displayName: "Alice", + username: "alice", + host: "example.org", + ); + final content = mergeNameOfUser(user); expect(content, isNotNull); expect(content!.$1, equals("Alice")); expect(content.$2, equals("@example.org"));