positionrange 0.6.2 → 0.6.4

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.
data/CHANGELOG ADDED
@@ -0,0 +1,25 @@
1
+ *0.6.4* (May 2009)
2
+
3
+ * Fixed bug in translate_to/from_view
4
+ * Added non-'!' alternatives to methods
5
+ * Changed license to LGPL v3
6
+
7
+
8
+ *0.6.3* (4 February 2009)
9
+
10
+ * Updated README
11
+
12
+
13
+ *0.6.2* (20 January 2009)
14
+
15
+ * Updated link to docs in README.txt
16
+
17
+
18
+ *0.6.1* (31 December 2008)
19
+
20
+ * Updated README
21
+
22
+
23
+ *0.6.0* (28 December 2008)
24
+
25
+ * First release as a gem
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -1,4 +1,6 @@
1
- = Position Range -- Ranges with attributes that can be juggled
1
+ = Position Range Gem documentation
2
+
3
+ -- Ranges with attributes that can be juggled
2
4
 
3
5
  Allows you to assign random attributes to ranges and juggle them in
4
6
  lists. Also adds parsing from string, but most intereting when used in
@@ -65,31 +67,19 @@ Clustering overlaps maintains attributes.
65
67
  > l.cluster_overlaps == output
66
68
  => true
67
69
 
68
- == Download
69
-
70
- The latest version of Position Range can be found at:
71
-
72
- * http://rubyforge.org/frs/?group_id=7564
73
-
74
- Documentation can be found at:
75
-
76
- * http://positionrange.rubyforge.org
77
-
78
70
  == Installation
79
71
 
80
72
  You can install Position Range with the following command:
81
73
 
82
74
  % [sudo] gem install positionrange
83
75
 
84
- Or from its distribution directory with:
85
-
86
- % [sudo] ruby install.rb
76
+ The latest version of Diff LCS can also be downloaded at:
87
77
 
88
- == License
78
+ * http://rubyforge.org/frs/?group_id=7564
89
79
 
90
- Position Range is released under the GNU Affero GPL licence.
80
+ And then from its distribution directory installed with:
91
81
 
92
- * http://www.fsf.org/licensing/licenses/agpl-3.0.html
82
+ % [sudo] ruby install.rb
93
83
 
94
84
  == Support
95
85
 
@@ -101,3 +91,22 @@ For the latest news on Position Range:
101
91
 
102
92
  Feel free to submit commits or feature requests. If you send a patch,
103
93
  remember to update the corresponding unit tests.
