~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/ruby/test_proc.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
  def test_method_to_proc
145
145
    b = block()
146
146
    assert_equal "OK", b.call
 
147
    assert_instance_of(Binding, b.binding, '[ruby-core:25589]')
147
148
  end
148
149
 
149
150
  def test_curry
177
178
    b = proc { :foo }
178
179
    assert_equal(:foo, b.curry[])
179
180
 
180
 
    b = lambda {|x, y, &b| b.call(x + y) }.curry
 
181
    b = lambda {|x, y, &blk| blk.call(x + y) }.curry
181
182
    b = b.call(2) { raise }
182
183
    b = b.call(3) {|x| x + 4 }
183
184
    assert_equal(9, b)
189
190
    assert_equal(true, l.lambda?)
190
191
    assert_equal(true, l.curry.lambda?, '[ruby-core:24127]')
191
192
  end
192
 
 
 
193
 
193
194
  def test_curry_ski_fib
194
195
    s = proc {|f, g, x| f[x][g[x]] }.curry
195
196
    k = proc {|x, y| x }.curry
291
292
  def test_arity2
292
293
    assert_equal(0, method(:proc).to_proc.arity)
293
294
    assert_equal(-1, proc {}.curry.arity)
 
295
 
 
296
    c = Class.new
 
297
    c.class_eval { attr_accessor :foo }
 
298
    assert_equal(1, c.new.method(:foo=).to_proc.arity)
294
299
  end
295
300
 
296
301
  def test_proc_location
304
309
    b2 = b1.dup
305
310
    assert(b1 == b2)
306
311
  end
307
 
  
 
312
 
308
313
  def test_to_proc
309
314
    b = proc { :foo }
310
315
    assert_equal(:foo, b.to_proc.call)
374
379
    assert_equal [1,2,3,[4,5,6]], pr.call([1,2,3,4,5,6])
375
380
 
376
381
    r = proc{|*a| a}.call([1,2,3])
377
 
    assert [1,2,3], r
 
382
    assert_equal [[1,2,3]], r
378
383
  end
379
384
 
380
385
  def test_proc_args_rest_and_post
615
620
    assert_equal [1, 2, 3, 4, 5, 6, Proc, :x], (pr.call(1, 2, 3, 4, 5, 6, 7){|x| x})
616
621
  end
617
622
 
618
 
  def test_proc_args_opt_and_block
 
623
  def test_proc_args_opt_and_block2
619
624
    pr = proc {|a,b,c=:c,d=:d,*e,&f|
620
625
      [a, b, c, d, e, f.class, f&&f.call(:x)]
621
626
    }
686
691
    assert_equal([1,2,[3],4,5], r, "[ruby-core:19485]")
687
692
  end
688
693
 
 
694
  def test_parameters
 
695
    assert_equal([], proc {}.parameters)
 
696
    assert_equal([], proc {||}.parameters)
 
697
    assert_equal([[:opt, :a]], proc {|a|}.parameters)
 
698
    assert_equal([[:opt, :a], [:opt, :b]], proc {|a, b|}.parameters)
 
699
    assert_equal([[:opt, :a], [:block, :b]], proc {|a=:a, &b|}.parameters)
 
700
    assert_equal([[:opt, :a], [:opt, :b]], proc {|a, b=:b|}.parameters)
 
701
    assert_equal([[:rest, :a]], proc {|*a|}.parameters)
 
702
    assert_equal([[:opt, :a], [:rest, :b], [:block, :c]], proc {|a, *b, &c|}.parameters)
 
703
    assert_equal([[:opt, :a], [:rest, :b], [:opt, :c]], proc {|a, *b, c|}.parameters)
 
704
    assert_equal([[:opt, :a], [:rest, :b], [:opt, :c], [:block, :d]], proc {|a, *b, c, &d|}.parameters)
 
705
    assert_equal([[:opt, :a], [:opt, :b], [:rest, :c], [:opt, :d], [:block, :e]], proc {|a, b=:b, *c, d, &e|}.parameters)
 
706
    assert_equal([[:opt, nil], [:block, :b]], proc {|(a), &b|}.parameters)
 
707
    assert_equal([[:opt, :a], [:opt, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:opt, :f], [:opt, :g], [:block, :h]], proc {|a,b,c=:c,d=:d,*e,f,g,&h|}.parameters)
 
