Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 68 lines (53 sloc) 1.245 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
require 'proc_source'

@subject = ProcString.new "{ false }"

def lambda?
  @l.call
  return true
end


## string should be set
@subject
#=> "{ false }"

## #file can be set
@subject.file = "test.rb"
@subject.file
#=> "test.rb"
  
## #lines can be set
@subject.lines = 1..10
#=> (1..10)


## should create a proc
ps = ProcString.new "do\n false\n end"
ps.to_proc.class
#=> Proc
  
## should connect #file and #lines to the proc
ps = ProcString.new "do\n false\n end"
ps.file = "to_proc_test"
ps.lines = (100..102)
ps.to_proc.inspect.index('to_proc_test:100').nil?
#=> false
  
## should fail if #file is set and #lines is a non Range
ps = ProcString.new "do\n false\n end"
ps.file = "to_proc_test"
ps.lines = 100
begin
  ps.to_proc
rescue RuntimeError
  :success
end
#=> :success
  
## should create a lambda
## Test is from: http://en.wikipedia.org/wiki/Closure_(computer_science)#Closure_leaving
ps = ProcString.new "do\n return false\n end"
@l = ps.to_lambda
[@l.call, lambda?]
#=> [false, true]

## should dump and load
@test = "do\n false\n end"
@file = "ps_test"
@lines = (23..25)
p1 = ProcString.new @test
p1.file = @file
p1.lines = @lines
str = Marshal.dump(p1)
p2 = Marshal.load str
[p2, p2.file, p2.lines]
#=> [@test, @file, @lines]


Something went wrong with that request. Please try again.