test/tc/skiplines.rb in rio-0.3.8 vs test/tc/skiplines.rb in rio-0.3.9

- old
+ new

@@ -7,23 +7,52 @@ require 'rio' require 'tc/testcase' class TC_skiplines < Test::RIO::TestCase @@once = false - N_LINES = 4 + N_LINES = 25 def self.once @@once = true - rio('f1') < (0...N_LINES).map { |i| "L#{i}:f1\n" } - rio('f2') < (0...N_LINES).map { |i| "L#{i}:f2\n" } - rio('g1') < (0...N_LINES).map { |i| "L#{i}:g1\n" } - rio('g2') < (0...N_LINES).map { |i| "L#{i}:g2\n" } + #rio('f1') < (0...N_LINES).map { |i| "L#{i}:f1" + $/ } + rio('f2') < (0...N_LINES).map { |i| "L#{i}:f2" + $/ } + #rio('g1') < (0...N_LINES).map { |i| "L#{i}:g1" + $/ } + #rio('g2') < (0...N_LINES).map { |i| "L#{i}:g2" + $/ } end def setup super self.class.once unless @@once + @lines = {} + #%w[f1 f2 g1 g2].each do |fname| + %w[f2].each do |fname| + @lines[fname] = rio(fname).to_a + end end + def test_basic + fname = 'f2' + + re = /1/ + exp = @lines[fname].reject{ |l| l =~ re } + + ans = [] + rio(fname).skiplines(re) { |l| ans << l } + assert_equal(exp,ans,"skiplines using #each with regular expression") + ans = rio(fname).skiplines[re] + assert_equal(exp,ans,"skiplines using array operator with regular expression") + + rng = (2..9) + + exp = @lines[fname][0..rng.first-1] + @lines[fname][rng.last+1...N_LINES] + + ans = [] + rio(fname).skiplines(rng) { |l| ans << l } + assert_equal(exp,ans,"skiplines using #each with line range") + ans = rio(fname).skiplines[rng] + assert_equal(exp,ans,"skiplines using array operator with line range") + + + end def test_prefix_lines # exprio = rio(@d0).skipfiles(/1/) # ansrio = rio(@d0).skip.files(/1/) r = rio('f1').skip.lines(1) # p r.cx