about summary refs log tree commit diff stats
path: root/arc/.traces/channel-new-empty-not-full
blob: 32175580e8b69a2ad88c4d8fa39a947a71b7f452 (plain) (blame)
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
c{0: 0 (((1 channel-address)) <- ((init-channel)) ((3 literal))) -- nil
c{0: 1 (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref))) -- nil
c{0: 2 (((3 boolean)) <- ((full?)) ((1 channel-address) (deref))) -- nil
c{1: 0 ✓ (((1 channel-address)) <- ((init-channel)) ((3 literal)))
c{1: 1 ✓ (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref)))
c{1: 2 ✓ (((3 boolean)) <- ((full?)) ((1 channel-address) (deref)))
cn0: convert-names in main
cn0: (((1 channel-address)) <- ((init-channel)) ((3 literal))) nil nil
cn0: checking arg ((3 literal))
cn0: checking oarg ((1 channel-address))
maybe-add: ((1 channel-address))
cn0: (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref))) nil nil
cn0: checking arg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: checking oarg ((2 boolean))
maybe-add: ((2 boolean))
cn0: (((3 boolean)) <- ((full?)) ((1 channel-address) (deref))) nil nil
cn0: checking arg ((1 channel-address) (deref))
maybe-add: ((1 channel-address) (deref))
cn0: checking oarg ((3 boolean))
maybe-add: ((3 boolean))
cn1: (((1 channel-address)) <- ((init-channel)) ((3 literal)))
cn1: (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref)))
cn1: (((3 boolean)) <- ((full?)) ((1 channel-address) (deref)))
schedule: main
run: main 0: (((1 channel-address)) <- ((init-channel)) ((3 literal)))
run: init-channel/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: init-channel/main 0: 1000 => ((default-space space-address))
run: init-channel/main 1: (((1 channel-address)) <- ((new)) ((channel literal)))
run: init-channel/main 1: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1002 <= 1031
run: init-channel/main 2: (((2 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((0 offset)))
run: init-channel/main 2: 1031 => ((2 integer-address))
mem: ((2 integer-address)): 1003 <= 1031
run: init-channel/main 3: (((2 integer-address) (deref)) <- ((copy)) ((0 literal)))
run: init-channel/main 3: 0 => ((2 integer-address) (deref))
mem: ((2 integer-address) (deref)): 1031 <= 0
run: init-channel/main 4: (((3 integer-address)) <- ((get-address)) ((1 channel-address) (deref)) ((1 offset)))
run: init-channel/main 4: 1032 => ((3 integer-address))
mem: ((3 integer-address)): 1004 <= 1032
run: init-channel/main 5: (((3 integer-address) (deref)) <- ((copy)) ((0 literal)))
run: init-channel/main 5: 0 => ((3 integer-address) (deref))
mem: ((3 integer-address) (deref)): 1032 <= 0
run: init-channel/main 6: (((4 integer)) <- ((next-input)))
arg: nil 0 (3)
run: init-channel/main 6: 3 => ((4 integer))
mem: ((4 integer)): 1005 <= 3
run: init-channel/main 7: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal)))
mem: ((4 integer)) => 3
run: init-channel/main 7: 4 => ((4 integer))
mem: ((4 integer)): 1005 <= 4
run: init-channel/main 8: (((5 tagged-value-array-address-address)) <- ((get-address)) ((1 channel-address) (deref)) ((2 offset)))
run: init-channel/main 8: 1033 => ((5 tagged-value-array-address-address))
mem: ((5 tagged-value-array-address-address)): 1006 <= 1033
run: init-channel/main 9: (((5 tagged-value-array-address-address) (deref)) <- ((new)) ((tagged-value-array literal)) ((4 integer)))
mem: ((4 integer)) => 4
run: init-channel/main 9: 1034 => ((5 tagged-value-array-address-address) (deref))
mem: ((5 tagged-value-array-address-address) (deref)): 1033 <= 1034
run: init-channel/main 10: (((reply)) ((1 channel-address)))
mem: ((1 channel-address)) => 1031
run: main 0: 1031 => ((1 channel-address))
mem: ((1 channel-address)): 1 <= 1031
run: main 1: (((2 boolean)) <- ((empty?)) ((1 channel-address) (deref)))
mem: ((1 channel-address) (deref)) => #(tagged record (0 0 1034 . nil))
run: empty?/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: empty?/main 0: 1043 => ((default-space space-address))
run: empty?/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 0 1034 . nil)))
run: empty?/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1045 <= 0
mem: ((1 channel)): 1046 <= 0
mem: ((1 channel)): 1047 <= 1034
run: empty?/main 2: (((4 integer)) <- ((get)) ((1 channel)) ((0 offset)))
mem: ((1045 integer) (raw)) => 0
run: empty?/main 2: 0 => ((4 integer))
mem: ((4 integer)): 1048 <= 0
run: empty?/main 3: (((5 integer)) <- ((get)) ((1 channel)) ((1 offset)))
mem: ((1046 integer) (raw)) => 0
run: empty?/main 3: 0 => ((5 integer))
mem: ((5 integer)): 1049 <= 0
run: empty?/main 4: (((6 boolean)) <- ((equal)) ((4 integer)) ((5 integer)))
mem: ((4 integer)) => 0
mem: ((5 integer)) => 0
run: empty?/main 4: t => ((6 boolean))
mem: ((6 boolean)): 1050 <= t
run: empty?/main 5: (((reply)) ((6 boolean)))
mem: ((6 boolean)) => t
run: main 1: t => ((2 boolean))
mem: ((2 boolean)): 2 <= t
run: main 2: (((3 boolean)) <- ((full?)) ((1 channel-address) (deref)))
mem: ((1 channel-address) (deref)) => #(tagged record (0 0 1034 . nil))
run: full?/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: full?/main 0: 1074 => ((default-space space-address))
run: full?/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 0 1034 . nil)))
run: full?/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1076 <= 0
mem: ((1 channel)): 1077 <= 0
mem: ((1 channel)): 1078 <= 1034
run: full?/main 2: (((4 integer)) <- ((get)) ((1 channel)) ((1 offset)))
mem: ((1077 integer) (raw)) => 0
run: full?/main 2: 0 => ((4 integer))
mem: ((4 integer)): 1079 <= 0
run: full?/main 3: (((4 integer)) <- ((add)) ((4 integer)) ((1 literal)))
mem: ((4 integer)) => 0
run: full?/main 3: 1 => ((4 integer))
mem: ((4 integer)): 1079 <= 1
run: full?/main 4: (((5 integer)) <- ((capacity)) ((1 channel)))
mem: ((1 channel)) => #(tagged record (0 0 1034 . nil))
run: capacity/full?/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: capacity/full?/main 0: 1105 => ((default-space space-address))
run: capacity/full?/main 1: (((1 channel)) <- ((next-input)))
arg: nil 0 (#(tagged record (0 0 1034 . nil)))
run: capacity/full?/main 1: #(tagged record (0 0 1034 . nil)) => ((1 channel))
mem: ((1 channel)): 1107 <= 0
mem: ((1 channel)): 1108 <= 0
mem: ((1 channel)): 1109 <= 1034
run: capacity/full?/main 2: (((4 tagged-value-array-address)) <- ((get)) ((1 channel)) ((2 offset)))
mem: ((1109 tagged-value-array-address) (raw)) => 1034
run: capacity/full?/main 2: 1034 => ((4 tagged-value-array-address))
mem: ((4 tagged-value-array-address)): 1110 <= 1034
run: capacity/full?/main 3: (((5 integer)) <- ((length)) ((4 tagged-value-array-address) (deref)))
array-len: ((4 tagged-value-array-address) (deref))
mem: ((1034 integer) (raw)) => 4
run: capacity/full?/main 3: 4 => ((5 integer))
mem: ((5 integer)): 1111 <= 4
run: capacity/full?/main 4: (((reply)) ((5 integer)))
mem: ((5 integer)) => 4
run: full?/main 4: 4 => ((5 integer))
mem: ((5 integer)): 1080 <= 4
run: full?/main 5: (((6 boolean)) <- ((less-than)) ((4 integer)) ((5 integer)))
mem: ((4 integer)) => 1
mem: ((5 integer)) => 4
run: full?/main 5: t => ((6 boolean))
mem: ((6 boolean)): 1081 <= t
run: full?/main 6: (((jump-if)) ((6 boolean)) ((1 offset)))
mem: ((6 boolean)) => t
run: full?/main 8: (((7 integer)) <- ((get)) ((1 channel)) ((0 offset)))
mem: ((1076 integer) (raw)) => 0
run: full?/main 8: 0 => ((7 integer))
mem: ((7 integer)): 1082 <= 0
run: full?/main 9: (((8 boolean)) <- ((equal)) ((7 integer)) ((4 integer)))
mem: ((7 integer)) => 0
mem: ((4 integer)) => 1
run: full?/main 9: nil => ((8 boolean))
mem: ((8 boolean)): 1083 <= nil
run: full?/main 10: (((reply)) ((8 boolean)))
mem: ((8 boolean)) => nil
run: main 2: nil => ((3 boolean))
mem: ((3 boolean)): 3 <= nil
schedule: done with routine nil
'n568' href='#n568'>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 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>

#include <locale.h>

#include "ui/keyhandlers.h"
#include "ui/inputwin.h"
#include "tests/helpers.h"

static char line[INP_WIN_MAX];

// append

void append_to_empty(void **state)
{
    setlocale(LC_ALL, "");
    line[0] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'a', 80);

    assert_string_equal("a", line);
    assert_int_equal(line_utf8_pos, 1);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void append_wide_to_empty(void **state)
{
    setlocale(LC_ALL, "");
    line[0] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80);

    assert_string_equal("四", line);
    assert_int_equal(line_utf8_pos, 1);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void append_to_single(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "a", 1);
    line[1] = '\0';
    int line_utf8_pos = 1;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80);

    assert_string_equal("ab", line);
    assert_int_equal(line_utf8_pos, 2);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}


