1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
;;; erc-scenarios-base-split-line.el --- ERC line splitting -*- lexical-binding: t -*-
;; Copyright (C) 2023-2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert-x)
(eval-and-compile
(let ((load-path (cons (ert-resource-directory) load-path)))
(require 'erc-scenarios-common)))
(ert-deftest erc-scenarios-base-split-line--koi8-r ()
:tags '(:expensive-test)
(should (equal erc-split-line-length 440))
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "base/flood")
(erc-server-flood-penalty 0.1)
(dumb-server (erc-d-run "localhost" t 'koi8-r))
(erc-encoding-coding-alist '(("#koi8" . cyrillic-koi8)))
(port (process-contact dumb-server :service))
(expect (erc-d-t-make-expecter)))
(ert-info ("Connect to server")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:nick "tester"
:full-name "tester")
(funcall expect 10 "debug mode")
(erc-cmd-JOIN "#koi8")))
(with-current-buffer (erc-d-t-wait-for 8 (get-buffer "#koi8"))
(funcall expect 10 "короче теперь")
(ert-info ("Message well within `erc-split-line-length'")
(erc-scenarios-common-say
(concat
"короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"))
(funcall expect 1 "<tester>")
(funcall expect -0.1 "<tester>"))
(ert-info ("Message over `erc-split-line-length'")
(erc-scenarios-common-say
(concat
"короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" будет разрыв строки непонятно где"))
(funcall expect 1 "<tester>")
(funcall expect 1 "<tester> разрыв")))
(with-current-buffer "foonet"
(erc-cmd-QUIT "")
(funcall expect 10 "finished"))))
(ert-deftest erc-scenarios-base-split-line--ascii ()
:tags '(:expensive-test)
(should (equal erc-split-line-length 440))
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "base/flood")
(msg-432 (string-join (make-list 18 "twenty-three characters") " "))
(erc-server-flood-penalty 0.1)
(dumb-server (erc-d-run "localhost" t 'ascii))
(port (process-contact dumb-server :service))
(expect (erc-d-t-make-expecter)))
(ert-info ("Connect to server")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:nick "tester"
:full-name "tester")
(funcall expect 10 "debug mode")
(erc-cmd-JOIN "#ascii")))
(with-current-buffer (erc-d-t-wait-for 8 (get-buffer "#ascii"))
(ert-info ("Message with spaces fits exactly")
(funcall expect 10 "Welcome")
(should (= (length (concat msg-432 " 12345678")) 440))
(erc-scenarios-common-say (concat msg-432 " 12345678"))
(funcall expect 1 "<tester>")
;; Sent in a single go, hence no second <speaker>.
(funcall expect -0.1 "<tester>")
(funcall expect 0.1 "12345678"))
(ert-info ("Message with spaces too long.")
(erc-scenarios-common-say (concat msg-432 " 123456789"))
(funcall expect 1 "<tester>")
;; Sent in two passes, split at last word.
(funcall expect 0.1 "<tester> 123456789"))
(ert-info ("Message sans spaces fits exactly")
(erc-scenarios-common-say (make-string 440 ?x))
(funcall expect 1 "<tester>")
;; Sent in a single go, hence no second <speaker>.
(funcall expect -0.1 "<tester>"))
(ert-info ("Message sans spaces too long.")
(erc-scenarios-common-say (concat (make-string 440 ?y) "z"))
(funcall expect 1 "<tester>")
;; Sent in two passes, split at last word.
(funcall expect 0.1 "<tester> z"))
(ert-info ("Rejected when escape-hatch set")
(let ((erc--reject-unbreakable-lines t))
(should-error
(erc-scenarios-common-say
(concat
"https://mail.example.org/verify?token="
(string-join (make-list 18 "twenty-three_characters") "_")))))))
(with-current-buffer "foonet"
(erc-cmd-QUIT "")
(funcall expect 10 "finished"))))
(ert-deftest erc-scenarios-base-split-line--utf-8 ()
:tags '(:expensive-test)
(unless (> emacs-major-version 27)
(ert-skip "No emojis in Emacs 27"))
(should (equal erc-split-line-length 440))
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "base/flood")
(msg-432 (string-join (make-list 18 "twenty-three characters") " "))
(erc-server-flood-penalty 0.1)
(dumb-server (erc-d-run "localhost" t 'utf-8))
(port (process-contact dumb-server :service))
(expect (erc-d-t-make-expecter)))
(ert-info ("Connect to server")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:nick "tester"
:full-name "tester")
(funcall expect 10 "debug mode")
(erc-cmd-JOIN "#utf-8")))
(with-current-buffer (erc-d-t-wait-for 8 (get-buffer "#utf-8"))
(funcall expect 10 "Welcome")
(ert-info ("Message with spaces over `erc-split-line-length'")
(erc-scenarios-common-say
(concat
"короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" короче теперь если по русски написать все четко или все равно"
" будет разрыв строки непонятно где"
" будет разрыв строки непонятно где"))
(funcall expect 1 "<tester> короче")
(funcall expect 1 "<tester> все")
(funcall expect 1 "<tester> разрыв")
(funcall expect 1 "Entirely honour"))
(ert-info ("Message sans spaces over `erc-split-line-length'")
(erc-scenarios-common-say
(concat "話說天下大勢,分久必合,合久必分:周末七國分爭,并入於秦。"
"及秦滅之後,楚、漢分爭,又并入於漢。漢朝自高祖斬白蛇而起義,"
"一統天下。後來光武中興,傳至獻帝,遂分為三國。推其致亂之由,"
"殆始於桓、靈二帝。桓帝禁錮善類,崇信宦官。及桓帝崩,靈帝即位,"
"大將軍竇武、太傅陳蕃,共相輔佐。時有宦官曹節等弄權,竇武、陳蕃謀誅之,"
"作事不密,反為所害。中涓自此愈橫"))
(funcall expect 1 "<tester>")
;; Sent in two passes, split at last word.
(funcall expect 0.1 "<tester> 竇武")
(funcall expect 1 "this prey out"))
;; Combining emojis are respected.
(ert-info ("Message sans spaces over small `erc-split-line-length'")
(let ((erc-split-line-length 100))
(erc-scenarios-common-say
"будет разрыв строки непонятно где🏁🚩🎌🏴🏳️🏳️🌈🏳️⚧️🏴☠️"))
(funcall expect 1 "<tester>")
(funcall expect 1 "<tester> 🏳️🌈")))
(with-current-buffer "foonet"
(erc-cmd-QUIT "")
(funcall expect 10 "finished"))))
;;; erc-scenarios-base-split-line.el ends here
|