Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: fix name_merging_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Craftplacer committed Feb 4, 2024
1 parent f62850e commit 63bf28d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/kaiteki/lib/utils/name_merging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 16 additions & 4 deletions src/kaiteki/test/name_merging_test.dart
Original file line number Diff line number Diff line change
@@ -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"));
Expand Down

0 comments on commit 63bf28d

Please sign in to comment.