rtext 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,302 +1,301 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","..","lib")
2
-
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'rtext/frontend/context'
6
-
7
- class ContextTest < MiniTest::Test
8
-
9
- def test_simple
10
- assert_context(
11
- %Q(
12
- A {
13
- B {
14
- |F bla
15
- ),
16
- %Q(
17
- A {
18
- B {
19
- C a1: v1, a2: "v2"
20
- D {
21
- E a1: 5
22
- }
23
- |F bla
24
- ))
25
- end
26
-
27
- def test_child_label
28
- assert_context(
29
- %Q(
30
- A {
31
- sub:
32
- B {
33
- F bla|
34
- ),
35
- %Q(
36
- A {
37
- sub:
38
- B {
39
- C a1: v1, a2: "v2"
40
- D {
41
- E a1: 5
42
- }
43
- F bla|
44
- ))
45
- end
46
-
47
- def test_child_label_array
48
- assert_context(
49
- %Q(
50
- A {
51
- sub: [
52
- B {
53
- F| bla
54
- ),
55
- %Q(
56
- A {
57
- sub: [
58
- B {
59
- C
60
- }
61
- B {
62
- C a1: v1, a2: "v2"
63
- D {
64
- E a1: 5
65
- }
66
- F| bla
67
- ))
68
- end
69
-
70
- def test_child_label_array2
71
- assert_context(
72
- %Q(
73
- A {
74
- B |
75
- ),
76
- %Q(
77
- A {
78
- sub: [
79
- ]
80
- B |
81
- ))
82
- end
83
-
84
- def test_child_label_array3
85
- assert_context(
86
- %Q(
87
- A {
88
- sub: [
89
- ] |
90
- ),
91
- %Q(
92
- A {
93
- sub: [
94
- ] |
95
- ))
96
- end
97
-
98
-
99
- def test_ignore_child_lables
100
- assert_context(
101
- %Q(
102
- A {
103
- B {
104
- F bl|a
105
- ),
106
- %Q(
107
- A {
108
- B {
109
- sub:
110
- C a1: v1, a2: "v2"
111
- sub2: [
112
- D {
113
- E a1: 5
114
- }
115
- ]
116
- F bl|a
117
- ))
118
- end
119
-
120
- def test_linebreak
121
- assert_context(
122
- %Q(
123
- A {
124
- B {
125
- C name, a1: v1, a2: "v2"|
126
- ),
127
- %Q(
128
- A {
129
- B {
130
- C name,
131
- a1: v1,
132
- a2: "v2"|
133
- ))
134
- end
135
-
136
- def test_linebreak_arg_array
137
- assert_context(
138
- %Q(
139
- A {
140
- B {
141
- C name, a1: [ v1, v2 ], a2: |5
142
- ),
143
- %Q(
144
- A {
145
- B {
146
- C name,
147
- a1: [
148
- v1,
149
- v2
150
- ],
151
- a2: |5
152
- ))
153
- end
154
-
155
- def test_linebreak_empty_last_line
156
- assert_context(
157
- %Q(
158
- A {
159
- B name, |
160
- ),
161
- %Q(
162
- A {
163
- B name,
164
- |
165
- ))
166
- end
167
-
168
- def test_linebreak_empty_last_line2
169
- assert_context(
170
- %Q(
171
- A {
172
- B name, |
173
- ),
174
- %Q(
175
- A {
176
- B name,
177
- |
178
- ))
179
- end
180
-
181
- def test_linebreak_empty_lines
182
- assert_context(
183
- %Q(
184
- A {
185
- B name, a1: |
186
- ),
187
- %Q(
188
- A {
189
- B name,
190
-
191
- a1: |
192
- ))
193
- end
194
-
195
- def test_linebreak_first_arg_array
196
- assert_context(
197
- %Q(
198
- A {
199
- B [ |
200
- ),
201
- %Q(
202
- A {
203
- B [
204
- |
205
- ))
206
- end
207
-
208
- def test_linebreak_first_arg_array2
209
- assert_context(
210
- %Q(
211
- A {
212
- B [ 2, |
213
- ),
214
- %Q(
215
- A {
216
- B [
217
- 2,
218
- |
219
- ))
220
- end
221
-
222
- def test_linebreak_first_arg_array3
223
- assert_context(
224
- %Q(
225
- A {
226
- B [ 2 ], |
227
- ),
228
- %Q(
229
- A {
230
- B [
231
- 2
232
- ], |
233
- ))
234
- end
235
-
236
- def test_linebreak_backslash
237
- assert_context(
238
- %Q(
239
- A {
240
- B arg: 1,|
241
- ),
242
- %Q(
243
- A {
244
- B \\
245
- arg: 1,|
246
- ))
247
- end
248
-
249
- def test_linebreak_whitespace_after_backslash
250
- assert_context(
251
- %Q(
252
- A {
253
- B arg: 1,|
254
- ),
255
- %Q(
256
- A {
257
- B \\
258
- arg: 1,|
259
- ))
260
- end
261
-
262
- def test_comment_annotation
263
- assert_context(
264
- %Q(
265
- A {
266
- B {
267
- |F bla
268
- ),
269
- %Q(
270
- A {
271
- # bla
272
- B {
273
- C a1: v1, a2: "v2"
274
- # bla
275
- D {
276
- E a1: 5
277
- }
278
- @ anno
279
- |F bla
280
- ))
281
- end
282
-
283
- def assert_context(expected, text)
284
- # remove first and last lines
285
- # these are empty because of the use of %Q
286
- exp_lines = expected.split("\n")[1..-2]
287
- exp_col = exp_lines.last.index("|")
288
- exp_lines.last.sub!("|","")
289
- in_lines = text.split("\n")[1..-2]
290
- in_col = in_lines.last.index("|")
291
- in_lines.last.sub!("|","")
292
- ctx = RText::Frontend::Context.new
293
- lines, out_col = ctx.extract(in_lines, in_col)
294
- assert_equal exp_lines, lines
295
- if exp_col && in_col
296
- assert_equal exp_col, out_col
297
- end
298
- end
299
-
300
- end
301
-
302
-
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","..","lib")
2
+
3
+ require 'minitest/autorun'
4
+ require 'rtext/frontend/context'
5
+
6
+ class ContextTest < MiniTest::Test
7
+
8
+ def test_simple
9
+ assert_context(
10
+ %Q(
11
+ A {
12
+ B {
13
+ |F bla
14
+ ),
15
+ %Q(
16
+ A {
17
+ B {
18
+ C a1: v1, a2: "v2"
19
+ D {
20
+ E a1: 5
21
+ }
22
+ |F bla
23
+ ))
24
+ end
25
+
26
+ def test_child_label
27
+ assert_context(
28
+ %Q(
29
+ A {
30
+ sub:
31
+ B {
32
+ F bla|
33
+ ),
34
+ %Q(
35
+ A {
36
+ sub:
37
+ B {
38
+ C a1: v1, a2: "v2"
39
+ D {
40
+ E a1: 5
41
+ }
42
+ F bla|
43
+ ))
44
+ end
45
+
46
+ def test_child_label_array
47
+ assert_context(
48
+ %Q(
49
+ A {
50
+ sub: [
51
+ B {
52
+ F| bla
53
+ ),
54
+ %Q(
55
+ A {
56
+ sub: [
57
+ B {
58
+ C
59
+ }
60
+ B {
61
+ C a1: v1, a2: "v2"
62
+ D {
63
+ E a1: 5
64
+ }
65
+ F| bla
66
+ ))
67
+ end
68
+
69
+ def test_child_label_array2
70
+ assert_context(
71
+ %Q(
72
+ A {
73
+ B |
74
+ ),
75
+ %Q(
76
+ A {
77
+ sub: [
78
+ ]
79
+ B |
80
+ ))
81
+ end
82
+
83
+ def test_child_label_array3
84
+ assert_context(
85
+ %Q(
86
+ A {
87
+ sub: [
88
+ ] |
89
+ ),
90
+ %Q(
91
+ A {
92
+ sub: [
93
+ ] |
94
+ ))
95
+ end
96
+
97
+
98
+ def test_ignore_child_lables
99
+ assert_context(
100
+ %Q(
101
+ A {
102
+ B {
103
+ F bl|a
104
+ ),
105
+ %Q(
106
+ A {
107
+ B {
108
+ sub:
109
+ C a1: v1, a2: "v2"
110
+ sub2: [
111
+ D {
112
+ E a1: 5
113
+ }
114
+ ]
115
+ F bl|a
116
+ ))
117
+ end
118
+
119
+ def test_linebreak
120
+ assert_context(
121
+ %Q(
122
+ A {
123
+ B {
124
+ C name, a1: v1, a2: "v2"|
125
+ ),
126
+ %Q(
127
+ A {
128
+ B {
129
+ C name,
130
+ a1: v1,
131
+ a2: "v2"|
132
+ ))
133
+ end
134
+
135
+ def test_linebreak_arg_array
136
+ assert_context(
137
+ %Q(
138
+ A {
139
+ B {
140
+ C name, a1: [ v1, v2 ], a2: |5
141
+ ),
142
+ %Q(
143
+ A {
144
+ B {
145
+ C name,
146
+ a1: [
147
+ v1,
148
+ v2
149
+ ],
150
+ a2: |5
151
+ ))
152
+ end
153
+
154
+ def test_linebreak_empty_last_line
155
+ assert_context(
156
+ %Q(
157
+ A {
158
+ B name, |
159
+ ),
160
+ %Q(
161
+ A {
162
+ B name,
163
+ |
164
+ ))
165
+ end
166
+
167
+ def test_linebreak_empty_last_line2
168
+ assert_context(
169
+ %Q(
170
+ A {
171
+ B name, |
172
+ ),
173
+ %Q(
174
+ A {
175
+ B name,
176
+ |
177
+ ))
178
+ end
179
+
180
+ def test_linebreak_empty_lines
181
+ assert_context(
182
+ %Q(
183
+ A {
184
+ B name, a1: |
185
+ ),
186
+ %Q(
187
+ A {
188
+ B name,
189
+
190
+ a1: |
191
+ ))
192
+ end
193
+
194
+ def test_linebreak_first_arg_array
195
+ assert_context(
196
+ %Q(
197
+ A {
198
+ B [ |
199
+ ),
200
+ %Q(
201
+ A {
202
+ B [
203
+ |
204
+ ))
205
+ end
206
+
207
+ def test_linebreak_first_arg_array2
208
+ assert_context(
209
+ %Q(
210
+ A {
211
+ B [ 2, |
212
+ ),
213
+ %Q(
214
+ A {
215
+ B [
216
+ 2,
217
+ |
218
+ ))
219
+ end
220
+
221
+ def test_linebreak_first_arg_array3
222
+ assert_context(
223
+ %Q(
224
+ A {
225
+ B [ 2 ], |
226
+ ),
227
+ %Q(
228
+ A {
229
+ B [
230
+ 2
231
+ ], |
232
+ ))
233
+ end
234
+
235
+ def test_linebreak_backslash
236
+ assert_context(
237
+ %Q(
238
+ A {
239
+ B arg: 1,|
240
+ ),
241
+ %Q(
242
+ A {
243
+ B \\
244
+ arg: 1,|
245
+ ))
246
+ end
247
+
248
+ def test_linebreak_whitespace_after_backslash
249
+ assert_context(
250
+ %Q(
251
+ A {
252
+ B arg: 1,|
253
+ ),
254
+ %Q(
255
+ A {
256
+ B \\
257
+ arg: 1,|
258
+ ))
259
+ end
260
+
261
+ def test_comment_annotation
262
+ assert_context(
263
+ %Q(
264
+ A {
265
+ B {
266
+ |F bla
267
+ ),
268
+ %Q(
269
+ A {
270
+ # bla
271
+ B {
272
+ C a1: v1, a2: "v2"
273
+ # bla
274
+ D {
275
+ E a1: 5
276
+ }
277
+ @ anno
278
+ |F bla
279
+ ))
280
+ end
281
+
282
+ def assert_context(expected, text)
283
+ # remove first and last lines
284
+ # these are empty because of the use of %Q
285
+ exp_lines = expected.split("\n")[1..-2]
286
+ exp_col = exp_lines.last.index("|")
287
+ exp_lines.last.sub!("|","")
288
+ in_lines = text.split("\n")[1..-2]
289
+ in_col = in_lines.last.index("|")
290
+ in_lines.last.sub!("|","")
291
+ ctx = RText::Frontend::Context.new
292
+ lines, out_col = ctx.extract(in_lines, in_col)
293
+ assert_equal exp_lines, lines
294
+ if exp_col && in_col
295
+ assert_equal exp_col, out_col
296
+ end
297
+ end
298
+
299
+ end
300
+
301
+