groovy_oneliner 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/groovy_oneliner/converter.rb +8 -6
- data/lib/groovy_oneliner/version.rb +1 -1
- data/spec/groovy_oneliner/converter_spec.rb +39 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: becb9184b8f80f893eacae6964412b6a68436292
|
4
|
+
data.tar.gz: feb97a340c04d053cb700d177dcdbb8c68b277f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a64e75d13f1b0f271a697595209fa48664d17497c38dbaa85e8735f037ef9557414bc0b8cb80d76d5d378335199b8d97329af8af4ec9cb79fc29560643fa81
|
7
|
+
data.tar.gz: ac765a3f0f7aa37a6e56753b41eaed69677f6acd163a38512c198987e7c5b9aa4851396074295212d854fe51b3e8aa4e0f8c12df5ad6df56a13de886e12066a2
|
@@ -9,12 +9,14 @@ class GroovyOneliner
|
|
9
9
|
|
10
10
|
def compute
|
11
11
|
@content
|
12
|
-
.gsub(/\/\/.*$/, '')
|
13
|
-
.gsub("\n", '')
|
14
|
-
.gsub("\"", "'")
|
15
|
-
.gsub(/^$/, '')
|
16
|
-
.gsub(
|
17
|
-
.gsub(
|
12
|
+
.gsub(/\/\/.*$/, '') # remove all comments //
|
13
|
+
.gsub("\n", '') # remove all line-breaks
|
14
|
+
.gsub("\"", "'") # substitute all double-quote to single-quote
|
15
|
+
.gsub(/^$/, '') # remove all empty lines
|
16
|
+
.gsub(%r{\/\*(\*(?!\/)|[^*])*\*\/}, '') # remove all /* */ comments
|
17
|
+
.gsub(/\s*;\s*/, ';') # remove all whitespace before and after ;
|
18
|
+
.gsub(/\s*=\s*/, '=') # remove all whitespace before and after ;
|
19
|
+
.strip
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -29,7 +29,7 @@ a = 3;
|
|
29
29
|
return 1;
|
30
30
|
TEXT
|
31
31
|
|
32
|
-
expect(subject.compute).to eql("a
|
32
|
+
expect(subject.compute).to eql("a=3;return 1;")
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'removes all empty lines' do
|
@@ -39,27 +39,56 @@ a = 4;
|
|
39
39
|
b = 5;
|
40
40
|
TEXT
|
41
41
|
|
42
|
-
expect(subject.compute).to eql("a
|
42
|
+
expect(subject.compute).to eql("a=4;b=5;")
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
context 'when removing whitespace' do
|
46
|
+
it 'removes all before and after ;' do
|
47
|
+
subject = described_class.new <<-TEXT
|
47
48
|
a = 4; b = 5;
|
48
|
-
|
49
|
+
TEXT
|
50
|
+
|
51
|
+
expect(subject.compute).to eql("a=4;b=5;")
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'removes all before and after =' do
|
55
|
+
subject = described_class.new <<-TEXT
|
56
|
+
a = 4; b = 5;
|
57
|
+
TEXT
|
49
58
|
|
50
|
-
|
59
|
+
expect(subject.compute).to eql("a=4;b=5;")
|
60
|
+
end
|
51
61
|
end
|
52
62
|
|
53
|
-
|
54
|
-
|
63
|
+
context 'when handling /* */ block' do
|
64
|
+
it 'removes the block' do
|
65
|
+
subject = described_class.new <<-TEXT
|
55
66
|
/*
|
56
67
|
* This is a comment and will be ignored
|
57
68
|
*/
|
58
69
|
return 1;
|
59
|
-
|
70
|
+
TEXT
|
71
|
+
|
72
|
+
expect(subject.compute).to eql("return 1;")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'handles multiple blocks' do
|
76
|
+
subject = described_class.new <<-TEXT
|
77
|
+
/*
|
78
|
+
* This is a comment and will be ignored
|
79
|
+
*/
|
80
|
+
a = 1;
|
81
|
+
/*
|
82
|
+
* This is a comment and will be ignored
|
83
|
+
*/
|
84
|
+
b = 1;
|
85
|
+
TEXT
|
86
|
+
|
87
|
+
expect(subject.compute).to eql("a=1;b=1;")
|
88
|
+
end
|
60
89
|
|
61
|
-
expect(subject.compute).to eql("return 1;")
|
62
90
|
end
|
63
91
|
|
92
|
+
|
64
93
|
end
|
65
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groovy_oneliner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Cunha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|