summaryrefslogtreecommitdiff
path: root/yarvtest
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-05 18:50:35 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-05 18:50:35 +0000
commita4a81019653287291f88563964d482798da6221f (patch)
treeec7c2bdf59d69e9f2b87b1c45e51977b0ed792e2 /yarvtest
parent0d70d8864359e6d8c410dd2727de618ba7cc3dc7 (diff)
downloadbundler-a4a81019653287291f88563964d482798da6221f.tar.gz
* proc.c: support Binding#eval.
* yarvtest/test_eval.rb: add a test for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'yarvtest')
-rw-r--r--yarvtest/test_eval.rb434
1 files changed, 221 insertions, 213 deletions
diff --git a/yarvtest/test_eval.rb b/yarvtest/test_eval.rb
index fc4ac0372d..8a82c4cff4 100644
--- a/yarvtest/test_eval.rb
+++ b/yarvtest/test_eval.rb
@@ -1,213 +1,221 @@
-require 'yarvtest/yarvtest'
-
-class TestEval < YarvTestBase
- def test_eval
- ae %q{
- eval('1')
- }
- ae %q{
- eval('a=1; a')
- }
- ae %q{
- a = 1
- eval('a')
- }
- end
-
- def test_eval_with_send
- ae %q{
- __send! :eval, %{
- :ok
- }
- }
- ae %q{
- 1.__send! :instance_eval, %{
- :ok
- }
- }
- end
-
- def test_module_eval
- ae %q{
- Const = :top
- class C
- Const = :C
- end
- C.module_eval{
- Const
- }
- }
- ae %q{
- Const = :top
- class C
- Const = :C
- end
- C.module_eval %{
- Const
- }
- } if false # TODO: Ruby 1.9 error
-
- ae %q{
- Const = :top
- class C
- Const = :C
- end
- C.class_eval %{
- def m
- Const
- end
- }
- C.new.m
- }
- ae %q{
- Const = :top
- class C
- Const = :C
- end
- C.class_eval{
- def m
- Const
- end
- }
- C.new.m
- }
- end
-
- def test_instance_eval
- ae %q{
- 1.instance_eval{
- self
- }
- }
- ae %q{
- 'foo'.instance_eval{
- self
- }
- }
- ae %q{
- class Fixnum
- Const = 1
- end
- 1.instance_eval %{
- Const
- }
- }
- end
-
- def test_nest_eval
- ae %q{
- Const = :top
- class C
- Const = :C
- end
- $nest = false
- $ans = []
- def m
- $ans << Const
- C.module_eval %{
- $ans << Const
- Boo = false unless defined? Boo
- unless $nest
- $nest = true
- m
- end
- }
- end
- m
- $ans
- }
- ae %q{
- $nested = false
- $ans = []
- $pr = proc{
- $ans << self
- unless $nested
- $nested = true
- $pr.call
- end
- }
- class C
- def initialize &b
- 10.instance_eval(&b)
- end
- end
- C.new(&$pr)
- $ans
- }
- end
-
- def test_binding
- ae %q{
- def m
- a = :ok
- $b = binding
- end
- m
- eval('a', $b)
- }
- ae %q{
- def m
- a = :ok
- $b = binding
- end
- m
- eval('b = :ok2', $b)
- eval('[a, b]', $b)
- }
- ae %q{
- $ans = []
- def m
- $b = binding
- end
- m
- $ans << eval(%q{
- $ans << eval(%q{
- a
- }, $b)
- a = 1
- }, $b)
- $ans
- }
- ae %q{
- Const = :top
- class C
- Const = :C
- def m
- binding
- end
- end
- eval('Const', C.new.m)
- }
- ae %q{
- Const = :top
- a = 1
- class C
- Const = :C
- def m
- eval('Const', TOPLEVEL_BINDING)
- end
- end
- C.new.m
- }
- ae %q{
- class C
- $b = binding
- end
- eval %q{
- def m
- :ok
- end
- }, $b
- p C.new.m
- }
- ae %q{
- b = proc{
- a = :ok
- binding
- }.call
- a = :ng
- eval("a", b)
- }
- end
-end
-
+require 'yarvtest/yarvtest'
+
+class TestEval < YarvTestBase
+ def test_eval
+ ae %q{
+ eval('1')
+ }
+ ae %q{
+ eval('a=1; a')
+ }
+ ae %q{
+ a = 1
+ eval('a')
+ }
+ end
+
+ def test_eval_with_send
+ ae %q{
+ __send! :eval, %{
+ :ok
+ }
+ }
+ ae %q{
+ 1.__send! :instance_eval, %{
+ :ok
+ }
+ }
+ end
+
+ def test_module_eval
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ end
+ C.module_eval{
+ Const
+ }
+ }
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ end
+ C.module_eval %{
+ Const
+ }
+ } if false # TODO: Ruby 1.9 error
+
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ end
+ C.class_eval %{
+ def m
+ Const
+ end
+ }
+ C.new.m
+ }
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ end
+ C.class_eval{
+ def m
+ Const
+ end
+ }
+ C.new.m
+ }
+ end
+
+ def test_instance_eval
+ ae %q{
+ 1.instance_eval{
+ self
+ }
+ }
+ ae %q{
+ 'foo'.instance_eval{
+ self
+ }
+ }
+ ae %q{
+ class Fixnum
+ Const = 1
+ end
+ 1.instance_eval %{
+ Const
+ }
+ }
+ end
+
+ def test_nest_eval
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ end
+ $nest = false
+ $ans = []
+ def m
+ $ans << Const
+ C.module_eval %{
+ $ans << Const
+ Boo = false unless defined? Boo
+ unless $nest
+ $nest = true
+ m
+ end
+ }
+ end
+ m
+ $ans
+ }
+ ae %q{
+ $nested = false
+ $ans = []
+ $pr = proc{
+ $ans << self
+ unless $nested
+ $nested = true
+ $pr.call
+ end
+ }
+ class C
+ def initialize &b
+ 10.instance_eval(&b)
+ end
+ end
+ C.new(&$pr)
+ $ans
+ }
+ end
+
+ def test_binding
+ ae %q{
+ def m
+ a = :ok
+ $b = binding
+ end
+ m
+ eval('a', $b)
+ }
+ ae %q{
+ def m
+ a = :ok
+ $b = binding
+ end
+ m
+ eval('b = :ok2', $b)
+ eval('[a, b]', $b)
+ }
+ ae %q{
+ $ans = []
+ def m
+ $b = binding
+ end
+ m
+ $ans << eval(%q{
+ $ans << eval(%q{
+ a
+ }, $b)
+ a = 1
+ }, $b)
+ $ans
+ }
+ ae %q{
+ Const = :top
+ class C
+ Const = :C
+ def m
+ binding
+ end
+ end
+ eval('Const', C.new.m)
+ }
+ ae %q{
+ Const = :top
+ a = 1
+ class C
+ Const = :C
+ def m
+ eval('Const', TOPLEVEL_BINDING)
+ end
+ end
+ C.new.m
+ }
+ ae %q{
+ class C
+ $b = binding
+ end
+ eval %q{
+ def m
+ :ok
+ end
+ }, $b
+ p C.new.m
+ }
+ ae %q{
+ b = proc{
+ a = :ok
+ binding
+ }.call
+ a = :ng
+ eval("a", b)
+ }
+ ae %q{
+ class C
+ def foo
+ binding
+ end
+ end
+ C.new.foo.eval("self.class.to_s")
+ }
+ end
+end
+