1*f049f87fSNicolas Bonnefon #include "gmock/gmock.h" 2*f049f87fSNicolas Bonnefon 3*f049f87fSNicolas Bonnefon #include "config.h" 4*f049f87fSNicolas Bonnefon 5*f049f87fSNicolas Bonnefon #include "log.h" 6*f049f87fSNicolas Bonnefon 7*f049f87fSNicolas Bonnefon #include "data/linepositionarray.h" 8*f049f87fSNicolas Bonnefon 9*f049f87fSNicolas Bonnefon using namespace std; 10*f049f87fSNicolas Bonnefon using namespace testing; 11*f049f87fSNicolas Bonnefon 12*f049f87fSNicolas Bonnefon class LinePositionArraySmall: public testing::Test { 13*f049f87fSNicolas Bonnefon public: 14*f049f87fSNicolas Bonnefon LinePositionArray line_array; 15*f049f87fSNicolas Bonnefon 16*f049f87fSNicolas Bonnefon LinePositionArraySmall() { 17*f049f87fSNicolas Bonnefon line_array.append( 4 ); 18*f049f87fSNicolas Bonnefon line_array.append( 8 ); 19*f049f87fSNicolas Bonnefon line_array.append( 10 ); 20*f049f87fSNicolas Bonnefon } 21*f049f87fSNicolas Bonnefon }; 22*f049f87fSNicolas Bonnefon 23*f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, HasACorrectSize ) { 24*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 3 ) ); 25*f049f87fSNicolas Bonnefon } 26*f049f87fSNicolas Bonnefon 27*f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, RememberAddedLines ) { 28*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 29*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 30*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 10 ) ); 31*f049f87fSNicolas Bonnefon } 32*f049f87fSNicolas Bonnefon 33*f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, FakeLFisNotKeptWhenAddingAfterIt ) { 34*f049f87fSNicolas Bonnefon line_array.setFakeFinalLF(); 35*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 10 ) ); 36*f049f87fSNicolas Bonnefon line_array.append( 15 ); 37*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 15 ) ); 38*f049f87fSNicolas Bonnefon } 39*f049f87fSNicolas Bonnefon 40*f049f87fSNicolas Bonnefon class LinePositionArrayConcatOperation: public LinePositionArraySmall { 41*f049f87fSNicolas Bonnefon public: 42*f049f87fSNicolas Bonnefon LinePositionArray other_array; 43*f049f87fSNicolas Bonnefon 44*f049f87fSNicolas Bonnefon LinePositionArrayConcatOperation() { 45*f049f87fSNicolas Bonnefon other_array.append( 15 ); 46*f049f87fSNicolas Bonnefon other_array.append( 23 ); 47*f049f87fSNicolas Bonnefon } 48*f049f87fSNicolas Bonnefon }; 49*f049f87fSNicolas Bonnefon 50*f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayConcatOperation, SimpleConcat ) { 51*f049f87fSNicolas Bonnefon line_array += other_array; 52*f049f87fSNicolas Bonnefon 53*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 5 ) ); 54*f049f87fSNicolas Bonnefon 55*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 56*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 57*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 10 ) ); 58*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( 15 ) ); 59*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[4], Eq( 23 ) ); 60*f049f87fSNicolas Bonnefon } 61*f049f87fSNicolas Bonnefon 62*f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayConcatOperation, DoesNotKeepFakeLf ) { 63*f049f87fSNicolas Bonnefon line_array.setFakeFinalLF(); 64*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 10 ) ); 65*f049f87fSNicolas Bonnefon 66*f049f87fSNicolas Bonnefon line_array += other_array; 67*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 15 ) ); 68*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 4 ) ); 69*f049f87fSNicolas Bonnefon } 70*f049f87fSNicolas Bonnefon 71*f049f87fSNicolas Bonnefon class LinePositionArrayBig: public testing::Test { 72*f049f87fSNicolas Bonnefon public: 73*f049f87fSNicolas Bonnefon LinePositionArray line_array; 74*f049f87fSNicolas Bonnefon 75*f049f87fSNicolas Bonnefon LinePositionArrayBig() { 76*f049f87fSNicolas Bonnefon line_array.append( 4 ); 77*f049f87fSNicolas Bonnefon line_array.append( 8 ); 78*f049f87fSNicolas Bonnefon // A very big line 79*f049f87fSNicolas Bonnefon line_array.append( UINT32_MAX - 10 ); 80*f049f87fSNicolas Bonnefon line_array.append( UINT32_MAX + 10 ); 81*f049f87fSNicolas Bonnefon line_array.append( UINT32_MAX + 30 ); 82*f049f87fSNicolas Bonnefon } 83*f049f87fSNicolas Bonnefon }; 84*f049f87fSNicolas Bonnefon 85*f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBig, IsTheRightSize ) { 86*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), 5 ); 87*f049f87fSNicolas Bonnefon } 88*f049f87fSNicolas Bonnefon 89*f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBig, HasRightData ) { 90*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 91*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 92*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( UINT32_MAX - 10 ) ); 93*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( UINT32_MAX + 10 ) ); 94*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[4], Eq( UINT32_MAX + 30 ) ); 95*f049f87fSNicolas Bonnefon } 96*f049f87fSNicolas Bonnefon 97*f049f87fSNicolas Bonnefon class LinePositionArrayBigConcat: public testing::Test { 98*f049f87fSNicolas Bonnefon public: 99*f049f87fSNicolas Bonnefon LinePositionArray line_array; 100*f049f87fSNicolas Bonnefon LinePositionArray other_array; 101*f049f87fSNicolas Bonnefon 102*f049f87fSNicolas Bonnefon LinePositionArrayBigConcat() { 103*f049f87fSNicolas Bonnefon line_array.append( 4 ); 104*f049f87fSNicolas Bonnefon line_array.append( 8 ); 105*f049f87fSNicolas Bonnefon 106*f049f87fSNicolas Bonnefon other_array.append( UINT32_MAX + 10 ); 107*f049f87fSNicolas Bonnefon other_array.append( UINT32_MAX + 30 ); 108*f049f87fSNicolas Bonnefon } 109*f049f87fSNicolas Bonnefon }; 110*f049f87fSNicolas Bonnefon 111*f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBigConcat, SimpleBigConcat ) { 112*f049f87fSNicolas Bonnefon line_array += other_array; 113*f049f87fSNicolas Bonnefon 114*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 4 ) ); 115*f049f87fSNicolas Bonnefon 116*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 117*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 118*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( UINT32_MAX + 10 ) ); 119*f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( UINT32_MAX + 30 ) ); 120*f049f87fSNicolas Bonnefon } 121