2015-12-29 10:47:22 +00:00
# include <gmock/gmock.h>
2015-12-29 15:26:01 +00:00
# include "stringTools.h"
2015-12-29 10:47:22 +00:00
using namespace testing ;
// 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 ) {
const char * lipsum = " Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. " ;
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 " , " " ) ) ;
}