Sha256: 68de754c3becd4322e574c5886b6486eb109ab62602efb6c42147807fe67eba9

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')

require 'scout/open'

class TestOpenUtil < Test::Unit::TestCase
  def test_read_grep
    content =<<-EOF
1
2
3
4
    EOF
    TmpFile.with_file(content) do |file|
      sum = 0
      Open.read(file, :grep => '^1\|3') do |line| sum += line.to_i end
      assert_equal(1 + 3, sum)
    end

    TmpFile.with_file(content) do |file|
      sum = 0
      Open.read(file, :grep => ["1","3"]) do |line| sum += line.to_i end
      assert_equal(1 + 3, sum)
    end
  end

  def test_read_grep_invert
    content =<<-EOF
1
2
3
4
    EOF
    TmpFile.with_file(content) do |file|
      sum = 0
      Open.read(file, :grep => '^1\|3', :invert_grep => true) do |line| sum += line.to_i end
      assert_equal(2 + 4, sum)
    end

    TmpFile.with_file(content) do |file|
      sum = 0
      Open.read(file, :grep => ["1","3"]) do |line| sum += line.to_i end
      assert_equal(1 + 3, sum)
    end
  end

  def test_ln_s
    TmpFile.with_file do |directory|
      Path.setup(directory)
      file1 = directory.subdir1.file
      file2 = directory.subdir2.file
      Open.write(file1, "TEST")
      Open.ln_s file1, file2
      assert_equal "TEST", Open.read(file2)
      Open.write(file1, "TEST2")
      assert_equal "TEST2", Open.read(file2)
    end
  end

  def test_ln_h
    TmpFile.with_file do |directory|
      Path.setup(directory)
      file1 = directory.subdir1.file
      file2 = directory.subdir2.file
      Open.write(file1, "TEST")
      Open.ln_s file1, file2
      assert_equal "TEST", Open.read(file2)
      Open.write(file1, "TEST2")
      assert_equal "TEST2", Open.read(file2)
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
scout-essentials-1.6.2 test/scout/open/test_util.rb
scout-essentials-1.6.1 test/scout/open/test_util.rb
scout-essentials-1.6.0 test/scout/open/test_util.rb
scout-essentials-1.3.1 test/scout/open/test_util.rb
scout-essentials-1.3.0 test/scout/open/test_util.rb
scout-essentials-1.2.0 test/scout/open/test_util.rb
scout-essentials-1.1.1 test/scout/open/test_util.rb
scout-essentials-1.1.0 test/scout/open/test_util.rb
scout-essentials-1.0.0 test/scout/open/test_util.rb
scout-gear-9.1.0 test/scout/open/test_util.rb
scout-gear-9.0.0 test/scout/open/test_util.rb
scout-gear-8.1.0 test/scout/open/test_util.rb
scout-gear-8.0.0 test/scout/open/test_util.rb
scout-gear-7.3.0 test/scout/open/test_util.rb
scout-gear-7.2.0 test/scout/open/test_util.rb
scout-gear-7.1.0 test/scout/open/test_util.rb
scout-gear-6.0.0 test/scout/open/test_util.rb
scout-gear-5.2.0 test/scout/open/test_util.rb
scout-gear-5.1.1 test/scout/open/test_util.rb