void append_wide_to_single_non_wide(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "a", 1);
    line[1] = '\0';
    int line_utf8_pos = 1;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80);

    assert_string_equal("a四", line);
    assert_int_equal(line_utf8_pos, 2);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void append_non_wide_to_single_wide(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "四", 1);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 1;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80);

    assert_string_equal("四b", line);
    assert_int_equal(line_utf8_pos, 2);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void append_wide_to_single_wide(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "四", 1);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 1;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 80);

    assert_string_equal("四三", line);
    assert_int_equal(line_utf8_pos, 2);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void append_non_wide_when_overrun(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "0123456789四1234567", 18);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 18;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20);
    key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20);
    key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20);

    assert_string_equal("0123456789四1234567zzz", line);
    assert_int_equal(line_utf8_pos, 21);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 3);
}

void insert_non_wide_to_non_wide(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd", 4);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 2;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_printable(line, &line_utf8_pos, &col, &pad_start, '0', 80);

    assert_string_equal("ab0cd", line);
    assert_int_equal(line_utf8_pos, 3);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void insert_single_non_wide_when_pad_scrolled(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 2;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 2;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'B', 12);

    assert_string_equal("AABAAAAAAAAAAAAA", line);
    assert_int_equal(line_utf8_pos, 3);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 2);
}

