2016-06-02 18:09:37 +00:00
# include < gmock / gmock . h >
2017-09-10 20:17:17 +00:00
# include "tools/stringTools.h"
2015-12-29 10:47:22 +00:00
using namespace testing ;
2016-06-02 18:09:37 +00:00
using std : : string ;
2016-06-02 20:21:37 +00:00
using std : : wstring ;
2015-12-29 10:47:22 +00:00
// splitIntoLines
TEST ( splitIntoLines , splitsOnLineBreaks ) {
EXPECT_THAT ( splitIntoLines ( " this \n is \r \n a \r \n test " ) , ElementsAre ( " this " , " is " , " a " , " test " ) ) ;
}
TEST ( splitIntoLines , handlesEmptyElements ) {
EXPECT_THAT ( splitIntoLines ( " \n 1 \n \n \n 2 \n " ) , ElementsAre ( " " , " 1 " , " " , " " , " 2 " , " " ) ) ;
EXPECT_THAT ( splitIntoLines ( " \n " ) , ElementsAre ( " " , " " ) ) ;
EXPECT_THAT ( splitIntoLines ( " " ) , ElementsAre ( " " ) ) ;
}
// wrapSingleLineString
TEST ( wrapSingleLineString , basic ) {
2019-01-02 19:00:34 +00:00
const char * lipsum =
" Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. " ;
2015-12-29 10:47:22 +00:00
EXPECT_THAT ( wrapSingleLineString ( lipsum , 30 ) , ElementsAre ( " Lorem ipsum dolor sit amet, " , " consectetur adipisici elit, " , " sed eiusmod tempor incidunt ut " , " labore et dolore magna aliqua. " ) ) ;
}
TEST ( wrapSingleLineString , preciseWrapPosition ) {
const char * test = " a b c " ;
EXPECT_THAT ( wrapSingleLineString ( test , 5 ) , ElementsAre ( " a b c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 4 ) , ElementsAre ( " a b " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 3 ) , ElementsAre ( " a b " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 2 ) , ElementsAre ( " a " , " b " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 1 ) , ElementsAre ( " a " , " b " , " c " ) ) ;
}
TEST ( wrapSingleLineString , overlongLines ) {
EXPECT_THAT ( wrapSingleLineString ( " aaa bbbb ccc " , 3 ) , ElementsAre ( " aaa " , " bbb " , " b " , " ccc " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( " aaa bbbb c " , 3 ) , ElementsAre ( " aaa " , " bbb " , " b c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( " a bbbb c " , 5 ) , ElementsAre ( " a " , " bbbb " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( " aa b " , 1 ) , ElementsAre ( " a " , " a " , " b " ) ) ;
}
TEST ( wrapSingleLineString , discardingSpacesAtWrapPositionsAndEnd ) {
const char * test = " a b c " ;
EXPECT_THAT ( wrapSingleLineString ( test , 20 ) , ElementsAre ( " a b c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 6 ) , ElementsAre ( " a b " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 5 ) , ElementsAre ( " a " , " b c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 4 ) , ElementsAre ( " a " , " b c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 3 ) , ElementsAre ( " a " , " b " , " c " ) ) ;
EXPECT_THAT ( wrapSingleLineString ( test , 2 ) , ElementsAre ( " " , " a " , " b " , " c " ) ) ;
}
TEST ( wrapSingleLineString , errorHandling ) {
EXPECT_NO_THROW ( wrapSingleLineString ( " test " , 1 ) ) ;
EXPECT_NO_THROW ( wrapSingleLineString ( " " , 1 ) ) ;
// Throw if lineLength < 1
EXPECT_ANY_THROW ( wrapSingleLineString ( " test " , 0 ) ) ;
EXPECT_ANY_THROW ( wrapSingleLineString ( " " , 0 ) ) ;
EXPECT_ANY_THROW ( wrapSingleLineString ( " test " , - 1 ) ) ;
EXPECT_ANY_THROW ( wrapSingleLineString ( " " , - 1 ) ) ;
// Throw if string contains tabs
EXPECT_ANY_THROW ( wrapSingleLineString ( " a \t b " , 10 ) ) ;
// Throw if string contains line breaks
EXPECT_ANY_THROW ( wrapSingleLineString ( " a \n b " , 10 ) ) ;
}
// wrapString
TEST ( wrapString , basic ) {
EXPECT_THAT ( wrapString ( " \n \n Line no 3 \n \n Line no 4 \n " , 8 ) , ElementsAre ( " " , " " , " Line no " , " 3 " , " " , " Line no " , " 4 " , " " ) ) ;
}
2016-06-02 20:21:37 +00:00
// latin1ToWide
TEST ( latin1ToWide , basic ) {
2019-01-02 19:00:34 +00:00
const string pangramLatin1 =
" D \350 s No \353 l o \371 un z \351 phyr ha \357 me v \352 t de gla \347 ons w \374 rmiens, je d \356 ne d'exquis r \364 tis de boeuf au kir \340 l'a \377 d' \342 ge m \373 r & c \346 tera! " ;
wstring pangramWide =
L " Dès Noël où un zéphyr haï me vêt de glaçons würmiens, je dîne d'exquis rôtis de boeuf au kir à l'aÿ d'âge mûr & cætera! " ;
2016-06-02 20:21:37 +00:00
EXPECT_EQ ( pangramWide , latin1ToWide ( pangramLatin1 ) ) ;
}
2017-08-15 18:47:05 +00:00
// utf8ToAscii
2016-06-02 18:09:37 +00:00
2017-08-15 18:47:05 +00:00
TEST ( utf8ToAscii , string ) {
2016-06-02 18:09:37 +00:00
EXPECT_EQ (
" A naive man called was having pina colada and creme brulee. " ,
2017-08-15 18:47:05 +00:00
utf8ToAscii ( " A naïve man called 晨 was having piña colada and crème brûlée. " ) ) ;
EXPECT_EQ ( string ( " " ) , utf8ToAscii ( " " ) ) ;
EXPECT_EQ ( string ( " - - - - - - - - - - " ) , utf8ToAscii ( " - ‐ ‑ ‒ – — ― ﹘ ﹣ - " ) ) ;
EXPECT_EQ ( string ( " ' ' ' ' \" \" \" \" \" \" " ) , utf8ToAscii ( " ‘ ’ ‚ ‛ “ ” „ ‟ « »" ) ) ;
EXPECT_EQ ( string ( " 1 2 3 " ) , utf8ToAscii ( " ¹ ² ³ " ) ) ;
EXPECT_EQ ( string ( " 1/4 1/2 3/4 " ) , utf8ToAscii ( " ¼ ½ ¾ " ) ) ;
2016-06-02 18:09:37 +00:00
}