708
 
 
709
    assert_equal([[:req]], method(:putc).parameters)
 
710
    assert_equal([[:rest]], method(:p).parameters)
 
711
  end
 
712
 
 
713
  def pm0() end
 
714
  def pm1(a) end
 
715
  def pm2(a, b) end
 
716
  def pmo1(a = :a, &b) end
 
717
  def pmo2(a, b = :b) end
 
718
  def pmo3(*a) end
 
719
  def pmo4(a, *b, &c) end
 
720
  def pmo5(a, *b, c) end
 
721
  def pmo6(a, *b, c, &d) end
 
722
  def pmo7(a, b = :b, *c, d, &e) end
 
723
  def pma1((a), &b) end
 
724
 
 
725
 
 
726
  def test_bound_parameters
 
727
    assert_equal([], method(:pm0).to_proc.parameters)
 
728
    assert_equal([[:req, :a]], method(:pm1).to_proc.parameters)
 
729
    assert_equal([[:req, :a], [:req, :b]], method(:pm2).to_proc.parameters)
 
730
    assert_equal([[:opt, :a], [:block, :b]], method(:pmo1).to_proc.parameters)
 
731
    assert_equal([[:req, :a], [:opt, :b]], method(:pmo2).to_proc.parameters)
 
732
    assert_equal([[:rest, :a]], method(:pmo3).to_proc.parameters)
 
733
    assert_equal([[:req, :a], [:rest, :b], [:block, :c]], method(:pmo4).to_proc.parameters)
 
734
    assert_equal([[:req, :a], [:rest, :b], [:req, :c]], method(:pmo5).to_proc.parameters)
 
735
    assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).to_proc.parameters)
 
736
    assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters)
 
737
    assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters)
 
738
 
 
739
    assert_equal([], "".method(:upcase).to_proc.parameters)
 
740
    assert_equal([[:rest]], "".method(:gsub).to_proc.parameters)
 
741
    assert_equal([[:rest]], proc {}.curry.parameters)
 
742
  end
 
743
 
689
744
  def test_to_s
690
745
    assert_match(/^#<Proc:0x\h+@#{ Regexp.quote(__FILE__) }:\d+>$/, proc {}.to_s)
691
746
    assert_match(/^#<Proc:0x\h+@#{ Regexp.quote(__FILE__) }:\d+ \(lambda\)>$/, lambda {}.to_s)
695
750
    assert(x.to_s.tainted?)
696
751
  end
697
752
 
698
 
  def source_location_test
699
 
    __LINE__
 
753
  @@line_of_source_location_test = __LINE__ + 1
 
754
  def source_location_test a=1,
 
755
    b=2
700
756
  end
701
757
 
702
758
  def test_source_location
703
759
    file, lineno = method(:source_location_test).source_location
704
760
    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
705
 
    assert_equal(source_location_test - 1, lineno)
 
761
    assert_equal(@@line_of_source_location_test, lineno, 'Bug #2427')
 
762
  end
 
763
 
 
764
  @@line_of_attr_reader_source_location_test   = __LINE__ + 3
 
765
  @@line_of_attr_writer_source_location_test   = __LINE__ + 3
 
766
  @@line_of_attr_accessor_source_location_test = __LINE__ + 3
 
767
  attr_reader   :attr_reader_source_location_test
 
768
  attr_writer   :attr_writer_source_location_test
 
769
  attr_accessor :attr_accessor_source_location_test
 
770
 
 
771
  def test_attr_source_location
 
772
    file, lineno = method(:attr_reader_source_location_test).source_location
 
773
    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
 
774
    assert_equal(@@line_of_attr_reader_source_location_test, lineno)
 
775
 
 
776
    file, lineno = method(:attr_writer_source_location_test=).source_location
 
777
    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
 
778
    assert_equal(@@line_of_attr_writer_source_location_test, lineno)
 
779
 
 
780
    file, lineno = method(:attr_accessor_source_location_test).source_location
 
781
    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
 
782
    assert_equal(@@line_of_attr_accessor_source_location_test, lineno)
 
783
 
 
784
    file, lineno = method(:attr_accessor_source_location_test=).source_location
 
785
    assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
 
786
    assert_equal(@@line_of_attr_accessor_source_location_test, lineno)
706
787
  end
707
788
 
708
789
  def test_splat_without_respond_to