void insert_many_non_wide_when_pad_scrolled(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 2;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 2;

    key_printable(line, &line_utf8_pos, &col, &pad_start, 'B', 12);
    key_printable(line, &line_utf8_pos, &col, &pad_start, 'C', 12);
    key_printable(line, &line_utf8_pos, &col, &pad_start, 'D', 12);

    assert_string_equal("AABCDAAAAAAAAAAAAA", line);
    assert_int_equal(line_utf8_pos, 5);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 2);
}

void insert_single_non_wide_last_column(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcdefghijklmno", 15);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 2;

    key_printable(line, &line_utf8_pos, &col, &pad_start, '1', 5);

    assert_string_equal("abcdefg1hijklmno", line);
    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 3);
}

void insert_many_non_wide_last_column(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcdefghijklmno", 15);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 2;

    key_printable(line, &line_utf8_pos, &col, &pad_start, '1', 5);
    key_printable(line, &line_utf8_pos, &col, &pad_start, '2', 5);

    assert_string_equal("abcdefg12hijklmno", line);
    assert_int_equal(line_utf8_pos, 9);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 4);
}

void ctrl_left_when_no_input(void **state)
{
    setlocale(LC_ALL, "");
    line[0] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_start(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_first_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 2;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_first_space(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 4;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_start_of_second_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 5;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_second_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 8;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 5);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_end_of_second_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 10;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 5);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_second_space(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 11;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 5);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_start_of_third_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 12;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 5);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_third_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 14;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 12);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_end_of_third_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 15;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 12);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_third_space(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 16;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 12);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_at_end(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "abcd efghij klmn opqr", 21);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 20;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 17);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_in_only_whitespace(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "       ", 7);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 5;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_start_whitespace_start_of_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "    hello", 9);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 4;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_start_whitespace_middle_of_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "    hello", 9);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 4);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_in_whitespace_between_words(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "hey    hello", 12);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 5;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_in_whitespace_between_words_start_of_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "hey    hello", 12);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_in_whitespace_between_words_middle_of_word(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "hey    hello", 12);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 9;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 7);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_left_when_word_overrun_to_left(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 18;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 14;

    key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 9);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 9);
}

void ctrl_right_when_no_input(void **state)
{
    setlocale(LC_ALL, "");
    line[0] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 0);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_when_at_end(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 20;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 20);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_one_word_at_start(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword", 8);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 0;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_one_word_in_middle(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword", 8);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 3;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_one_word_at_end(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword", 8);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_two_words_from_middle_first(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 4;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_two_words_from_end_first(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 7;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_two_words_from_space(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 8;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 20);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_two_words_from_start_second(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword anotherword", 20);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 9;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 20);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_one_word_leading_whitespace(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "       someword", 15);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 3;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 15);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_two_words_in_whitespace(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "       someword        adfasdf", 30);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 19;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 30);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}

void ctrl_right_trailing_whitespace_from_middle(void **state)
{
    setlocale(LC_ALL, "");
    g_utf8_strncpy(line, "someword        ", 16);
    line[strlen(line)] = '\0';
    int line_utf8_pos = 3;
    int col = utf8_pos_to_col(line, line_utf8_pos);
    int pad_start = 0;

    key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);

    assert_int_equal(line_utf8_pos, 8);
    assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
    assert_int_equal(pad_start, 0);
}