groovy_oneliner 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d318fc216012756da8687ec71f1a7f8454246b6
4
- data.tar.gz: c80ee2b0e416668a5a272bd398886412d5ee70c9
3
+ metadata.gz: becb9184b8f80f893eacae6964412b6a68436292
4
+ data.tar.gz: feb97a340c04d053cb700d177dcdbb8c68b277f6
5
5
  SHA512:
6
- metadata.gz: 4fe72e995977a35e1aa9c8eb1edf4aa61f3658d31437532a340642a463933388979dd9c84794d1dc05c00d3ae05c6f340ba9ba3f6f7e5fa2c07596b265b940d2
7
- data.tar.gz: 1c41cea35991ee25f034e2f0017dbc2c80187caec1f042e5c53f93834c7cca24eb27735fa88e4fcb1a850c93477a166dbe7100c90a052171d57ceb895255f00a
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(/\/\/.*$/, '') # 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(/;\s*/, ';') # remove all whitespace after ;
17
- .gsub(%r{/\*.*\*\/}, '') # remove all comments /* ... */
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
@@ -1,3 +1,3 @@
1
1
  class GroovyOneliner
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -29,7 +29,7 @@ a = 3;
29
29
  return 1;
30
30
  TEXT
31
31
 
32
- expect(subject.compute).to eql("a = 3;return 1;")
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 = 4;b = 5;")
42
+ expect(subject.compute).to eql("a=4;b=5;")
43
43
  end
44
44
 
45
- it 'removes all whitespace after ;' do
46
- subject = described_class.new <<-TEXT
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
- TEXT
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
- expect(subject.compute).to eql("a = 4;b = 5;")
59
+ expect(subject.compute).to eql("a=4;b=5;")
60
+ end
51
61
  end
52
62
 
53
- it 'removes all /* comment */ blocks' do
54
- subject = described_class.new <<-TEXT
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
- TEXT
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.1.0
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-01 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler