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