dte test coverage


Directory: ./
File: test/shift.c
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #include "test.h"
2 #include "block-iter.h"
3 #include "buffer.h"
4 #include "editor.h"
5 #include "options.h"
6 #include "shift.h"
7 #include "view.h"
8 #include "window.h"
9
10 1 static void test_shift_lines(TestContext *ctx)
11 {
12 1 EditorState *e = ctx->userdata;
13 1 View *view = window_open_empty_buffer(e->window);
14 1 LocalOptions *opts = &view->buffer->options;
15 1 opts->indent_width = 4;
16 1 opts->auto_indent = false;
17 1 opts->emulate_tab = true;
18 1 opts->expand_tab = true;
19
20 1 static const char text[] = " line 1\n line 2\n";
21 1 BlockIter *cursor = &view->cursor;
22 1 buffer_insert_bytes(view, text, sizeof(text) - 1);
23 1 block_iter_goto_offset(cursor, 4);
24 1 EXPECT_EQ(block_iter_get_offset(cursor), 4);
25
26 1 CodePoint u = 0;
27 1 EXPECT_EQ(block_iter_get_char(cursor, &u), 1);
28 1 EXPECT_EQ(u, 'l');
29
30 1 shift_lines(view, 1);
31 1 EXPECT_EQ(block_iter_get_offset(cursor), 8);
32 1 shift_lines(view, 1);
33 1 EXPECT_EQ(block_iter_get_offset(cursor), 12);
34 1 shift_lines(view, 2);
35 1 EXPECT_EQ(block_iter_get_offset(cursor), 20);
36 1 shift_lines(view, -1);
37 1 EXPECT_EQ(block_iter_get_offset(cursor), 16);
38 1 shift_lines(view, -2);
39 1 EXPECT_EQ(block_iter_get_offset(cursor), 8);
40 1 shift_lines(view, -2);
41 1 EXPECT_EQ(block_iter_get_offset(cursor), 0);
42 1 shift_lines(view, -1);
43 1 EXPECT_EQ(block_iter_get_offset(cursor), 0);
44 1 shift_lines(view, 1);
45 1 EXPECT_EQ(block_iter_get_offset(cursor), 4);
46 1 shift_lines(view, -50);
47 1 EXPECT_EQ(block_iter_get_offset(cursor), 0);
48
49 1 window_close_current_view(e->window);
50 1 }
51
52 static const TestEntry tests[] = {
53 TEST(test_shift_lines),
54 };
55
56 const TestGroup shift_tests = TEST_GROUP(tests);
57