raheui 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,145 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Raheui::Stack do
5
+ it_behaves_like 'a store'
6
+
7
+ describe '#push' do
8
+ context 'with no elements' do
9
+ let(:element) { rand(10) }
10
+
11
+ it 'returns an array with the pushed element' do
12
+ expect(subject.push(element)).to match_array([element])
13
+ end
14
+ end
15
+
16
+ context 'with one element' do
17
+ let(:element) { rand(10) }
18
+
19
+ before(:example) { subject.push(42) }
20
+
21
+ it 'returns an array with the pushed element at last' do
22
+ expect(subject.push(element)).to match_array([42, element])
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '#pop' do
28
+ context 'with no elements' do
29
+ it 'returns last pushed element' do
30
+ subject.push(42)
31
+ expect(subject.pop).to be(42)
32
+ end
33
+ end
34
+
35
+ context 'with one element' do
36
+ let(:element) { rand(10) }
37
+
38
+ before(:example) { subject.push(element) }
39
+
40
+ it 'returns the element' do
41
+ expect(subject.pop).to be(element)
42
+ end
43
+
44
+ it 'returns last pushed element' do
45
+ subject.push(42)
46
+ expect(subject.pop).to be(42)
47
+ end
48
+
49
+ it 'returns nil after a pop call' do
50
+ subject.pop
51
+ expect(subject.pop).to be(nil)
52
+ end
53
+ end
54
+
55
+ context 'with more than one element' do
56
+ let(:one) { rand(10) }
57
+ let(:two) { rand(10) }
58
+
59
+ before(:example) do
60
+ subject.push(one)
61
+ subject.push(two)
62
+ end
63
+
64
+ it 'returns the elements in reversed order' do
65
+ expect(subject.pop).to be(two)
66
+ expect(subject.pop).to be(one)
67
+ end
68
+
69
+ it 'returns last pushed element' do
70
+ subject.push(42)
71
+ expect(subject.pop).to be(42)
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#push_dup' do
77
+ context 'with one element' do
78
+ let(:element) { rand(10) }
79
+
80
+ before(:example) { subject.push(element) }
81
+
82
+ it 'pushes the last element' do
83
+ subject.push_dup
84
+ expect(subject.pop).to be(element)
85
+ expect(subject.pop).to be(element)
86
+ end
87
+
88
+ it 'pushes last pushed element' do
89
+ subject.push(42)
90
+ subject.push_dup
91
+ expect(subject.pop).to be(42)
92
+ expect(subject.pop).to be(42)
93
+ expect(subject.pop).to be(element)
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#swap' do
99
+ context 'with one element' do
100
+ let(:element) { rand(10) }
101
+
102
+ before(:example) { subject.push(element) }
103
+
104
+ it "doesn't modify store" do
105
+ subject.swap
106
+ expect(subject.pop).to be(element)
107
+ end
108
+ end
109
+
110
+ context 'with two elements' do
111
+ let(:one) { rand(10) }
112
+ let(:two) { rand(10...20) }
113
+
114
+ before(:example) do
115
+ subject.push(one)
116
+ subject.push(two)
117
+ end
118
+
119
+ it 'swaps the last two elements' do
120
+ subject.swap
121
+ expect(subject.pop).to be(one)
122
+ expect(subject.pop).to be(two)
123
+ end
124
+ end
125
+
126
+ context 'with more than two elements' do
127
+ let(:one) { rand(10) }
128
+ let(:two) { rand(10...20) }
129
+ let(:three) { rand(20...30) }
130
+
131
+ before(:example) do
132
+ subject.push(one)
133
+ subject.push(two)
134
+ subject.push(three)
135
+ end
136
+
137
+ it 'swaps the last two elements' do
138
+ subject.swap
139
+ expect(subject.pop).to be(two)
140
+ expect(subject.pop).to be(three)
141
+ expect(subject.pop).to be(one)
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Raheui::Store do
5
+ let(:base_methods) { Raheui::Store.const_get(:BASE_METHODS) }
6
+ let(:error_msg) { 'base methods are not implemented: %s' }
7
+
8
+ describe '#initialize' do
9
+ it 'raises NotImplementedError' do
10
+ expect { subject }.to raise_error(
11
+ NotImplementedError,
12
+ format(error_msg, base_methods.join(', ')))
13
+ end
14
+
15
+ context 'with implemented push' do
16
+ let(:methods) { base_methods - [:push] }
17
+
18
+ before(:context) { Raheui::Store.class_eval { def push; end } }
19
+ after(:context) { Raheui::Store.class_eval { remove_method :push } }
20
+
21
+ it 'raises NotImplementedError' do
22
+ expect(base_methods - methods).to contain_exactly(:push)
23
+ expect { subject }.to raise_error(
24
+ NotImplementedError,
25
+ format(error_msg, methods.join(', ')))
26
+ end
27
+ end
28
+
29
+ context 'with implemented pop' do
30
+ let(:methods) { base_methods - [:pop] }
31
+
32
+ before(:context) { Raheui::Store.class_eval { def pop; end } }
33
+ after(:context) { Raheui::Store.class_eval { remove_method :pop } }
34
+
35
+ it 'raises NotImplementedError' do
36
+ expect(base_methods - methods).to contain_exactly(:pop)
37
+ expect { subject }.to raise_error(
38
+ NotImplementedError,
39
+ format(error_msg, methods.join(', ')))
40
+ end
41
+ end
42
+
43
+ context 'with implemented swap' do
44
+ let(:methods) { base_methods - [:swap] }
45
+
46
+ before(:context) { Raheui::Store.class_eval { def swap; end } }
47
+ after(:context) { Raheui::Store.class_eval { remove_method :swap } }
48
+
49
+ it 'raises NotImplementedError' do
50
+ expect(base_methods - methods).to contain_exactly(:swap)
51
+ expect { subject }.to raise_error(
52
+ NotImplementedError,
53
+ format(error_msg, methods.join(', ')))
54
+ end
55
+ end
56
+
57
+ context 'with implemented all base methods' do
58
+ before(:context) do
59
+ Raheui::Store.class_eval do
60
+ def push; end
61
+
62
+ def pop; end
63
+
64
+ def swap; end
65
+ end
66
+ end
67
+
68
+ after(:context) do
69
+ Raheui::Store.class_eval do
70
+ remove_method :push
71
+ remove_method :pop
72
+ remove_method :swap
73
+ end
74
+ end
75
+
76
+ it 'does not raise NotImplementedError' do
77
+ expect { subject }.not_to raise_error
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#size' do
83
+ it 'should respond to #size' do
84
+ expect(Raheui::Store.instance_methods(false)).to include(:size)
85
+ end
86
+ end
87
+
88
+ describe '#push_dup' do
89
+ it 'should respond to #push_dup' do
90
+ expect(Raheui::Store.instance_methods(false)).to include(:push_dup)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Raheui::Version do
5
+ describe '::STRING' do
6
+ it { expect(defined? subject::STRING).to eql('constant') }
7
+ end
8
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ if ENV['TRAVIS'] || ENV['COVERAGE']
3
+ require 'simplecov'
4
+
5
+ if ENV['TRAVIS']
6
+ require 'coveralls'
7
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
8
+ end
9
+
10
+ SimpleCov.start do
11
+ add_filter '/spec/'
12
+ end
13
+ end
14
+
15
+ require 'raheui'
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ # These two settings work together to allow you to limit a spec run
20
+ # to individual examples or groups you care about by tagging them with
21
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
22
+ # get run.
23
+ config.filter_run :focus
24
+ config.run_all_when_everything_filtered = true
25
+
26
+ # Many RSpec users commonly either run the entire suite or an individual
27
+ # file, and it's useful to allow more verbose output when running an
28
+ # individual spec file.
29
+ if config.files_to_run.one?
30
+ # Use the documentation formatter for detailed output,
31
+ # unless a formatter has already been configured
32
+ # (e.g. via a command-line flag).
33
+ config.default_formatter = 'doc'
34
+ end
35
+
36
+ # Print the 10 slowest examples and example groups at the
37
+ # end of the spec run, to help surface which specs are running
38
+ # particularly slow.
39
+ # config.profile_examples = 10
40
+
41
+ # Run specs in random order to surface order dependencies. If you find an
42
+ # order dependency and want to debug it, you can fix the order by providing
43
+ # the seed, which is printed after each run.
44
+ # --seed 1234
45
+ config.order = :random
46
+
47
+ # Seed global randomization in this process using the `--seed` CLI option.
48
+ # Setting this allows you to use `--seed` to deterministically reproduce
49
+ # test failures related to randomization by passing the same `--seed` value
50
+ # as the one that triggered the failure.
51
+ Kernel.srand config.seed
52
+
53
+ # rspec-expectations config goes here. You can use an alternate
54
+ # assertion/expectation library such as wrong or the stdlib/minitest
55
+ # assertions if you prefer.
56
+ config.expect_with :rspec do |expectations|
57
+ # Enable only the newer, non-monkey-patching expect syntax.
58
+ # For more details, see:
59
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
+ expectations.syntax = :expect
61
+ end
62
+
63
+ # rspec-mocks config goes here. You can use an alternate test double
64
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
65
+ config.mock_with :rspec do |mocks|
66
+ # Enable only the newer, non-monkey-patching expect syntax.
67
+ # For more details, see:
68
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ mocks.syntax = :expect
70
+
71
+ # Prevents you from mocking or stubbing a method that does not exist on
72
+ # a real object. This is generally recommended.
73
+ mocks.verify_partial_doubles = true
74
+ end
75
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ # Matches exit code of block with SystemExit.
4
+ module ExitCodeMatchers
5
+ RSpec::Matchers.define :exit_with_code do |code|
6
+ supports_block_expectations
7
+ actual = nil
8
+ match do |block|
9
+ begin
10
+ block.call
11
+ rescue SystemExit => e
12
+ actual = e.status
13
+ end
14
+ actual && actual == code
15
+ end
16
+ failure_message do
17
+ "expected block to call exit(#{code}) but exit" +
18
+ (actual.nil? ? ' not called' : "(#{actual}) was called")
19
+ end
20
+ failure_message_when_negated do
21
+ "expected block not to call exit(#{code})"
22
+ end
23
+ description do
24
+ "expect block to call exit(#{code})"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'fileutils'
3
+
4
+ # Util methods for processing file.
5
+ module FileHelper
6
+ # Create file with at given path with given content. Ensure parent directories
7
+ # are exists.
8
+ #
9
+ # path - An String path of file.
10
+ # content - An String or an Array of Strings content of file.
11
+ #
12
+ # Returns nothing.
13
+ def create_file(path, content)
14
+ file_path = File.expand_path(path)
15
+ dir_path = File.dirname(file_path)
16
+ FileUtils.makedirs(dir_path) unless File.exist?(dir_path)
17
+ write_file(path, content)
18
+ end
19
+
20
+ # Write file content at given path.
21
+ #
22
+ # path - An String path of file.
23
+ # content - An String or an Array of Strings content of file.
24
+ #
25
+ # Returns nothing.
26
+ def write_file(path, content)
27
+ File.open(path, 'w') do |file|
28
+ case content
29
+ when ''
30
+ # Create empty file.
31
+ when String
32
+ file.puts content
33
+ when Array
34
+ file.puts content.join("\n")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require 'tmpdir'
3
+
4
+ shared_context 'isolated environment' do
5
+ around do |example|
6
+ Dir.mktmpdir do |tmpdir|
7
+ tmpdir = File.realpath(tmpdir)
8
+ Dir.chdir(tmpdir) do
9
+ example.run
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ shared_examples 'a store' do
5
+ describe '#push' do
6
+ it { is_expected.to respond_to(:push) }
7
+ end
8
+
9
+ describe '#pop' do
10
+ it { is_expected.to respond_to(:pop) }
11
+
12
+ context 'with no elements' do
13
+ it { expect(subject.pop).to be_nil }
14
+ end
15
+ end
16
+
17
+ describe '#push_dup' do
18
+ context 'with no elements' do
19
+ it "doesn't push" do
20
+ subject.push_dup
21
+ expect(subject.size).to be_zero
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#swap' do
27
+ it { is_expected.to respond_to(:swap) }
28
+
29
+ context 'with no elements' do
30
+ it "doesn't modify store" do
31
+ subject.swap
32
+ expect(subject.size).to be_zero
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#size' do
38
+ context 'with no elements' do
39
+ it { expect(subject.size).to be_zero }
40
+
41
+ it 'returns 0 after pop' do
42
+ subject.pop
43
+ expect(subject.size).to be_zero
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: raheui
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ChaYoung You
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.25.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.25.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: Aheui interpreter in Ruby.
84
+ email:
85
+ - yousbe@gmail.com
86
+ executables:
87
+ - raheui
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .rubocop.yml
94
+ - .rubocop_todo.yml
95
+ - .travis.yml
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/raheui
102
+ - lib/raheui.rb
103
+ - lib/raheui/cli.rb
104
+ - lib/raheui/code.rb
105
+ - lib/raheui/io.rb
106
+ - lib/raheui/option.rb
107
+ - lib/raheui/port.rb
108
+ - lib/raheui/queue.rb
109
+ - lib/raheui/runner.rb
110
+ - lib/raheui/stack.rb
111
+ - lib/raheui/store.rb
112
+ - lib/raheui/version.rb
113
+ - raheui.gemspec
114
+ - spec/raheui/cli_spec.rb
115
+ - spec/raheui/code_spec.rb
116
+ - spec/raheui/io_spec.rb
117
+ - spec/raheui/option_spec.rb
118
+ - spec/raheui/port_spec.rb
119
+ - spec/raheui/queue_spec.rb
120
+ - spec/raheui/runner_spec.rb
121
+ - spec/raheui/stack_spec.rb
122
+ - spec/raheui/store_spec.rb
123
+ - spec/raheui/version_spec.rb
124
+ - spec/spec_helper.rb
125
+ - spec/support/exit_code_matchers.rb
126
+ - spec/support/file_helper.rb
127
+ - spec/support/isolated_environment.rb
128
+ - spec/support/shared_store.rb
129
+ homepage: ''
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Aheui interpreter in Ruby.
153
+ test_files:
154
+ - spec/raheui/cli_spec.rb
155
+ - spec/raheui/code_spec.rb
156
+ - spec/raheui/io_spec.rb
157
+ - spec/raheui/option_spec.rb
158
+ - spec/raheui/port_spec.rb
159
+ - spec/raheui/queue_spec.rb
160
+ - spec/raheui/runner_spec.rb
161
+ - spec/raheui/stack_spec.rb
162
+ - spec/raheui/store_spec.rb
163
+ - spec/raheui/version_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/support/exit_code_matchers.rb
166
+ - spec/support/file_helper.rb
167
+ - spec/support/isolated_environment.rb
168
+ - spec/support/shared_store.rb