~aleteoryx/muditaos

ref: 44d3306f280cc7d6daa718d2a9f6323e48f54616 muditaos/module-gui/test/test-catch-text/test-gui-TextLinesCursor.cpp -rw-r--r-- 29.7 KiB
44d3306f — rrandomsky [CP-1059] Fix for erase only sensitive data from logs 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <widgets/text/Text.hpp>
#include "Font.hpp"
#include "InitializedFontManager.hpp"

#include <catch2/catch.hpp>

namespace gui
{
    class TestText : public Text
    {
      public:
        [[nodiscard]] unsigned int linesVisible()
        {
            return lines->countVisible();
        }

        [[nodiscard]] auto &linesGet()
        {
            return lines->get();
        }

        auto moveCursor(NavigationDirection direction, unsigned int n)
        {
            cursor->moveCursor(direction, n);
        }

        auto removeNChars(unsigned int n)
        {
            for (unsigned int i = 0; i < n; i++) {
                removeChar();
            }
        }

        [[nodiscard]] auto getSelectedLine()
        {
            return cursor->getSelectedLine();
        }
    };
} // namespace gui

TEST_CASE("TextLinesCursor - navigation without scroll")
{
    using namespace gui;

    std::string testStringShortLine  = "Test Line ";                     // 10 sings
    std::string testStringNormalLine = "Test Normal No Line ";           // 20 sings
    std::string testStringLongLine   = "Test Long Long Long Long Line "; // 30 sings

    SECTION("Default position three lines text")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::None));

        auto [selectedLine, selectedLineCursorPosition, selectedLineNumber] = text->getSelectedLine();

        REQUIRE(selectedLine->getText(0).c_str() == testStringLongLine);
        REQUIRE(selectedLineCursorPosition == testStringLongLine.length());
        REQUIRE(selectedLineNumber == 2);
    }

    SECTION("Movement three lines text test -> short|normal|long")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Down nothing should happen as cursor is at bottom and right end
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Right nothing should happen as cursor is at bottom and right end
        text->moveCursor(gui::NavigationDirection::RIGHT, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Left to line center, line should not change but position should
        text->moveCursor(gui::NavigationDirection::LEFT, (testStringLongLine.length() / 2));

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == (testStringLongLine.length() / 2));
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Up line should change and cursor should be at corresponding position as it fits in upper line
        text->moveCursor(gui::NavigationDirection::UP, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == (testStringLongLine.length() / 2));
        REQUIRE(std::get<2>(selectedLine) == 1);

        // Move Up line should change and cursor should be at its end as corresponding position does not fit
        text->moveCursor(gui::NavigationDirection::UP, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);

        // Move Up line should not change and cursor should not change as it is first line
        text->moveCursor(gui::NavigationDirection::UP, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);

        // Move Left to line and text beginning
        text->moveCursor(gui::NavigationDirection::LEFT, testStringShortLine.length());

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);

        // Move two times Down line should change and cursor should be at its beginning
        text->moveCursor(gui::NavigationDirection::DOWN, 2);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move one time Left line should change and cursor should be at its end
        text->moveCursor(gui::NavigationDirection::LEFT, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringNormalLine.length());
        REQUIRE(std::get<2>(selectedLine) == 1);
    }

    SECTION("Movement three lines text test -> long|short|normal")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 200);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == testStringNormalLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Up two times, line should change and cursor should be at short line length position
        text->moveCursor(gui::NavigationDirection::UP, 2);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);

        // Move Right three times, only cursor pos should change
        text->moveCursor(gui::NavigationDirection::RIGHT, 3);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length() + 3);
        REQUIRE(std::get<2>(selectedLine) == 0);

        // Move Down one time, line should change and cursor should be at short line end as corresponding do not fit
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 1);

        // Move Right one time, line should change and cursor should be at next line beginning
        text->moveCursor(gui::NavigationDirection::RIGHT, 1);

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);
    }
}

