AtlatestRepositorysigil-irc
1
;;; Tests for nick@server-domain qualified identity3
(import (sigil test)4
(sigil irc identity))6
(test-group "IRC Identity"8
(test-group "construction"10
(test "make-irc-identity downcases server"11
(let ((id (make-irc-identity "Alice" "Enclave.Example")))12
(assert-equal "Alice" (irc-identity-nick id))13
(assert-equal "enclave.example" (irc-identity-server id))))15
(test "rejects empty nick"16
(assert-error (make-irc-identity "" "enclave.example")))18
(test "rejects empty server"19
(assert-error (make-irc-identity "alice" ""))))22
(test-group "canonical / display"24
(test "canonical form"25
(assert-equal "[email protected]"26
(irc-identity->canonical27
(make-irc-identity "alice" "enclave.example"))))29
(test "default display drops server"30
(assert-equal "alice"31
(irc-identity->display32
(make-irc-identity "alice" "enclave.example"))))34
(test "display with show-server? gives canonical"35
(assert-equal "[email protected]"36
(irc-identity->display37
(make-irc-identity "alice" "enclave.example")38
show-server?: #t))))41
(test-group "equality"43
(test "case-insensitive nick"44
(assert-true (irc-identity=?45
(make-irc-identity "Alice" "enclave.example")46
(make-irc-identity "alice" "enclave.example"))))48
(test "exact server match"49
(assert-true (irc-identity=?50
(make-irc-identity "alice" "Enclave.Example")51
(make-irc-identity "alice" "enclave.example"))))53
(test "different servers are unequal"54
(assert-false (irc-identity=?55
(make-irc-identity "alice" "enclave.example")56
(make-irc-identity "alice" "other.example")))))59
(test-group "parse-irc-identity"61
(test "parses canonical form"62
(let ((id (parse-irc-identity "[email protected]")))63
(assert-true id)64
(assert-equal "alice" (irc-identity-nick id))65
(assert-equal "enclave.example" (irc-identity-server id))))67
(test "rejects bare nick (no @)"68
(assert-equal #f (parse-irc-identity "alice")))70
(test "rejects empty nick"71
(assert-equal #f (parse-irc-identity "@enclave.example")))73
(test "rejects empty server"74
(assert-equal #f (parse-irc-identity "alice@")))76
(test "rejects multiple @"77
(assert-equal #f (parse-irc-identity "a@b@c"))))80
(test-group "irc-display-strip-server"82
(test "strips suffix"83
(assert-equal "alice" (irc-display-strip-server "[email protected]")))85
(test "passes bare nick through"86
(assert-equal "alice" (irc-display-strip-server "alice"))))89
(test-group "irc-identity-from-prefix"91
(test "qualifies with given server-domain"92
(let ((id (irc-identity-from-prefix "alice" "enclave.example")))93
(assert-true id)94
(assert-equal "alice" (irc-identity-nick id))95
(assert-equal "enclave.example" (irc-identity-server id))))97
(test "returns #f for missing nick"98
(assert-equal #f (irc-identity-from-prefix #f "enclave.example")))))100
(run-tests)