1/* 2 * Copyright © 2018 A Bunch Tell LLC. 3 * 4 * This file is part of WriteFreely. 5 * 6 * WriteFreely is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License, included 8 * in the LICENSE file in this source code package. 9 */ 10 11package parse 12 13import "testing" 14 15func TestPostLede(t *testing.T) { 16 text := map[string]string{ 17 "早安。跨出舒適圈,才能前往": "早安。", 18 "早安。This is my post. It is great.": "早安。", 19 "Hello. 早安。": "Hello.", 20 "Sup? Everyone says punctuation is punctuation.": "Sup?", 21 "Humans are humans, and society is full of good and bad actors. Technology, at the most fundamental level, is a neutral tool that can be used by either to meet any ends. ": "Humans are humans, and society is full of good and bad actors.", 22 `Online Domino Is Must For Everyone 23 24 Do you want to understand how to play poker online?`: "Online Domino Is Must For Everyone", 25 `おはようございます 26 27 私は日本から帰ったばかりです。`: "おはようございます", 28 "Hello, we say, おはよう. We say \"good morning\"": "Hello, we say, おはよう.", 29 } 30 31 c := 1 32 for i, o := range text { 33 if s := PostLede(i, true); s != o { 34 t.Errorf("#%d: Got '%s' from '%s'; expected '%s'", c, s, i, o) 35 } 36 c++ 37 } 38} 39 40func TestTruncToWord(t *testing.T) { 41 text := map[string]string{ 42 "Можливо, ми можемо використовувати інтернет-інструменти, щоб виготовити якийсь текст, який би міг бути і на, і в кінцевому підсумку, буде скорочено, тому що це тривало так довго.": "Можливо, ми можемо використовувати інтернет-інструменти, щоб виготовити якийсь", 43 "早安。This is my post. It is great. It is a long post that is great that is a post that is great.": "早安。This is my post. It is great. It is a long post that is great that is a post", 44 "Sup? Everyone says punctuation is punctuation.": "Sup? Everyone says punctuation is punctuation.", 45 "I arrived in Japan six days ago. Tired from a 10-hour flight after a night-long layover in Calgary, I wandered wide-eyed around Narita airport looking for an ATM.": "I arrived in Japan six days ago. Tired from a 10-hour flight after a night-long", 46 } 47 48 c := 1 49 for i, o := range text { 50 if s, _ := TruncToWord(i, 80); s != o { 51 t.Errorf("#%d: Got '%s' from '%s'; expected '%s'", c, s, i, o) 52 } 53 c++ 54 } 55} 56