94
+
95
+ == This Documentation
96
+
97
+ This documentation can be browsed online at:
98
+
99
+ * http://positionrange.rubyforge.org
100
+
101
+ == Copyrights
102
+
103
+ Position Range and these docs are Copyright (c) 2006-2009 The LogiLogi
104
+ Foundation. Position Range is licensed under the {Affero General Public
105
+ License}[http://www.fsf.org/licensing/licenses/agpl-3.0.html].
106
+ These docs are available under the {Creative Commons Attribution-Share
107
+ Alike License}[http://creativecommons.org/licenses/by-sa/3.0/].
108
+
109
+ If you want to use Position Range in a publicly accessable application
110
+ that is not Free Software (that means not Affero GPLed), then please
111
+ {contact us}[mailto:foundation@logilogi.org] for single server
112
+ licenses or special arrangements.
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ Rake::RDocTask.new { |rdoc|
34
34
  rdoc.title = "Position Range -- Ranges with attributes that can be juggled"
35
35
  rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
36
36
  rdoc.options << '--charset' << 'utf-8'
37
- rdoc.rdoc_files.include('README.txt', 'CHANGELOG.txt')
37
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
38
38
  rdoc.rdoc_files.include('lib/position_range.rb')
39
39
  rdoc.rdoc_files.include('lib/position_range/*.rb')
40
40
  }
@@ -56,7 +56,7 @@ spec = Gem::Specification.new do |s|
56
56
  s.requirements << 'none'
57
57
  s.require_path = 'lib'
58
58
 
59
- s.files = [ "Rakefile", "install.rb", "README.txt", "CHANGELOG.txt", "LICENSE.txt" ]
59
+ s.files = [ "Rakefile", "install.rb", "README", "CHANGELOG", "LICENSE" ]
60
60
  s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
61
61
  s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
62
62
  end
@@ -57,7 +57,7 @@ class PositionRange::List < Array
57
57
  # Returns a new PositionRangeList for the provided string, covering
58
58
  # it from start to end (the 'string' can also be an array).
59
59
  #
60
- def self.new_around(string)
60
+ def self.around(string)
61
61
  if string.size > 0
62
62
  return PositionRange::List.new([PositionRange.new(0,string.size)])
63
63
  else
@@ -97,7 +97,7 @@ class PositionRange::List < Array
97
97
  # Attributes are ignored.
98
98
  #
99
99
  def within?(other)
100
- if (self.dup.substract!(other, :ignore_attributes => true)).empty?
100
+ if (self.substract(other, :ignore_attributes => true)).empty?
101
101
  return true
102
102
  else
103
103
  return false
@@ -134,16 +134,16 @@ class PositionRange::List < Array
134
134
  # 1,5:7,8:10,12' becomes '2,5:11,12' after limiting to '2,6:11,40'
135
135
  #
136
136
  def &(other)
137
- substraction_list = other.dup.invert!
138
- return self.dup.substract!(substraction_list,:ignore_attributes => true)
137
+ substraction_list = other.invert
138
+ return self.substract(substraction_list, :ignore_attributes => true)
139
139
  end
140
140
 
141
141
  # Applies a substraction in the sense of Set theory.
142
142
  #
143
- # See substract!
143
+ # See substract
144
144
  #
145
145
  def -(other)
146
- self.dup.substract!(other)
146
+ self.substract(other)
147
147
  end
148
148
 
149
149
  # Applies a substraction in the sense of Set theory.
@@ -160,7 +160,7 @@ class PositionRange::List < Array
160
160
  # Options
161
161
  # <tt>:ignore_attributes</tt> => Ignores attributes
162
162
  #
163
- def substract!(other,options = {})
163
+ def substract!(other, options = {})
164
164
  ignore_attributes = options[:ignore_attributes]
165
165
 
166
166
  sorted_self = self.sort
@@ -201,12 +201,28 @@ class PositionRange::List < Array
201
201
  return self
202
202
  end
203
203
 
204
+ # Substraction returning a new list.
205
+ #
206
+ # See substract!
207
+ #
208
+ def substract(other, options = {})
209
+ self.dup.substract!(other)
210
+ end
211
+
204
212
  # Deletes the position_range that is specified.
205
213
  #
206
- def delete(p_r)
214
+ def delete!(p_r)
207
215
  self.substract!(PositionRange::List.new([p_r]))
208
216
  end
209
217
 
218
+ # Deletion returning a new list.
219
+ #
220
+ # See delete!
221
+ #
222
+ def delete(p_r)
223
+ self.substract(PositionRange::List.new([p_r]))
224
+ end
225
+
210
226
  # Results in all positions being included, being excluded now, and
211
227
  # all positions that were excluded, being included now, upto the
212
228
  # range below maximum_size.
@@ -246,6 +262,14 @@ class PositionRange::List < Array
246
262
  return self
247
263
  end
248
264
 
265
+ # Inversion returning a new list.
266
+ #
267
+ # See invert!
268
+ #
269
+ def invert(maximum_size = PositionRange::MaximumSize)
270
+ self.dup.invert!
271
+ end
272
+
249
273
  # Makes sure that there are no non-overlapping borders between
250
274
  # PositionRanges.
251
275
  #
@@ -297,6 +321,14 @@ class PositionRange::List < Array
297
321
  return self
298
322
  end
299
323
 
324
+ # Lining up overlaps returning a new list.
325
+ #
326
+ # See line_up_overlaps!
327
+ #
328
+ def line_up_overlaps
329
+ self.dup.line_up_overlaps!
330
+ end
331
+
300
332
  # Simplifies the PositionRange::List by merging adjacent PositionRanges.
301
333
  #
302
334
  # Example:
@@ -322,6 +354,14 @@ class PositionRange::List < Array
322
354
  return self
323
355
  end
324
356
 
357
+ # Merging adjacents returning a new list.
358
+ #
359
+ # See merge_adjacents!
360
+ #
361
+ def merge_adjacents(options = {})
362
+ self.dup.merge_adjacents!(options)
363
+ end
364
+
325
365
  # Translates the PositionRange::List in space, along the given vector.
326
366
  #
327
367
  def translate!(integer)
@@ -334,6 +374,14 @@ class PositionRange::List < Array
334
374
  return self
335
375
  end
336
376
 
377
+ # Translation returning a new list.
378
+ #
379
+ # See translate!
380
+ #
381
+ def translate(integer)
382
+ self.dup.translate!(integer)
383
+ end
384
+
337
385
  # The ranges_to_insert are inserted at the ranges_at_which_to_insert
338
386
  # of this list, counted in range_size from it's beginning, and inter-
339
387
  # luded with ranges_to_skip.
@@ -385,6 +433,16 @@ class PositionRange::List < Array
385
433
  return self
386
434
  end
387
435
 
436
+ # Inserting at ranges returning a new list.
437
+ #
438
+ # See insert_at_ranges!
439
+ #
440
+ def insert_at_ranges(ranges_to_insert, ranges_at_which_to_insert,
441
+ ranges_to_skip = [])
442
+ return self.dup.insert_at_ranges!(ranges_to_insert, ranges_at_which_to_insert,
443
+ ranges_to_skip)
444
+ end
445
+
388
446
  ### Highlevel methods
389
447
 
390
448
  # Translates the PositionRange::List into the relative space defined
@@ -392,13 +450,16 @@ class PositionRange::List < Array
392
450
  #
393
451
  def translate_to_view(view_position_range_list)
394
452
  relative = PositionRange::List.new
395
- view_p = 0
396
- view_position_range_list.each {|snippet_p_r|
397
- translate_list = self & PositionRange::List.new([snippet_p_r])
398
- vector = view_p - snippet_p_r.first
399
- relative.concat(translate_list.translate!(vector))
400
- view_p += snippet_p_r.size
401
- }
453
+ self.each do |p_r|
454
+ view_p = 0
455
+ p_r_list = PositionRange::List.new([p_r])
456
+ view_position_range_list.each do |snippet_p_r|
457
+ translate_list = p_r_list & PositionRange::List.new([snippet_p_r])
458
+ vector = view_p - snippet_p_r.first
459
+ relative.concat(translate_list.translate!(vector))
460
+ view_p += snippet_p_r.size
461
+ end
462
+ end
402
463
  relative.merge_adjacents!
403
464
  return relative
404
465
  end
@@ -407,14 +468,17 @@ class PositionRange::List < Array
407
468
  #
408
469
  def translate_from_view(view_position_range_list)
409
470
  absolute = PositionRange::List.new
410
- view_p = 0
411
- view_position_range_list.each {|snippet_p_r|
412
- translate_list = self & PositionRange::List.new(
413
- [PositionRange.new(view_p,view_p + snippet_p_r.size)])
414
- vector = snippet_p_r.first - view_p
415
- absolute.concat(translate_list.translate!(vector))
416
- view_p += snippet_p_r.size
417
- }
471
+ self.each do |p_r|
472
+ view_p = 0
473
+ p_r_list = PositionRange::List.new([p_r])
474
+ view_position_range_list.each do |snippet_p_r|
475
+ translate_list = p_r_list & PositionRange::List.new(
476
+ [PositionRange.new(view_p,view_p + snippet_p_r.size)])
477
+ vector = snippet_p_r.first - view_p
478
+ absolute.concat(translate_list.translate!(vector))
479
+ view_p += snippet_p_r.size
480
+ end
481
+ end
418
482
  absolute.merge_adjacents!
419
483
  return absolute
420
484
  end
@@ -454,7 +518,7 @@ class PositionRange::List < Array
454
518
  #
455
519
  def cluster_overlaps
456
520
  if !self.empty?
457
- lined_up_self = self.dup.line_up_overlaps!
521
+ lined_up_self = self.line_up_overlaps
458
522
  clusters = [PositionRange::List.new().push(lined_up_self.shift)]
459
523
  lined_up_self.each {|p_r|
460
524
  if p_r == clusters.last[0]
@@ -2,7 +2,7 @@ module PositionRange
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 6
5
- TINY = 2
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -37,13 +37,13 @@ class PositionRangeListTest < Test::Unit::TestCase
37
37
  }
38
38
  end
39
39
 
40
- def test_new_around
40
+ def test_around
41
41
  assert_equal PositionRange::List.from_s('0,5'),
42
- PositionRange::List.new_around('12345')
42
+ PositionRange::List.around('12345')
43
43
  assert_equal PositionRange::List.from_s('0,3'),
44
- PositionRange::List.new_around([1,2,3])
44
+ PositionRange::List.around([1,2,3])
45
45
  assert_equal PositionRange::List.new,
46
- PositionRange::List.new_around('')
46
+ PositionRange::List.around('')
47
47
  end
48
48
 
49
49
  ### Getters
@@ -184,11 +184,30 @@ class PositionRangeListTest < Test::Unit::TestCase
184
184
  old = PositionRange::List.from_s('5,15:16,25')
185
185
  new = old.dup << PositionRange.new(10,20, :attr => 5)
186
186
  assert_equal PositionRange::List.new, old - new
187
+
188
+ # dup-alternatives
189
+ p = PositionRange::List.from_s('1,15')
190
+ to_p = PositionRange::List.from_s('2,6:7,12')
191
+
192
+ assert_equal to_p, p.substract(
193
+ PositionRange::List.from_s('1,2:6,7:12,20'))
194
+ assert p != to_p
195
+
196
+ assert_equal to_p, p.substract!(
197
+ PositionRange::List.from_s('1,2:6,7:12,20'))
198
+ assert_equal p, to_p
187
199
  end
188
200
 
189
201
  def test_delete
190
- assert_equal PositionRange::List.from_s('1,3:6,8'),
191
- PositionRange::List.from_s('1,5:4,8').delete(PositionRange.new(3,6))
202
+ # dup-alternatives
203
+ p = PositionRange::List.from_s('1,5:4,8')
204
+ to_p = PositionRange::List.from_s('1,3:6,8')
205
+
206
+ assert_equal to_p, p.delete(PositionRange.new(3,6))
207
+ assert p != to_p
208
+
209
+ assert_equal to_p, p.delete!(PositionRange.new(3,6))
210
+ assert_equal p, to_p
192
211
  end
193
212
 
194
213
  def test_invert
@@ -211,6 +230,16 @@ class PositionRangeListTest < Test::Unit::TestCase
211
230
  PositionRange::List.new.invert!(55)
212
231
  assert_equal PositionRange::List.new,
213
232
  PositionRange::List.new.invert!(0)
233
+
234
+ # dup-alternatives
235
+ p = PositionRange::List.from_s('5,15')
236
+ to_p = PositionRange::List.from_s('0,5:15,' + PositionRange::MaximumSize.to_s)
237
+
238
+ assert_equal to_p, p.invert
239
+ assert p != to_p
240
+
241
+ assert_equal to_p, p.invert!
242
+ assert_equal p, to_p
214
243
  end
215
244
 
216
245
  def test_line_up_overlaps
@@ -272,6 +301,16 @@ class PositionRangeListTest < Test::Unit::TestCase
272
301
  # empty
273
302
  assert_equal PositionRange::List.new,
274
303
  PositionRange::List.new.line_up_overlaps!
304
+
305
+ # dup-alternatives
306
+ p = PositionRange::List.from_s('2,6:0,8')
307
+ to_p = PositionRange::List.from_s('0,2:2,6:2,6:6,8')
308
+
309
+ assert_equal to_p, p.line_up_overlaps
310
+ assert p != to_p
311
+
312
+ assert_equal to_p, p.line_up_overlaps!
313
+ assert_equal p, to_p
275
314
  end
276
315
 
277
316
  def test_merge_adjacents
@@ -300,6 +339,16 @@ class PositionRangeListTest < Test::Unit::TestCase
300
339
  # empty
301
340
  assert_equal PositionRange::List.new,
302
341
  PositionRange::List.new.merge_adjacents!
342
+
343
+ # dup-alternatives
344
+ p = PositionRange::List.from_s('2,4:4,8')
345
+ to_p = PositionRange::List.from_s('2,8')
346
+
347
+ assert_equal to_p, p.merge_adjacents
348
+ assert p != to_p
349
+
350
+ assert_equal to_p, p.merge_adjacents!
351
+ assert_equal p, to_p
303
352
  end
304
353
 
305
354
  def test_translate
@@ -314,6 +363,16 @@ class PositionRangeListTest < Test::Unit::TestCase
314
363
  # empty
315
364
  assert_equal PositionRange::List.new,
316
365
  PositionRange::List.new.translate!(5)
366
+
367
+ # dup-alternatives
368
+ p = PositionRange::List.from_s('10,13:16,18')
369
+ to_p = PositionRange::List.from_s('13,16:19,21')
370
+
371
+ assert_equal to_p, p.translate(3)
372
+ assert p != to_p
373
+
374
+ assert_equal to_p, p.translate!(3)
375
+ assert_equal p, to_p
317
376
  end
318
377
 
319
378
  def test_insert_at_ranges
@@ -353,6 +412,20 @@ class PositionRangeListTest < Test::Unit::TestCase
353
412
  PositionRange::List.from_s('0,750:100,250').insert_at_ranges!(
354
413
  PositionRange::List.from_s('20,30:40,50'),
355
414
  PositionRange::List.from_s('800,810:850,860'))
415
+
416
+ # dup-alternatives
417
+ p = PositionRange::List.from_s('0,10:15,20')
418
+ to_p = PositionRange::List.from_s('0,10:50,59:15,20')
419
+
420
+ assert_equal to_p, p.insert_at_ranges(
421
+ PositionRange::List.from_s('50,59'),
422
+ PositionRange::List.from_s('11,20'))
423
+ assert p != to_p
424
+
425
+ assert_equal to_p, p.insert_at_ranges!(
426
+ PositionRange::List.from_s('50,59'),
427
+ PositionRange::List.from_s('11,20'))
428
+ assert_equal p, to_p
356
429
  end
357
430
 
358
431
  ### Highlevel methods
@@ -372,9 +445,14 @@ class PositionRangeListTest < Test::Unit::TestCase
372
445
  assert_equal PositionRange::List.from_s('2,7'),
373
446
  p.translate_to_view(PositionRange::List.from_s('1,5:10,13'))
374
447
  # last before the first
375
- assert_equal PositionRange::List.from_s('3,9:16,18'),
448
+ assert_equal PositionRange::List.from_s('16,18:3,9'),
376
449
  p.translate_to_view(PositionRange::List.from_s('7,20:0,6'))
377
450
 
451
+ # interrupted
452
+ p = PositionRange::List.from_s('10,20:90,100:20,30')
453
+ assert_equal PositionRange::List.from_s('0,10:70,80:10,20'),
454
+ p.translate_to_view(PositionRange::List.from_s('10,50:60,100'))
455
+
378
456
  # empty
379
457
  assert_equal PositionRange::List.new,
380
458
  PositionRange::List.new.translate_to_view(
@@ -400,6 +478,10 @@ class PositionRangeListTest < Test::Unit::TestCase
400
478
  p = PositionRange::List.from_s('5,6:1,2')
401
479
  assert_equal PositionRange::List.from_s('6,7:2,3'),
402
480
  p.translate_from_view(PositionRange::List.from_s('1,8'))
481
+ # interrupted
482
+ p = PositionRange::List.from_s('0,10:70,80:10,20')
483
+ assert_equal PositionRange::List.from_s('10,20:90,100:20,30'),
484
+ p.translate_from_view(PositionRange::List.from_s('10,50:60,100'))
403
485
 
404
486
  # empty
405
487
  assert_equal PositionRange::List.new,