Mirror of github.com/gissleh/irc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
9.9 KiB

4 years ago
4 years ago
  1. package ircutil_test
  2. import (
  3. "fmt"
  4. "strings"
  5. "testing"
  6. "github.com/gissleh/irc/ircutil"
  7. )
  8. func TestCuts(t *testing.T) {
  9. t.Log("Testing that long messages can be cut up and put back together, and that no cut is greater than 510 - overhead")
  10. table := []struct {
  11. Overhead int
  12. Space bool
  13. Text string
  14. }{
  15. {
  16. ircutil.MessageOverhead("Longer_Name", "mircuser", "some-long-hostname-from-some-isp.com", "#Test", true), true,
  17. "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed maximus urna eu tincidunt lacinia. Morbi malesuada lacus placerat, ornare tellus a, scelerisque nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam placerat sem aliquet elit pharetra consectetur. Pellentesque ultrices turpis erat, et ullamcorper magna blandit vitae. Morbi aliquam, turpis at dictum hendrerit, mi urna mattis mi, non vulputate ligula sapien non urna. Nulla sed lorem lorem. Proin auctor ante et ligula aliquam lacinia. Sed pretium lacinia varius. Donec urna nibh, aliquam at metus ac, lobortis venenatis sem. Etiam et risus pellentesque diam faucibus faucibus. Vestibulum ornare, erat sit amet dapibus eleifend, arcu erat consectetur enim, id posuere ipsum enim eget metus. Aliquam erat volutpat. Nunc eget neque suscipit nisl fermentum hendrerit. Suspendisse congue turpis non tortor fermentum, vulputate egestas nibh tristique. Sed purus purus, pharetra ac luctus ut, accumsan et enim. Quisque lacus tellus, ullamcorper eu lacus aliquet, facilisis sodales mauris. Quisque fringilla, odio quis laoreet sagittis, urna leo commodo urna, eu auctor arcu arcu ac nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse accumsan leo sed sollicitudin dignissim. Aliquam et facilisis turpis. Morbi finibus nisi ut elit eleifend cursus. Donec eu imperdiet nulla. Vestibulum eget varius dui. Morbi dapibus leo sit amet ipsum porta, et volutpat lectus condimentum. Integer nec mi dui. Suspendisse ac tortor et tortor tempus imperdiet. Aenean erat ante, ultricies eget blandit eu, sollicitudin vel nibh. Vestibulum eget dolor urna. Proin sit amet nulla eu urna dictum dignissim. Nulla sit amet velit eu magna feugiat ultricies. Sed venenatis rutrum urna quis malesuada. Curabitur pretium molestie mi eget aliquam. Sed eget est non sem ornare tincidunt. Vestibulum mollis ultricies tellus sit amet fringilla. Vestibulum quam est, blandit venenatis iaculis id, bibendum sit amet purus. Nullam laoreet pellentesque vulputate. Curabitur porttitor massa justo, id pharetra purus ultricies et. Aliquam finibus molestie turpis quis mattis. Nulla pretium mauris dolor, quis porta arcu pulvinar eu. Nam tincidunt ac odio in hendrerit. Pellentesque elementum porttitor dui, at laoreet erat ultrices at. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed porttitor libero magna, vitae malesuada sapien blandit ut. Maecenas tempor auctor tortor eu mollis. Integer tempus mollis euismod. Nunc ligula ligula, dignissim sit amet tempor eget, pharetra lobortis risus. Ut ut libero risus. Integer tempus mauris nec quam volutpat tristique. Maecenas id lacus et metus condimentum placerat. Vestibulum eget mauris eros. Nulla sollicitudin libero id dui imperdiet, at ornare nibh sollicitudin. Pellentesque laoreet mollis nunc aliquam interdum. Phasellus egestas suscipit turpis in laoreet.",
  18. },
  19. {
  20. ircutil.MessageOverhead("=Scene=", "SceneAuthor", "npc.fakeuser.invalid", "#LongChannelName32", false), true,
  21. "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum..",
  22. },
  23. {
  24. ircutil.MessageOverhead("=Scene=", "Gissleh", "npc.fakeuser.invalid", "#Channel3", false), true,
  25. "A really short message that will not be cut.",
  26. },
  27. {
  28. ircutil.MessageOverhead("=Scene=", "Gissleh", "npc.fakeuser.invalid", "#Channel3", false), false,
  29. "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  30. },
  31. {
  32. ircutil.MessageOverhead("=Scene=", "Gissleh", "npc.fakeuser.invalid", "#Channel3", false), false,
  33. // It's just japanese lorem ipsun just to see that multi-byte runes don't get cut wrong.
  34. "弟ノネセ設35程カメ分軽談オイヲ趣英シ破与預ニ細試かゅ給桐やんぱ新交エムイ招地なる稿訓誘入倒がぞょあ9未わの表画フ標係暖りかす権邦ざらびフ第木庭げ司第すに芸型ず内兼んほでな答将携きあ大念じぽろ状表そむぞ販ぜひゆべ万53火6飾び付界ー兵供コ援仕シチヲ決表ウユアエ生記続ヌ金見貢ユ相帯ソ問禁ンる盟策れとぞの難屋セアヌネ記由僚ど物2理シホヤニ数重くむも米ヱ給辞めつへ長順チ稿転地ヌラヒエ稿横イ検地えつずた質信ヘヨ電本タウ測30終真いず章年雪しあすそ済座づずら期出必ツエキハ色罪ょイえ再危ケトリヘ東宅ちんり京倒停塚称ひほぱ報ワモネ意取やま画支完ユヱホ一崎そく子聞ハシ始家文なリさ新誕えぱつ渡講ニ著今就せド観3判成トフケユ食別ゆ績生タ告候ざンちぐ芸部幸績養はそを評ぶラ路2十ぐるッー本米ぼ新性うひゆ詠持ほかな測委もめべに犯九だへほう金作かドえは民53棋倉1無タウコフ真読おだぼ重訃壮憶軒研てだざ火皇テミヘユ関評レクな記本ラ日設識こへぎ読認水リるっ定件ラリレロ裁写フ記気やい縦写ヤコロ糸取ニワ金朝ウルオ世康でてめ氷諭ソフ副際ロワ念促縮繰やだつせ重身ケ容6契竹せぴま法能れ改長ひ出葉チソユ得4帯ツキヤホ込養フハケス言杯ネ策振オセメヘ合億育閥班綸諮らせ算甲ミカ夕支フ疲水ナ度先稿テ定特ぴ問触べ陸月は販93作意ぱへ以分げらご算路亡とスひ歓にレ完指リ覧論ぱょ中審ロ期旨ヲメヘケ記言ク構早べ埼組党高雄ぽ館世ウ通画ケ裁督え隆学びいゅ交利ヤトワ宮81明よ員乞伍ゅず更ナヲ士座ヘモレホ意有イリル表半ほラ採政イテ判募相37一対て配小ウオ広更モケヘヲ山週ト難覚ホセク小届角み3読コロ返立クあまゆ探気休るけをこ安金る展無にりひ聞説ね我郎みゆめ左州フメチヘ気席ん見夏くフには的8実ヒカ表更フ世教聞ロハヒウ引康ばぽわク見測希動五トしげ囲ニ通2政済キ少罪づあふ止政せげイ四内ラ劇中題ホ感負んけーゅ際禁オテ等鳥通県的せ議19賠ヒヌニ止牛気ぞぴわょ出来をるおぴ覧5法ヒヱウ金断舞つ発都芸トユ買将カテ需覧ほごレラ必鈴ト部部エムモ無学りぎ掲死お化もと康集ひ頼禁モツサ覧能べばゆぐ工9奪御セテキリ時者ゆちな美録江レユチウ誠遺目モヲ更新ふあぽら読時り問特リナケク子活マネオリ彌個べざを理時ずルゃ身払縄びひ学粉捜ワニヲ遂題ル読8野ネリユ世検顔るごかラ作類べ並90弟意リルづゆ証利ミ止9年フ細協づつ件ドつっお友載モヤヌ占教オ国射ホク部措昨ょげ初勝鋭ヒテワハ女実ゅおねて意情ろく性市へちイぱ務哲れんてか暮両ゆごこ今節ライげ向タ歩56崎っフゆ庭教ぞめ舞吉タ作道マノ報康エモチニ決欲トヨ棋郵産サレ挙写ル胸覚エネ心耀るざラぱ陽高ネメテ以査ず盾際ハセヌツ領証ルミヌ無不レセエナ同可析ドずと降月ず自八ヨロナ避詐ドか月買ばこ姿徴ぱ遺6低2紆囲へぽもに権場ひおもわ芋首とごも然得まや点人三ぶ改在ネノヘ時式頑威敵はつく在う協完ふリ大殺をり容賃エ更50事ワマ木再クびド康決転場コリ上初ミイヱ山第ま費禁トぼをぐ童載私海陸ね佐なぶゃ早五税イミホ話秋情ト発窃ね替究エコ郎著心ホ編今セシルウ金4本サヨ設中学ざど容迷もそ記主サツカ都枝ぐ哲速ご踊大にど短マラフチ理玉めフど展掲ばょい皿4題ゅっスぼ性五形53討ごぜン満給ユナツ人不ぼずス全読ゅやみろ赤95俣妃巳ス原安イ球竹ッょごせ向審ラルサ波野ゃ約球やむリぎ神情21就オサチ覧見式で所雑
  35. },
  36. }
  37. sep := map[bool]string{false: "", true: " "}
  38. for i, row := range table {
  39. t.Run(fmt.Sprintf("Row_%d", i), func(t *testing.T) {
  40. cuts := ircutil.CutMessage(row.Text, row.Overhead)
  41. joined := strings.Join(cuts, sep[row.Space])
  42. for i, cut := range cuts {
  43. t.Logf("Length %d: %d", i, len(cut))
  44. t.Logf("Cut %d: %s", i, cut)
  45. if len(cut) > (510 - row.Overhead) {
  46. t.Error("Cut was too long")
  47. }
  48. }
  49. if joined != row.Text {
  50. t.Error("Cut failed:")
  51. t.Error(" Result:", joined)
  52. t.Error(" Expected:", row.Text)
  53. }
  54. })
  55. }
  56. }