church 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ require 'church/lambda'
2
2
  require 'church/array'
3
3
  require 'church/hash'
4
4
  require 'church/io'
5
+ require 'church/kernel'
5
6
  require 'church/math'
6
7
  require 'church/range'
7
8
  require 'church/utils'
@@ -0,0 +1,23 @@
1
+ # TODO: Convince somebody on #ruby-core that this should be defined by default.
2
+ class String
3
+ def >> obj
4
+ obj.send self
5
+ end
6
+ end
7
+
8
+ module Church::Kernel
9
+ # Our reference to the Kernel constant
10
+ KERNEL = ('ancestors' >> ('class' >> []))[-2]
11
+
12
+ # Reads and returns a single line from standard input.
13
+ GETS = -> { 'gets' >> KERNEL }
14
+
15
+ # Reads lines from standard input and prints their results after being passed to fn, terminating on EOF.
16
+ INTERACT = -> &fn {
17
+ line = GETS[]
18
+ line ? 0 : ('exit' >> KERNEL)
19
+ line = 'chomp' >> line
20
+ PUTS[fn[line]]
21
+ INTERACT[&fn]
22
+ }
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Church
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -36,3 +36,15 @@ describe 'TO_I' do
36
36
  expect(TO_I['12345']).to be 12345
37
37
  end
38
38
  end
39
+
40
+ describe 'PRINT' do
41
+ it "should write its argument to standard output" do
42
+ expect(capture_stdout { PRINT['Alonzo'] }).to eq 'Alonzo'
43
+ end
44
+ end
45
+
46
+ describe 'PUTS' do
47
+ it "should write its argument to standard output with a newline" do
48
+ expect(capture_stdout { PUTS['Church'] }).to eq "Church\n"
49
+ end
50
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ include Church::Kernel
5
+
6
+ describe 'KERNEL' do
7
+ it "should be the same object as Kernel" do
8
+ expect(KERNEL).to be Kernel
9
+ end
10
+ end
11
+
12
+ describe 'GETS' do
13
+ it "should read a line from standard input" do
14
+ Kernel.should_receive :gets
15
+ GETS[]
16
+ end
17
+ end
18
+
19
+ describe 'INTERACT' do
20
+ it "should interact with user input" do
21
+ STDOUT.should_receive(:write).with('Ruby')
22
+ PRINT['Ruby']
23
+ end
24
+ end
@@ -1,5 +1,6 @@
1
1
  require 'simplecov'
2
2
  require 'simplecov-console'
3
+ require 'stringio'
3
4
 
4
5
  SimpleCov.add_filter '/spec'
5
6
 
@@ -10,4 +11,24 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
11
 
11
12
  SimpleCov.start
12
13
 
14
+ def capture_stdin(*args)
15
+ begin
16
+ $stdin = StringIO.new
17
+ $stdin.puts(args.shift) until args.empty?
18
+ $stdin.rewind
19
+ yield
20
+ ensure
21
+ $stdin = STDIN
22
+ end
23
+ end
24
+
25
+ def capture_stdout
26
+ old = $stdout
27
+ $stdout = fake = StringIO.new
28
+ yield
29
+ fake.string
30
+ ensure
31
+ $stdout = old
32
+ end
33
+
13
34
  require File.expand_path('../../lib/church', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: church
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -92,6 +92,7 @@ files:
92
92
  - lib/church/array.rb
93
93
  - lib/church/hash.rb
94
94
  - lib/church/io.rb
95
+ - lib/church/kernel.rb
95
96
  - lib/church/lambda.rb
96
97
  - lib/church/math.rb
97
98
  - lib/church/range.rb
@@ -100,6 +101,7 @@ files:
100
101
  - spec/array_spec.rb
101
102
  - spec/hash_spec.rb
102
103
  - spec/io_spec.rb
104
+ - spec/kernel_spec.rb
103
105
  - spec/lambda_spec.rb
104
106
  - spec/math_spec.rb
105
107
  - spec/range_spec.rb
@@ -135,6 +137,7 @@ test_files:
135
137
  - spec/array_spec.rb
136
138
  - spec/hash_spec.rb
137
139
  - spec/io_spec.rb
140
+ - spec/kernel_spec.rb
138
141
  - spec/lambda_spec.rb
139
142
  - spec/math_spec.rb
140
143
  - spec/range_spec.rb