Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.test/src/com/oracle/truffle/ruby/test/core/KernelTests.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children | dd0ba029bf34 |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
1 /* | |
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This | |
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, | |
4 * redistribute it and/or modify it under the terms of the: | |
5 * | |
6 * Eclipse Public License version 1.0 | |
7 * GNU General Public License version 2 | |
8 * GNU Lesser General Public License version 2.1 | |
9 */ | |
10 package com.oracle.truffle.ruby.test.core; | |
11 | |
12 import org.junit.*; | |
13 | |
14 import com.oracle.truffle.ruby.runtime.configuration.*; | |
15 import com.oracle.truffle.ruby.test.*; | |
16 | |
17 /** | |
18 * Test {@code Kernel}. | |
19 */ | |
20 public class KernelTests extends RubyTests { | |
21 | |
22 @Test | |
23 public void testPutsEmpty() { | |
24 assertPrints("\n", "puts"); | |
25 } | |
26 | |
27 @Test | |
28 public void testPutsString() { | |
29 assertPrints("1\n", "puts 1"); | |
30 } | |
31 | |
32 @Test | |
33 public void testPrintfNoFormatting() { | |
34 assertPrints("", "printf"); | |
35 assertPrints("foo", "printf \"foo\""); | |
36 assertPrints("foo\n", "printf \"foo\\n\""); | |
37 } | |
38 | |
39 @Test | |
40 public void testPrintfDecimal() { | |
41 assertPrints("foo14bar", "printf \"foo%dbar\", 14"); | |
42 } | |
43 | |
44 @Test | |
45 public void testGets() { | |
46 assertPrintsWithInput("test\n", "puts gets", "test\n"); | |
47 } | |
48 | |
49 @Test | |
50 public void testInteger() { | |
51 assertPrints("14\n", "puts Integer(\"14\")"); | |
52 } | |
53 | |
54 @Test | |
55 public void testEval() { | |
56 assertPrints("16\n", "puts eval(\"14 + 2\")"); | |
57 } | |
58 | |
59 @Test | |
60 public void testBindingLocalVariables() { | |
61 // Use the current binding for eval | |
62 assertPrints("16\n", "x = 14; y = 2; puts eval(\"x + y\", binding)"); | |
63 | |
64 // Use the binding returned from a method for eval | |
65 assertPrints("16\n", "def foo; x = 14; y = 2; binding; end; puts eval(\"x + y\", foo)"); | |
66 } | |
67 | |
68 @Test | |
69 public void testBindingInstanceVariables() { | |
70 // Use the binding returned from a method in an object for eval | |
71 assertPrints("16\n", "class Foo; def foo; @x = 14; @y = 2; binding; end; end; puts eval(\"@x + @y\", Foo.new.foo)"); | |
72 } | |
73 | |
74 @Test | |
75 public void testSetTraceFuncLine() { | |
76 final ConfigurationBuilder configuration = new ConfigurationBuilder(); | |
77 configuration.setTrace(true); | |
78 | |
79 final String code = "def foo\n" + // | |
80 " a = 14\n" + // | |
81 " b = 2\n" + // | |
82 " a + b\n" + // | |
83 "end\n" + // | |
84 "\n" + // | |
85 "set_trace_func proc { |event, file, line, id, binding, classname|\n" + // | |
86 " if event == \"line\"\n" + // | |
87 " puts file + \":\" + line.to_s\n" + // | |
88 " end\n" + // | |
89 "}\n" + // | |
90 "\n" + // | |
91 "foo"; | |
92 final String input = ""; | |
93 final String expected = "(test):13\n(test):2\n(test):3\n(test):4\n"; | |
94 assertPrints(new Configuration(configuration), expected, "(test)", code, input); | |
95 } | |
96 | |
97 @Test | |
98 public void testBlockGiven() { | |
99 assertPrints("false\n", "def foo; puts block_given?; end; foo"); | |
100 assertPrints("true\n", "def foo; puts block_given?; end; foo do; end"); | |
101 assertPrints("true\n", "def foo; puts block_given?; end; foo {}"); | |
102 assertPrints("true\n", "def foo; puts block_given?; end; foo &:+"); | |
103 } | |
104 | |
105 @Test | |
106 public void testLoop() { | |
107 assertPrints("14\n", "loop do; break; end; puts 14"); | |
108 } | |
109 | |
110 } |