rhcl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,326 @@
1
+ describe Rhcl do
2
+ it 'basic' do
3
+ parsed = Rhcl.parse(<<-EOS)
4
+ foo = "bar"
5
+ EOS
6
+
7
+ expect(parsed).to eq(
8
+ {"foo" => "bar"}
9
+ )
10
+ end
11
+
12
+ it 'decode_policy' do
13
+ parsed = Rhcl.parse(<<-EOS)
14
+ key "" {
15
+ policy = "read"
16
+ }
17
+
18
+ key "foo/" {
19
+ policy = "write"
20
+ }
21
+
22
+ key "foo/bar/" {
23
+ policy = "read"
24
+ }
25
+
26
+ key "foo/bar/baz" {
27
+ policy = "deny"
28
+ }
29
+ EOS
30
+
31
+ expect(parsed).to eq(
32
+ {"key"=>
33
+ {""=>{"policy"=>"read"},
34
+ "foo/"=>{"policy"=>"write"},
35
+ "foo/bar/"=>{"policy"=>"read"},
36
+ "foo/bar/baz"=>{"policy"=>"deny"}}}
37
+ )
38
+ end
39
+
40
+ it 'decode_tf_variable' do
41
+ parsed = Rhcl.parse(<<-EOS)
42
+ variable "foo" {
43
+ default = "bar"
44
+ description = "bar"
45
+ }
46
+
47
+ variable "amis" {
48
+ default = {
49
+ east = "foo"
50
+ }
51
+ }
52
+ EOS
53
+
54
+ expect(parsed).to eq(
55
+ {"variable"=>
56
+ {"foo"=>{"default"=>"bar", "description"=>"bar"},
57
+ "amis"=>{"default"=>{"east"=>"foo"}}}}
58
+ )
59
+ end
60
+
61
+ it 'empty' do
62
+ parsed = Rhcl.parse(<<-EOS)
63
+ resource "aws_instance" "db" {}
64
+ EOS
65
+
66
+ expect(parsed).to eq(
67
+ {"resource"=>{"aws_instance"=>{"db"=>{}}}}
68
+ )
69
+ end
70
+
71
+ it 'flat' do
72
+ parsed = Rhcl.parse(<<-EOS)
73
+ foo = "bar"
74
+ Key = 7
75
+ EOS
76
+
77
+ expect(parsed).to eq(
78
+ {"foo"=>"bar", "Key"=>7}
79
+ )
80
+ end
81
+
82
+ it 'structure' do
83
+ parsed = Rhcl.parse(<<-EOS)
84
+ // This is a test structure for the lexer
85
+ foo "baz" {
86
+ key = 7
87
+ foo = "bar"
88
+ }
89
+ EOS
90
+
91
+ expect(parsed).to eq(
92
+ {"foo"=>{"baz"=>{"key"=>7, "foo"=>"bar"}}}
93
+ )
94
+ end
95
+
96
+ it 'structure2' do
97
+ parsed = Rhcl.parse(<<-EOS)
98
+ // This is a test structure for the lexer
99
+ foo "baz" {
100
+ key = 7
101
+ foo = "bar"
102
+ }
103
+
104
+ foo {
105
+ key = 7
106
+ }
107
+ EOS
108
+
109
+ expect(parsed).to eq(
110
+ {"foo"=>{"baz"=>{"key"=>7, "foo"=>"bar"}, "key"=>7}}
111
+ )
112
+ end
113
+
114
+ it 'structure_flat' do
115
+ parsed = Rhcl.parse(<<-EOS)
116
+ # This is a test structure for the lexer
117
+ foo "baz" {
118
+ key = 7
119
+ foo = "bar"
120
+ }
121
+ EOS
122
+
123
+ expect(parsed).to eq(
124
+ {"foo"=>{"baz"=>{"key"=>7, "foo"=>"bar"}}}
125
+ )
126
+ end
127
+
128
+ it 'structure_flatmap' do
129
+ parsed = Rhcl.parse(<<-EOS)
130
+ /*
131
+ comment
132
+ */
133
+ foo {
134
+ key = 7
135
+ }
136
+
137
+ foo {
138
+ foo = "bar"
139
+ }
140
+ EOS
141
+
142
+ expect(parsed).to eq(
143
+ {"foo"=>{"key"=>7, "foo"=>"bar"}}
144
+ )
145
+ end
146
+
147
+ it 'structure_multi' do
148
+ parsed = Rhcl.parse(<<-EOS)
149
+ foo "baz" {
150
+ key = 7
151
+ }
152
+
153
+ foo "bar" {
154
+ key = 12
155
+ }
156
+ EOS
157
+
158
+ expect(parsed).to eq(
159
+ {"foo"=>{"baz"=>{"key"=>7}, "bar"=>{"key"=>12}}}
160
+ )
161
+ end
162
+
163
+ it 'array' do
164
+ parsed = Rhcl.parse(<<-EOS)
165
+ foo = [1, 2, "baz"]
166
+ bar = "baz"
167
+ EOS
168
+
169
+ expect(parsed).to eq(
170
+ {"foo"=>[1, 2, "baz"], "bar"=>"baz"}
171
+ )
172
+ end
173
+
174
+ it 'object' do
175
+ parsed = Rhcl.parse(<<-EOS)
176
+ foo = {
177
+ bar = [1, 2, "baz"]
178
+ }
179
+ EOS
180
+
181
+ expect(parsed).to eq(
182
+ {"foo"=>{"bar"=>[1, 2, "baz"]}}
183
+ )
184
+ end
185
+
186
+ it 'types' do
187
+ parsed = Rhcl.parse(<<-EOS)
188
+ foo = "bar"
189
+ bar = 7
190
+ baz = [1,2,3]
191
+ foo2 = -12
192
+ bar2 = 3.14159
193
+ bar3 = -3.14159
194
+ hoge = true
195
+ fuga = false
196
+ EOS
197
+
198
+ expect(parsed).to eq(
199
+ {"foo"=>"bar",
200
+ "bar"=>7,
201
+ "baz"=>[1, 2, 3],
202
+ "foo2"=>-12,
203
+ "bar2"=>3.14159,
204
+ "bar3"=>-3.14159,
205
+ "hoge"=>true,
206
+ "fuga"=>false}
207
+ )
208
+ end
209
+
210
+ it 'assign_colon' do
211
+ expect {
212
+ Rhcl.parse(<<-EOS)
213
+ resource = [{
214
+ "foo": {
215
+ "bar": {},
216
+ "baz": [1, 2, "foo"],
217
+ }
218
+ }]
219
+ EOS
220
+ }.to raise_error
221
+ end
222
+
223
+ it 'assign_deep' do
224
+ expect {
225
+ Rhcl.parse(<<-EOS)
226
+ resource = [{
227
+ foo = [{
228
+ bar = {}
229
+ }]
230
+ }]
231
+ EOS
232
+ }.to raise_error
233
+ end
234
+
235
+ it 'comment' do
236
+ parsed = Rhcl.parse(<<-EOS)
237
+ // Foo
238
+
239
+ /* Bar */
240
+
241
+ /*
242
+ /*
243
+ Baz
244
+ */
245
+ */
246
+
247
+ # Another
248
+
249
+ # Multiple
250
+ # Lines
251
+
252
+ foo = "bar"
253
+ EOS
254
+
255
+ expect(parsed).to eq(
256
+ {"foo"=>"bar"}
257
+ )
258
+ end
259
+
260
+ it 'complex' do
261
+ parsed = Rhcl.parse(<<-EOS)
262
+ // This comes from Terraform, as a test
263
+ variable "foo" {
264
+ default = "bar"
265
+ description = "bar"
266
+ }
267
+
268
+ provider "aws" {
269
+ access_key = "foo"
270
+ secret_key = "bar"
271
+ }
272
+
273
+ provider "do" {
274
+ api_key = "${var.foo}"
275
+ }
276
+
277
+ resource "aws_security_group" "firewall" {
278
+ count = 5
279
+ }
280
+
281
+ resource aws_instance "web" {
282
+ ami = "${var.foo}"
283
+ security_groups = [
284
+ "foo",
285
+ "${aws_security_group.firewall.foo}"
286
+ ]
287
+
288
+ network_interface {
289
+ device_index = 0
290
+ description = "Main network interface"
291
+ }
292
+ }
293
+
294
+ resource "aws_instance" "db" {
295
+ security_groups = "${aws_security_group.firewall.*.id}"
296
+ VPC = "foo"
297
+
298
+ depends_on = ["aws_instance.web"]
299
+ }
300
+
301
+ output "web_ip" {
302
+ value = "${aws_instance.web.private_ip}"
303
+ }
304
+ EOS
305
+
306
+ expect(parsed).to eq(
307
+ {"variable"=>{"foo"=>{"default"=>"bar", "description"=>"bar"}},
308
+ "provider"=>
309
+ {"aws"=>{"access_key"=>"foo", "secret_key"=>"bar"},
310
+ "do"=>{"api_key"=>"${var.foo}"}},
311
+ "resource"=>
312
+ {"aws_security_group"=>{"firewall"=>{"count"=>5}},
313
+ "aws_instance"=>
314
+ {"web"=>
315
+ {"ami"=>"${var.foo}",
316
+ "security_groups"=>["foo", "${aws_security_group.firewall.foo}"],
317
+ "network_interface"=>
318
+ {"device_index"=>0, "description"=>"Main network interface"}},
319
+ "db"=>
320
+ {"security_groups"=>"${aws_security_group.firewall.*.id}",
321
+ "VPC"=>"foo",
322
+ "depends_on"=>["aws_instance.web"]}}},
323
+ "output"=>{"web_ip"=>{"value"=>"${aws_instance.web.private_ip}"}}}
324
+ )
325
+ end
326
+ end
@@ -0,0 +1,2 @@
1
+ require 'rhcl'
2
+ require 'json'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rhcl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deep_merge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: racc
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ description: Pure Ruby HCL parser
84
+ email:
85
+ - sgwr_dts@yahoo.co.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/rhcl.rb
98
+ - lib/rhcl/dump.rb
99
+ - lib/rhcl/parse.tab.rb
100
+ - lib/rhcl/parse.y
101
+ - lib/rhcl/version.rb
102
+ - rhcl.gemspec
103
+ - spec/rhcl_dump_spec.rb
104
+ - spec/rhcl_parse_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Pure Ruby HCL parser
130
+ test_files:
131
+ - spec/rhcl_dump_spec.rb
132
+ - spec/rhcl_parse_spec.rb
133
+ - spec/spec_helper.rb