windstorm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Windstorm::Parser do
5
+
6
+ describe '#table/#table=' do
7
+ context 'raise error if not table seted or empty' do
8
+ it { lambda{ Parser.new.table}.should raise_error }
9
+ it { lambda{ Parser.create({}) }.should raise_error }
10
+ end
11
+
12
+ context 'set commands table' do
13
+ before do
14
+ @table = {:pinc => ['hoge', 'piyo'], :inc => 'aborn'}
15
+ @expect = {:pinc => ['hoge', 'piyo'], :inc => ['aborn']}
16
+ end
17
+ subject { Parser.create(@table) }
18
+ its(:table) { should == @expect }
19
+ end
20
+
21
+ context 'not commands table, raise error' do
22
+ before do
23
+ @table = {:a => 'hoge', :b => 'piyo'}
24
+ @ps = Parser.new
25
+ end
26
+ it { lambda{ @ps.table = @table }.should raise_error }
27
+ end
28
+ end
29
+
30
+ describe '#dict' do
31
+ context 'raise error if not table seted' do
32
+ it { lambda{ Parser.new.dict }.should raise_error }
33
+ end
34
+
35
+ context 'get reverse table' do
36
+ before do
37
+ @table = {:pinc => ['hoge', 'piyo'], :inc => 'aborn'}
38
+ @expect = {'hoge' => :pinc, 'piyo' => :pinc, 'aborn' => :inc}
39
+ end
40
+ subject{ Parser.create(@table) }
41
+ its(:dict) { should == @expect }
42
+ end
43
+ end
44
+
45
+ describe '#filter' do
46
+ context 'source filter with dict' do
47
+ before do
48
+ @table = {:pinc => ['+', '/'], :inc => '(´・ω・`)'}
49
+ @source = '+dsa+(´・ω・`)-rqwyuiyiu-(`・ω・´)*;;;:::das( ´・ω・` )kl;das*(´-ω-)/>>>../'
50
+ @expect = ['+', '+', '(´・ω・`)', '/', '/']
51
+ @parser = Parser.create(@table)
52
+ end
53
+ it { @parser.filter(@source).should == @expect }
54
+ end
55
+
56
+ context 'reject comment lines' do
57
+ before do
58
+ @table = {:inc => ['b', 'c']}
59
+ @source = <<-EOS
60
+ abc
61
+ # cba # comment
62
+ // cba // comment
63
+ # cba # spece head
64
+ // cba // spece head
65
+ EOS
66
+ @expect = ['b', 'c', 'c', 'b', 'c', 'c', 'b', 'c']
67
+ @parser = Parser.create(@table)
68
+ end
69
+ it { @parser.filter(@source).should == @expect }
70
+ end
71
+
72
+ context 'empty array for no hit' do
73
+ before do
74
+ @table = {:inc => ['b', 'c']}
75
+ @source = '(´・ω・`)'
76
+ @parser = Parser.create(@table)
77
+ end
78
+ it { @parser.filter(@source).should be_empty }
79
+ end
80
+
81
+ context 'given nil' do
82
+ before do
83
+ @table = {:inc => ['b', 'c']}
84
+ @parser = Parser.create(@table)
85
+ end
86
+ it { @parser.filter(nil).should be_empty }
87
+ end
88
+ end
89
+
90
+ describe '#convert' do
91
+ context 'convert word to command' do
92
+ before do
93
+ @table = {:pinc => '12', :pdec => '3', :inc => '5'}
94
+ @filtered = ['3', '12', '21', '5']
95
+ @expect = [:pdec, :pinc, :inc]
96
+ @parser = Parser.create(@table)
97
+ end
98
+ it { @parser.convert(@filtered).should == @expect }
99
+ end
100
+
101
+ context 'empty list or nil' do
102
+ before do
103
+ @table = {:pinc => '12', :pdec => '3', :inc => '5'}
104
+ @parser = Parser.create(@table)
105
+ end
106
+ it { @parser.convert(nil).should be_empty }
107
+ it { @parser.convert([]).should be_empty }
108
+ end
109
+ end
110
+
111
+ describe '#build' do
112
+ context 'build commands from source' do
113
+ before do
114
+ @table = {:pinc => ['+', '/'], :inc => '(´・ω・`)'}
115
+ @source = '+dsa+(´・ω・`)-rqwyuiyiu-(`・ω・´)*;;;:::das( ´・ω・` )kl;das*(´-ω-)/>>>../'
116
+ @expect = [:pinc, :pinc, :inc, :pinc, :pinc]
117
+ @parser = Parser.create(@table)
118
+ end
119
+ it { @parser.build(@source).should == @expect }
120
+ end
121
+
122
+ context 'no commands included' do
123
+ before do
124
+ @table = {:pinc => '12', :pdec => '3', :inc => '5'}
125
+ @source = 'ta-noshi-na-kama-ga-'
126
+ @parser = Parser.create(@table)
127
+ end
128
+ it { @parser.build(@source).should be_empty }
129
+ it { @parser.build(nil).should be_empty }
130
+ end
131
+ end
132
+
133
+ end
data/windstorm.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "windstorm/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "windstorm"
7
+ s.version = Windstorm::VERSION
8
+ s.authors = ["parrot-studio"]
9
+ s.email = ["parrot.studio.dev@gmail.com"]
10
+ s.homepage = "https://github.com/parrot-studio/windstorm"
11
+ s.summary = %q{Program language paser/executor like BrainF**k}
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "windstorm"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: windstorm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - parrot-studio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70261919865920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70261919865920
25
+ description: Program language paser/executor like BrainF**k
26
+ email:
27
+ - parrot.studio.dev@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/windstorm.rb
38
+ - lib/windstorm/executor.rb
39
+ - lib/windstorm/machine.rb
40
+ - lib/windstorm/parser.rb
41
+ - lib/windstorm/version.rb
42
+ - spec/fixtures/bf.yml
43
+ - spec/fixtures/invalid.yml
44
+ - spec/fixtures/source.txt
45
+ - spec/spec_helper.rb
46
+ - spec/windstorm/executor_spec.rb
47
+ - spec/windstorm/machine_execute_spec.rb
48
+ - spec/windstorm/machine_spec.rb
49
+ - spec/windstorm/parser_spec.rb
50
+ - windstorm.gemspec
51
+ homepage: https://github.com/parrot-studio/windstorm
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project: windstorm
71
+ rubygems_version: 1.8.11
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Program language paser/executor like BrainF**k
75
+ test_files:
76
+ - spec/fixtures/bf.yml
77
+ - spec/fixtures/invalid.yml
78
+ - spec/fixtures/source.txt
79
+ - spec/spec_helper.rb
80
+ - spec/windstorm/executor_spec.rb
81
+ - spec/windstorm/machine_execute_spec.rb
82
+ - spec/windstorm/machine_spec.rb
83
+ - spec/windstorm/parser_spec.rb