10 #include <diff_internal.h>
11 #include <diff_debug.h>
13 void test_minus_after_plus(void)
15 struct diff_result *result = malloc(sizeof(struct diff_result));
16 char *left_data = "a\nb\nc\nd\ne\nm\nn\n";
17 char *right_data = "a\nb\nj\nk\nl\nm\nn\n";
20 printf("\n--- %s()\n", __func__);
22 *result = (struct diff_result) {
23 .left = (struct diff_data){
25 .len = strlen(left_data),
26 .root = &result->left,
28 .right = (struct diff_data){
30 .len = strlen(right_data),
31 .root = &result->right,
35 diff_atomize_text_by_line(0, &result->left, &result->right);
37 struct diff_state state = {
39 .recursion_depth_left = 32,
41 diff_data_init_subsection(&state.left, &result->left,
42 result->left.atoms.head,
43 result->left.atoms.len);
44 diff_data_init_subsection(&state.right, &result->right,
45 result->right.atoms.head,
46 result->right.atoms.len);
49 diff_state_add_chunk(&state, true,
50 &state.left.atoms.head[0], 2,
51 &state.right.atoms.head[0], 2);
54 diff_state_add_chunk(&state, true,
55 &state.left.atoms.head[2], 0,
56 &state.right.atoms.head[2], 3);
59 diff_state_add_chunk(&state, true,
60 &state.left.atoms.head[2], 3,
61 &state.right.atoms.head[5], 0);
64 diff_state_add_chunk(&state, true,
65 &state.left.atoms.head[5], 2,
66 &state.right.atoms.head[5], 2);
68 for (i = 0; i < result->chunks.len; i++) {
69 struct diff_chunk *c = &result->chunks.head[i];
70 enum diff_chunk_type t = diff_chunk_type(c);
72 printf("[%d] %s lines L%d R%d @L %d @R %d\n",
73 i, (t == CHUNK_MINUS ? "minus" :
74 (t == CHUNK_PLUS ? "plus" :
75 (t == CHUNK_SAME ? "same" : "?"))),
78 c->left_start ? c->left_start->pos : -1,
79 c->right_start ? c->right_start->pos : -1);
82 diff_result_free(result);
85 void test_plus_after_plus(void)
87 struct diff_result *result = malloc(sizeof(struct diff_result));
88 char *left_data = "a\nb\nc\nd\ne\nm\nn\n";
89 char *right_data = "a\nb\nj\nk\nl\nm\nn\n";
92 printf("\n--- %s()\n", __func__);
94 *result = (struct diff_result) {
95 .left = (struct diff_data){
97 .len = strlen(left_data),
98 .root = &result->left,
100 .right = (struct diff_data){
102 .len = strlen(right_data),
103 .root = &result->right,
107 diff_atomize_text_by_line(0, &result->left, &result->right);
109 struct diff_state state = {
111 .recursion_depth_left = 32,
113 diff_data_init_subsection(&state.left, &result->left,
114 result->left.atoms.head,
115 result->left.atoms.len);
116 diff_data_init_subsection(&state.right, &result->right,
117 result->right.atoms.head,
118 result->right.atoms.len);
121 diff_state_add_chunk(&state, true,
122 &state.left.atoms.head[0], 2,
123 &state.right.atoms.head[0], 2);
125 /* "minus" section */
126 diff_state_add_chunk(&state, true,
127 &state.left.atoms.head[2], 3,
128 &state.right.atoms.head[2], 0);
131 diff_state_add_chunk(&state, true,
132 &state.left.atoms.head[5], 0,
133 &state.right.atoms.head[2], 1);
135 diff_state_add_chunk(&state, true,
136 &state.left.atoms.head[5], 0,
137 &state.right.atoms.head[3], 2);
140 diff_state_add_chunk(&state, true,
141 &state.left.atoms.head[5], 2,
142 &state.right.atoms.head[5], 2);
144 ARRAYLIST_FOREACH(c, result->chunks) {
145 enum diff_chunk_type t = diff_chunk_type(c);
147 printf("[%d] %s lines L%d R%d @L %d @R %d\n",
148 ARRAYLIST_IDX(c, result->chunks),
149 (t == CHUNK_MINUS ? "minus" :
150 (t == CHUNK_PLUS ? "plus" :
151 (t == CHUNK_SAME ? "same" : "?"))),
154 c->left_start ? c->left_start->pos : -1,
155 c->right_start ? c->right_start->pos : -1);
158 diff_result_free(result);
163 test_minus_after_plus();
164 test_plus_after_plus();