wml_action 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/tag_spec.rb ADDED
@@ -0,0 +1,235 @@
1
+ require 'wml_action'
2
+ require 'debugger'
3
+
4
+ module WMLAction
5
+
6
+ describe Tag do
7
+
8
+ describe '#merge' do
9
+
10
+ context 'when no action' do
11
+
12
+ let(:actions) do
13
+ a = Tag.new
14
+ a << Tag::Attribute[:hp,25]
15
+ a << Tag::Macro['{REGENERATE}']
16
+ sub = Tag.new(name: 'attack')
17
+ sub << Tag::Attribute[:type,'blunt']
18
+ a << sub
19
+ sub = Tag.new(name: 'resists')
20
+ sub << Tag::Attribute[:cold,100]
21
+ a << sub
22
+ end
23
+
24
+ let(:target) do
25
+ t = Tag.new
26
+ t << Tag::Attribute[:hp,10]
27
+ t << Tag.new(name: 'attack')
28
+ t << Tag.new(name: 'attack')
29
+ t.merge(actions)
30
+ end
31
+
32
+ it 'adds an attribute' do
33
+ expect(target.attrs).to include :hp
34
+ end
35
+
36
+ it 'merges existing sections' do
37
+ # TODO Should it works through check receiving messages?
38
+ expect(target.subs[0].attrs).to include :type
39
+ expect(target.subs[1].attrs).to include :type
40
+ end
41
+
42
+ it 'ignores new sections' do
43
+ expect(target.subs[2]).to be_nil
44
+ end
45
+
46
+ it 'adds macros' do
47
+ expect(target.macros).to include '{REGENERATE}'
48
+ end
49
+
50
+ it 'change an existing attribute' do
51
+ expect(target.attrs[:hp]).to eq 25
52
+ end
53
+
54
+ end
55
+
56
+ context 'when + action' do
57
+
58
+ let(:actions) do
59
+ a = Tag.new
60
+ sub = Tag.new(name: 'attack')
61
+ sub << Tag::Attribute[:type,'blunt']
62
+ a << Tag::Action[sub, '+']
63
+ sub = Tag.new(name: 'resists')
64
+ a << Tag::Action[sub, '+']
65
+ a << Tag::Action[Tag::Macro['{REGENERATE}'], '+']
66
+ a
67
+ end
68
+
69
+ let(:target) do
70
+ t = Tag.new
71
+ t << Tag.new(name: 'attack')
72
+ t.merge(actions)
73
+ end
74
+
75
+ it 'adds (existing) sections' do
76
+ expect(target.subs[0].name).to eq 'attack'
77
+ expect(target.subs[1].name).to eq 'attack'
78
+ end
79
+
80
+ it 'adds (new) sections' do
81
+ expect(target.subs[2].name).to eq 'resists'
82
+ end
83
+
84
+ it 'adds macros' do
85
+ expect(target.macros).to include '{REGENERATE}'
86
+ end
87
+
88
+ end
89
+
90
+ context 'when - action' do
91
+
92
+ let(:actions) do
93
+ a = Tag.new
94
+ sub = Tag.new(name: 'attack')
95
+ a << Tag::Action[sub,'-']
96
+ a << Tag::Action[Tag::Macro['{REGENERATE}'], '-']
97
+ end
98
+
99
+ let(:target) do
100
+ t = Tag.new
101
+ t << Tag.new(name: 'attack')
102
+ t << Tag::Macro['{REGENERATE}']
103
+ t.merge(actions)
104
+ end
105
+
106
+ it 'removes section' do
107
+ expect(target.subs.size).to eq 0
108
+ end
109
+
110
+ it 'removes macros' do
111
+ expect(target.macros).not_to include '{REGENERATE}'
112
+ end
113
+
114
+ end
115
+
116
+ context 'when filtered section' do
117
+ let(:actions) do
118
+ a = Tag.new
119
+ sub = Tag.new(name: 'attack')
120
+ sub << Tag::Filter[Tag::Attribute[:type,'blunt']]
121
+ sub << Tag::Attribute[:damage, 30]
122
+ a << sub
123
+ end
124
+
125
+ let(:target) do
126
+ t = Tag.new
127
+ sub = Tag.new(name: 'attack')
128
+ sub << Tag::Attribute[:type,'blunt']
129
+ sub << Tag::Attribute[:damage, 25]
130
+ t << sub
131
+ sub = Tag.new(name: 'attack')
132
+ sub << Tag::Attribute[:type,'pierce']
133
+ sub << Tag::Attribute[:damage, 25]
134
+ t << sub
135
+ t.merge(actions)
136
+ end
137
+
138
+ it 'modifies matching section' do
139
+ expect(target.subs[0].attrs[:damage]).to eq 30
140
+ end
141
+
142
+ it 'ignores filtered section' do
143
+ expect(target.subs[1].attrs[:damage]).to eq 25
144
+ end
145
+
146
+
147
+ end
148
+
149
+
150
+ end
151
+
152
+ describe '#add and #<<' do
153
+
154
+ it 'returns self' do
155
+ s = Tag.new << Tag::Attribute[:hp,25]
156
+ expect(s).to be_kind_of(Tag)
157
+ end
158
+
159
+ end
160
+
161
+ describe '#match?' do
162
+ it 'matches filter'
163
+ end
164
+
165
+ describe '#to_s' do
166
+ let(:s) { Tag.new(name: 'unit') }
167
+
168
+ it 'prints tags for section' do
169
+ expect(s.to_s).to eq "[unit]\n[/unit]\n"
170
+ end
171
+
172
+ it 'prints attributes' do
173
+ s << Tag::Attribute[:hp,25]
174
+ s << Tag::Attribute[:race,'human']
175
+ expect(s.to_s).to eq <<-EOS.gsub(/^\s+\|/, '')
176
+ |[unit]
177
+ |\thp=25
178
+ |\trace=human
179
+ |[/unit]
180
+ EOS
181
+ end
182
+
183
+ it 'prints macros' do
184
+ s << Tag::Macro['{REGENERATES}']
185
+ s << Tag::Macro['{INVISIBLE}']
186
+ expect(s.to_s).to eq <<-EOS.gsub(/^\s+\|/, '')
187
+ |[unit]
188
+ |\t{REGENERATES}
189
+ |\t{INVISIBLE}
190
+ |[/unit]
191
+ EOS
192
+ end
193
+
194
+ it 'prints sections' do
195
+ s << Tag.new(name: 'attack')
196
+ s << Tag.new(name: 'resists')
197
+ expect(s.to_s).to eq <<-EOS.gsub(/^\s+\|/, '')
198
+ |[unit]
199
+ |\t[attack]
200
+ |\t[/attack]
201
+ |\t[resists]
202
+ |\t[/resists]
203
+ |[/unit]
204
+ EOS
205
+ end
206
+
207
+ it 'prints filters' do
208
+ s << Tag::Filter[Tag::Attribute[:hp,25]]
209
+ s << Tag::Filter[Tag::Macro['{REGENERATES}']]
210
+ expect(s.to_s).to eq <<-EOS.gsub(/^\s+\|/, '')
211
+ |[unit]
212
+ |\t/ hp=25
213
+ |\t/ {REGENERATES}
214
+ |[/unit]
215
+ EOS
216
+ end
217
+
218
+ it 'prints actions' do
219
+ s << Tag::Action[Tag.new(name: 'attack'),'+']
220
+ s << Tag::Action[Tag::Macro['{REGENERATES}'],'-']
221
+ expect(s.to_s).to eq <<-EOS.gsub(/^\s+\|/, '')
222
+ |[unit]
223
+ |\t+ [attack]
224
+ |\t[/attack]
225
+ |\t- {REGENERATES}
226
+ |[/unit]
227
+ EOS
228
+ end
229
+
230
+ end
231
+
232
+
233
+ end
234
+
235
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wml_action/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wml_action"
8
+ spec.version = WMLAction::VERSION
9
+ spec.authors = ["Pancho"]
10
+ spec.email = ["paul.schko@gmail.com"]
11
+ spec.description = %q{Parses WML files and performs actions on them}
12
+ spec.summary = %q{Parse WML and simple WML extension to make modifications to WML files }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "debugger"
25
+ spec.add_development_dependency "ruby-prof"
26
+ spec.add_development_dependency "rubocop"
27
+ spec.add_development_dependency "rubocop-rspec"
28
+ spec.add_development_dependency "reek"
29
+ spec.add_development_dependency "cucumber"
30
+
31
+
32
+ spec.add_development_dependency "racc"
33
+ spec.add_development_dependency "oedipus_lex"
34
+
35
+ spec.add_dependency "thor"
36
+ end
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wml_action
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Pancho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-11 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-prof
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: reek
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: cucumber
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: racc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: oedipus_lex
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: thor
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Parses WML files and performs actions on them
182
+ email:
183
+ - paul.schko@gmail.com
184
+ executables:
185
+ - wml_action
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - .gitignore
190
+ - .rubocop.yml
191
+ - Gemfile
192
+ - LICENSE.txt
193
+ - README.md
194
+ - Rakefile
195
+ - bin/wml_action
196
+ - lib/wml_action.rb
197
+ - lib/wml_action/cli.rb
198
+ - lib/wml_action/document.rb
199
+ - lib/wml_action/lexer.rex
200
+ - lib/wml_action/lexer.rex.rb
201
+ - lib/wml_action/log.rb
202
+ - lib/wml_action/parser.tab.rb
203
+ - lib/wml_action/parser.y
204
+ - lib/wml_action/tag.rb
205
+ - lib/wml_action/version.rb
206
+ - spec/document_spec.rb
207
+ - spec/fixtures/actions.cfg
208
+ - spec/fixtures/as_from_file.cfg
209
+ - spec/fixtures/attributes.cfg
210
+ - spec/fixtures/filter.cfg
211
+ - spec/fixtures/inners.cfg
212
+ - spec/fixtures/macros.cfg
213
+ - spec/fixtures/s_from_file.cfg
214
+ - spec/fixtures/strings.cfg
215
+ - spec/fixtures/tag.cfg
216
+ - spec/tag_spec.rb
217
+ - wml_action.gemspec
218
+ homepage: ''
219
+ licenses:
220
+ - MIT
221
+ metadata: {}
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ! '>='
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ! '>='
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubyforge_project:
238
+ rubygems_version: 2.0.7
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Parse WML and simple WML extension to make modifications to WML files
242
+ test_files:
243
+ - spec/document_spec.rb
244
+ - spec/fixtures/actions.cfg
245
+ - spec/fixtures/as_from_file.cfg
246
+ - spec/fixtures/attributes.cfg
247
+ - spec/fixtures/filter.cfg
248
+ - spec/fixtures/inners.cfg
249
+ - spec/fixtures/macros.cfg
250
+ - spec/fixtures/s_from_file.cfg
251
+ - spec/fixtures/strings.cfg
252
+ - spec/fixtures/tag.cfg
253
+ - spec/tag_spec.rb