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 struct diff_data d_left, d_right;
17 char *left_data = "a\nb\nc\nd\ne\nm\nn\n";
18 char *right_data = "a\nb\nj\nk\nl\nm\nn\n";
21 printf("\n--- %s()\n", __func__);
23 d_left = (struct diff_data){
25 .len = strlen(left_data),
28 d_right = (struct diff_data){
30 .len = strlen(right_data),
33 *result = (struct diff_result) {
38 diff_atomize_text_by_line(NULL, result->left);
39 diff_atomize_text_by_line(NULL, result->right);
41 struct diff_state state = {
43 .recursion_depth_left = 32,
45 diff_data_init_subsection(&state.left, result->left,
46 result->left->atoms.head,
47 result->left->atoms.len);
48 diff_data_init_subsection(&state.right, result->right,
49 result->right->atoms.head,
50 result->right->atoms.len);
53 diff_state_add_chunk(&state, true,
54 &state.left.atoms.head[0], 2,
55 &state.right.atoms.head[0], 2);
58 diff_state_add_chunk(&state, true,
59 &state.left.atoms.head[2], 0,
60 &state.right.atoms.head[2], 3);
63 diff_state_add_chunk(&state, true,
64 &state.left.atoms.head[2], 3,
65 &state.right.atoms.head[5], 0);
68 diff_state_add_chunk(&state, true,
69 &state.left.atoms.head[5], 2,
70 &state.right.atoms.head[5], 2);
72 for (i = 0; i < result->chunks.len; i++) {
73 struct diff_chunk *c = &result->chunks.head[i];
74 enum diff_chunk_type t = diff_chunk_type(c);
76 printf("[%d] %s lines L%d R%d @L %lld @R %lld\n",
77 i, (t == CHUNK_MINUS ? "minus" :
78 (t == CHUNK_PLUS ? "plus" :
79 (t == CHUNK_SAME ? "same" : "?"))),
82 (long long)(c->left_start ? diff_atom_root_idx(result->left, c->left_start) : -1LL),
83 (long long)(c->right_start ? diff_atom_root_idx(result->right, c->right_start) : -1LL));
86 diff_result_free(result);
87 diff_data_free(&d_left);
88 diff_data_free(&d_right);
91 void test_plus_after_plus(void)
93 struct diff_result *result = malloc(sizeof(struct diff_result));
94 struct diff_data d_left, d_right;
95 char *left_data = "a\nb\nc\nd\ne\nm\nn\n";
96 char *right_data = "a\nb\nj\nk\nl\nm\nn\n";
99 printf("\n--- %s()\n", __func__);
101 d_left = (struct diff_data){
103 .len = strlen(left_data),
106 d_right = (struct diff_data){
108 .len = strlen(right_data),
111 *result = (struct diff_result) {
116 diff_atomize_text_by_line(NULL, result->left);
117 diff_atomize_text_by_line(NULL, result->right);
119 struct diff_state state = {
121 .recursion_depth_left = 32,
123 diff_data_init_subsection(&state.left, result->left,
124 result->left->atoms.head,
125 result->left->atoms.len);
126 diff_data_init_subsection(&state.right, result->right,
127 result->right->atoms.head,
128 result->right->atoms.len);
131 diff_state_add_chunk(&state, true,
132 &state.left.atoms.head[0], 2,
133 &state.right.atoms.head[0], 2);
135 /* "minus" section */
136 diff_state_add_chunk(&state, true,
137 &state.left.atoms.head[2], 3,
138 &state.right.atoms.head[2], 0);
141 diff_state_add_chunk(&state, true,
142 &state.left.atoms.head[5], 0,
143 &state.right.atoms.head[2], 1);
145 diff_state_add_chunk(&state, true,
146 &state.left.atoms.head[5], 0,
147 &state.right.atoms.head[3], 2);
150 diff_state_add_chunk(&state, true,
151 &state.left.atoms.head[5], 2,
152 &state.right.atoms.head[5], 2);
154 ARRAYLIST_FOREACH(c, result->chunks) {
155 enum diff_chunk_type t = diff_chunk_type(c);
157 printf("[%lu] %s lines L%d R%d @L %lld @R %lld\n",
158 (unsigned long)ARRAYLIST_IDX(c, result->chunks),
159 (t == CHUNK_MINUS ? "minus" :
160 (t == CHUNK_PLUS ? "plus" :
161 (t == CHUNK_SAME ? "same" : "?"))),
164 (long long)(c->left_start ? diff_atom_root_idx(result->left, c->left_start) : -1LL),
165 (long long)(c->right_start ? diff_atom_root_idx(result->right, c->right_start) : -1LL));
168 diff_result_free(result);
169 diff_data_free(&d_left);
170 diff_data_free(&d_right);
175 test_minus_after_plus();
176 test_plus_after_plus();