]> scripts.mit.edu Git - wizard.git/blob - wizard/tests/resolve_test.py
Major updates to resolution code from runs.
[wizard.git] / wizard / tests / resolve_test.py
1 from wizard import resolve
2
3 def test_resolve_simple():
4     contents = """
5 foo
6 bar
7 <<<<<<< HEAD
8 baz
9 =======
10 boo
11 >>>>>>> upstream
12 bing
13 """
14     spec = """
15 <<<<<<<
16 baz
17 =======
18 boo
19 >>>>>>>
20 """
21     result = [0]
22     assert resolve.resolve(contents, spec, result) == """
23 foo
24 bar
25 boo
26 bing
27 """
28
29 def test_resolve_wildcard():
30     contents = """
31 foo
32 bar
33 <<<<<<< HEAD
34 common
35 uncommon
36 still uncommon
37
38 =======
39 transformed common
40 >>>>>>> 456ef127bf8531bb363b1195172c71bce3747ae7
41 baz
42 """
43
44     spec = """
45 <<<<<<<
46 common
47 ***1***
48 =======
49 transformed common
50 >>>>>>>
51 """
52
53     result = [0, 1]
54     assert resolve.resolve(contents, spec, result) == """
55 foo
56 bar
57 transformed common
58 uncommon
59 still uncommon
60
61 baz
62 """
63
64 def test_resolve_user():
65     contents = """
66 top
67 <<<<<<<
68 bar
69 the user is right
70 baz
71 =======
72 blah blah
73 >>>>>>>
74 bottom
75 <<<<<<<
76 Unrelated conflict
77 =======
78 Unrelated conflicts
79 >>>>>>>"""
80     spec = """
81 <<<<<<<
82 ***1***
83 the user is right
84 ***2***
85 =======
86 blah blah
87 >>>>>>>
88 """
89     result = [-1]
90     assert resolve.resolve(contents, spec, result) == """
91 top
92 bar
93 the user is right
94 baz
95 bottom
96 <<<<<<<
97 Unrelated conflict
98 =======
99 Unrelated conflicts
100 >>>>>>>"""
101
102 def test_resolve_multi_var():
103     contents = """
104 top
105 <<<<<<<
106 the user is right
107 this is ours
108 more user stuff
109 this is ours
110 =======
111 this is kept, but variable
112 this is not kept
113 >>>>>>>
114 bottom
115 <<<<<<<
116 unrelated conflict
117 =======
118 unrelated conflicts
119 >>>>>>>
120 """
121     spec = """
122 <<<<<<<
123 ***1***
124 this is ours
125 ***2***
126 this is ours
127 =======
128 ***3***
129 this is not kept
130 >>>>>>>
131 """
132     result = [3, 1, 2]
133     assert resolve.resolve(contents, spec, result) == """
134 top
135 this is kept, but variable
136 the user is right
137 more user stuff
138 bottom
139 <<<<<<<
140 unrelated conflict
141 =======
142 unrelated conflicts
143 >>>>>>>
144 """
145
146 def test_resolve_simple():
147     contents = """
148 bar
149 <<<<<<< HEAD
150 baz
151 =======
152 boo
153 >>>>>>> upstream
154 bing
155 <<<<<<< HEAD
156 oh?
157 =======
158 bad match
159 >>>>>>> upstream
160 """
161     spec = """
162 <<<<<<<
163 ***1***
164 =======
165 bad match
166 >>>>>>>
167 """
168     result = [-1]
169     assert resolve.resolve(contents, spec, result) == """
170 bar
171 <<<<<<< HEAD
172 baz
173 =======
174 boo
175 >>>>>>> upstream
176 bing
177 oh?
178 """
179
180 def test_is_conflict():
181     assert not resolve.is_conflict("foobar\nbar")
182     assert resolve.is_conflict("bar\n<<<<<<< HEAD\n=======\n>>>>>>> abcd\nbar")