Sha256: fbf2fa55cdd92b5f87bb6cd1c0bd561b8958f412fe648d6f4c92a8598d8defe3

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

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 'wrap' do
    pipeline = each(%w(foo bar)) | wrap(each{ |x| x.chars}, :each)
    expected = %w(r a b o o f)
    while !pipeline.done?
      assert_equal(expected.pop, pipeline.run)
    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

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

  test 'cache' do
    order = []
    pipeline = each([1, 3, 2, 3, 2, 1]) | map{|x| order << 'a'; x} | cache  | map{|x| order << 'b'; x} | run_until_exhausted
    assert_equal([1, 3, 2, 3, 2, 1], pipeline.run)
    assert_equal(%w(a a a a a a b b b b b b), order)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stages-0.4.0 test/test_syntax.rb