Sha256: 3bff44fb1be45398720777c4dc270e3b61b1526d8ed490f617802042dc423f1d

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

require 'helper'
include Stages

class TestSyntax < MiniTest::Unit::TestCase
  include Stages::Sugar

  test 'select and map' do
    pipeline = evens | select{ |val| val > 6} | map{ |val| val * 2}
    assert_equal(16, pipeline.run)
  end

  test 'each and group' do
    pipeline = each([1, 2, 3]) | map{ |x| [1]*x} | each | group
    assert_equal({ 1 => 6}, pipeline.run)
  end

  test 'restrict and resume' do
    pipeline = each(%w(foo bar)) | restrict | each{ |x| x.chars} | resume
    result = []
    while v = pipeline.run
      result << v
    end
    assert_equal([{ 'foo' => %w(f o o)}, {'bar' => %w(b a r)}], result)
  end

  test 'wrap' do
    pipeline = each(%w(foo bar)) | wrap(each{ |x| x.chars}, :each)
    expected = %w(r a b o o f)
    while r = pipeline.run
      assert_equal(expected.pop, r)
    end
  end

  test 'unique and exhaust' do
    pipeline = each([1, 3, 2, 3, 2, 1]) | unique | run_until_exhausted
    assert_equal([1, 3, 2], pipeline.run)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stages-0.2.10 test/test_syntax.rb
stages-0.2.9 test/test_syntax.rb
stages-0.2.8 test/test_syntax.rb
stages-0.2.7 test/test_syntax.rb
stages-0.2.6 test/test_syntax.rb