summaryrefslogtreecommitdiff
path: root/test/test_code_helpers.rb
diff options
context:
space:
mode:
authorConrad Irwin <conrad.irwin@gmail.com>2012-07-02 00:31:32 -0700
committerConrad Irwin <conrad.irwin@gmail.com>2012-07-02 00:33:45 -0700
commit0dbc9344dfa5e94d52ebb3d79d3d43b35434a74e (patch)
treeb8e12136c55e71dc44ac5a3f5a1fc422934fd8d9 /test/test_code_helpers.rb
parentd2b25cdbbed2f8539fe5f11e5dcf180fc1f3fce8 (diff)
downloadmethod_source-0dbc9344dfa5e94d52ebb3d79d3d43b35434a74e.tar.gz
Allow embedded documents in incomplete expressions [Fixes pry#622]
Also import complete_expression? tests from Pry.
Diffstat (limited to 'test/test_code_helpers.rb')
-rw-r--r--test/test_code_helpers.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test_code_helpers.rb b/test/test_code_helpers.rb
new file mode 100644
index 0000000..ba83a63
--- /dev/null
+++ b/test/test_code_helpers.rb
@@ -0,0 +1,41 @@
+describe MethodSource::CodeHelpers do
+ before do
+ @tester = Object.new.extend(MethodSource::CodeHelpers)
+ end
+
+ [
+ ["p = '", "'"],
+ ["def", "a", "(); end"],
+ ["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
+ ["[", ":lets,", "'list',", "[/nested/", "], things ]"],
+ ["abc =~ /hello", "/"],
+ ["issue = %W/", "343/"],
+ ["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
+ ["=begin", "no-one uses this syntax anymore...", "=end"],
+ ["puts 1, 2,", "3"],
+ ["puts 'hello'\\", "'world'"]
+ ].each do |lines|
+ it "should not raise an error on broken lines: #{lines.join("\\n")}" do
+ 1.upto(lines.size - 1) do |i|
+ @tester.complete_expression?(lines[0...i].join("\n") + "\n").should == false
+ end
+ @tester.complete_expression?(lines.join("\n")).should == true
+ end
+ end
+
+ [
+ ["end"],
+ ["puts )("],
+ ["1 1"],
+ ["puts :"]
+ ] + (RbConfig::CONFIG['ruby_install_name'] == 'rbx' ? [] : [
+ ["def", "method(1"], # in this case the syntax error is "expecting ')'".
+ ["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
+ ]).compact.each do |foo|
+ it "should raise an error on invalid syntax like #{foo.inspect}" do
+ lambda{
+ @tester.complete_expression?(foo.join("\n"))
+ }.should.raise(SyntaxError)
+ end
+ end
+end