xref: /glogg/tests/linepositionarrayTest.cpp (revision f049f87fc315bc7e68fc0a52b15c5b79496761d2)
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     }
21 };
22 
23 TEST_F( LinePositionArraySmall, HasACorrectSize ) {
24     ASSERT_THAT( line_array.size(), Eq( 3 ) );
25 }
26 
27 TEST_F( LinePositionArraySmall, RememberAddedLines ) {
28     ASSERT_THAT( line_array[0], Eq( 4 ) );
29     ASSERT_THAT( line_array[1], Eq( 8 ) );
30     ASSERT_THAT( line_array[2], Eq( 10 ) );
31 }
32 
33 TEST_F( LinePositionArraySmall, FakeLFisNotKeptWhenAddingAfterIt ) {
34     line_array.setFakeFinalLF();
35     ASSERT_THAT( line_array[2], Eq( 10 ) );
36     line_array.append( 15 );
37     ASSERT_THAT( line_array[2], Eq( 15 ) );
38 }
39 
40 class LinePositionArrayConcatOperation: public LinePositionArraySmall {
41   public:
42     LinePositionArray other_array;
43 
44     LinePositionArrayConcatOperation() {
45         other_array.append( 15 );
46         other_array.append( 23 );
47     }
48 };
49 
50 TEST_F( LinePositionArrayConcatOperation, SimpleConcat ) {
51     line_array += other_array;
52 
53     ASSERT_THAT( line_array.size(), Eq( 5 ) );
54 
55     ASSERT_THAT( line_array[0], Eq( 4 ) );
56     ASSERT_THAT( line_array[1], Eq( 8 ) );
57     ASSERT_THAT( line_array[2], Eq( 10 ) );
58     ASSERT_THAT( line_array[3], Eq( 15 ) );
59     ASSERT_THAT( line_array[4], Eq( 23 ) );
60 }
61 
62 TEST_F( LinePositionArrayConcatOperation, DoesNotKeepFakeLf ) {
63     line_array.setFakeFinalLF();
64     ASSERT_THAT( line_array[2], Eq( 10 ) );
65 
66     line_array += other_array;
67     ASSERT_THAT( line_array[2], Eq( 15 ) );
68     ASSERT_THAT( line_array.size(), Eq( 4 ) );
69 }
70 
71 class LinePositionArrayBig: public testing::Test {
72   public:
73     LinePositionArray line_array;
74 
75     LinePositionArrayBig() {
76         line_array.append( 4 );
77         line_array.append( 8 );
78         // A very big line
79         line_array.append( UINT32_MAX - 10 );
80         line_array.append( UINT32_MAX + 10 );
81         line_array.append( UINT32_MAX + 30 );
82     }
83 };
84 
85 TEST_F( LinePositionArrayBig, IsTheRightSize ) {
86     ASSERT_THAT( line_array.size(), 5 );
87 }
88 
89 TEST_F( LinePositionArrayBig, HasRightData ) {
90     ASSERT_THAT( line_array[0], Eq( 4 ) );
91     ASSERT_THAT( line_array[1], Eq( 8 ) );
92     ASSERT_THAT( line_array[2], Eq( UINT32_MAX - 10 ) );
93     ASSERT_THAT( line_array[3], Eq( UINT32_MAX + 10 ) );
94     ASSERT_THAT( line_array[4], Eq( UINT32_MAX + 30 ) );
95 }
96 
97 class LinePositionArrayBigConcat: public testing::Test {
98   public:
99     LinePositionArray line_array;
100     LinePositionArray other_array;
101 
102     LinePositionArrayBigConcat() {
103         line_array.append( 4 );
104         line_array.append( 8 );
105 
106         other_array.append( UINT32_MAX + 10 );
107         other_array.append( UINT32_MAX + 30 );
108     }
109 };
110 
111 TEST_F( LinePositionArrayBigConcat, SimpleBigConcat ) {
112     line_array += other_array;
113 
114     ASSERT_THAT( line_array.size(), Eq( 4 ) );
115 
116     ASSERT_THAT( line_array[0], Eq( 4 ) );
117     ASSERT_THAT( line_array[1], Eq( 8 ) );
118     ASSERT_THAT( line_array[2], Eq( UINT32_MAX + 10 ) );
119     ASSERT_THAT( line_array[3], Eq( UINT32_MAX + 30 ) );
120 }
121