TEST_CASE("TextLinesCursor - navigation with scroll")
{
    using namespace gui;

    std::string testStringShortLine  = "Test Line ";                     // 10 sings
    std::string testStringNormalLine = "Test Normal No Line ";           // 20 sings
    std::string testStringLongLine   = "Test Long Long Long Long Line "; // 30 sings

    SECTION("One line text space text containing three lines - scroll init position at document begin")
    {

        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Left two times, nothing should change
        text->moveCursor(gui::NavigationDirection::LEFT, 2);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Down one time, line should change and cursor should be at its beginning
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Left one time, line should change and cursor should be at previous line end
        text->moveCursor(gui::NavigationDirection::LEFT, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Down one time, line should change and cursor should be at its end as current line is longer
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Right one time, line should change and cursor should be at its beginning
        text->moveCursor(gui::NavigationDirection::RIGHT, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Down one time, nothing should change as it is document end
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Right for string length + 1, cursor should stop at end without line changing at it is document end
        text->moveCursor(gui::NavigationDirection::RIGHT, testStringNormalLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == testStringNormalLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move UP three times, lines should change and cursor should be at shortest line position.
        text->moveCursor(gui::NavigationDirection::UP, 3);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);
    }

    SECTION("One line text space text containing three lines - scroll init position at document end")
    {

        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == testStringNormalLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move UP three times, lines should change and cursor should be at shortest line position.
        text->moveCursor(gui::NavigationDirection::UP, 3);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Right one time, line should change and cursor should be at its beginning
        text->moveCursor(gui::NavigationDirection::RIGHT, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Right for line length + 1, line should change and cursor should be at its beginning
        text->moveCursor(gui::NavigationDirection::RIGHT, testStringLongLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);
    }

    SECTION("One 10 lines text space text containing three lines - scroll init position at document begin")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 3);

        // Move Left two times, nothing should change
        text->moveCursor(gui::NavigationDirection::LEFT, 2);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 3);

        // Move Down two times, lines should change but without scroll
        text->moveCursor(gui::NavigationDirection::DOWN, 2);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Down one time, lines should change with scroll
        text->moveCursor(gui::NavigationDirection::DOWN, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Right for line length, lines should change with scroll
        text->moveCursor(gui::NavigationDirection::RIGHT, testStringLongLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);

        // Move Down ten times, lines should change with scroll and stop at last one
        text->moveCursor(gui::NavigationDirection::DOWN, 10);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 2);
    }

    SECTION("One 10 lines text space text containing three lines - scroll init position at document end")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);
        REQUIRE(text->linesVisible() == 3);

        // Move Left two times, nothing should change
        text->moveCursor(gui::NavigationDirection::RIGHT, 2);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);
        REQUIRE(text->linesVisible() == 3);

        // Move Up two times, lines should change and cursor should be at shortest line length
        text->moveCursor(gui::NavigationDirection::UP, 2);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 3);

        // Move Left for line length, line should change and cursor should be at previous line end
        text->moveCursor(gui::NavigationDirection::LEFT, testStringShortLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 3);

        // Move Up ten times, line should change and cursor should be at shortest line position
        text->moveCursor(gui::NavigationDirection::UP, 10);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 3);
    }
}

TEST_CASE("TextLinesCursor - addition and deletion with scroll")
{
    using namespace gui;

    std::string testStringShortLine  = "Test Line ";                     // 10 sings
    std::string testStringNormalLine = "Test Normal No Line ";           // 20 sings
    std::string testStringLongLine   = "Test Long Long Long Long Line "; // 30 sings

    SECTION("One line text space text containing three lines - scroll init position at document begin")
    {

        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(600, 40);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentBegin);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Add empty new line at beginning, other lines should shift down
        text->addText("\n");

        selectedLine = text->getSelectedLine();
        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == std::string("\n"));
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Move Down three times, lines should change
        text->moveCursor(gui::NavigationDirection::DOWN, 3);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == 0);
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // As we are line beginning remove character which should remove newline and merge two lines
        text->removeChar();

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);

        // Remove whole line (+1 for newline), line should change and what left in line should merge
        text->removeNChars(testStringShortLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine + testStringNormalLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 0);
        REQUIRE(text->linesVisible() == 1);
    }

    SECTION("One 10 lines text space text containing three lines - scroll init position at document end")
    {
        mockup::fontManager();
        auto text = std::make_unique<gui::TestText>();
        text->setMaximumSize(400, 90);
        text->setCursorStartPosition(gui::CursorStartPosition::DocumentEnd);

        std::tuple<const TextLine *, unsigned int, unsigned int> selectedLine;

        REQUIRE(text->linesVisible() == 0);

        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringShortLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringNormalLine, Font(27).raw(), TextBlock::End::Newline));
        text->addText(TextBlock(testStringLongLine, Font(27).raw(), TextBlock::End::None));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);
        REQUIRE(text->linesVisible() == 3);

        // Move Up two times, lines should change and cursor should be at shortest line length
        text->moveCursor(gui::NavigationDirection::UP, 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringNormalLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringNormalLine.length());
        REQUIRE(std::get<2>(selectedLine) == 1);
        REQUIRE(text->linesVisible() == 3);

        // Remove whole line (+1 for newline), there should be additional previous line added for free space.
        text->removeNChars(testStringNormalLine.length() + 1);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringShortLine + "\n");
        REQUIRE(std::get<1>(selectedLine) == testStringShortLine.length());
        REQUIRE(std::get<2>(selectedLine) == 1);
        REQUIRE(text->linesVisible() == 3);

        // Go to document ending (with multiple moves)
        text->moveCursor(gui::NavigationDirection::DOWN, 10);
        text->moveCursor(gui::NavigationDirection::RIGHT, 100);

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == testStringLongLine);
        REQUIRE(std::get<1>(selectedLine) == testStringLongLine.length());
        REQUIRE(std::get<2>(selectedLine) == 2);
        REQUIRE(text->linesVisible() == 3);

        // Add character so line would change (extra spaces to cover line width)
        std::string addText = "Additional Text for testing";
        text->addText(std::string("        " + addText));

        selectedLine = text->getSelectedLine();

        REQUIRE(std::get<0>(selectedLine)->getText(0).c_str() == addText);
        REQUIRE(std::get<1>(selectedLine) == addText.length());
        REQUIRE(std::get<2>(selectedLine) == 2);
        REQUIRE(text->linesVisible() == 3);
    }
}