Skip to content

Commit

Permalink
Fix patterns for trimming whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tcd committed Dec 10, 2019
1 parent 572575a commit 293dd78
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

<!-- ## master (unreleased) -->

## 0.5.4 (2019-12-09)

### Changed

- Improve regular expressions for trimming trailing whitespace.

## 0.5.3 (2019-12-09)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ginny (0.5.3)
ginny (0.5.4)
coolkit (~> 0.2.2)
dry-inflector (~> 0.2.0)

Expand Down
4 changes: 2 additions & 2 deletions lib/ginny/models/class.rb
Expand Up @@ -70,10 +70,10 @@ def render()
parts << (self.body&.length&.positive? ? self.body.indent(2) : nil)
parts << "end"
if self.modules.length > 0
body = parts.compact.join("\n").gsub(/(\s+)$/, "")
body = parts.compact.join("\n").gsub(/([[:blank:]]+)$/, "")
return Ginny.mod(body, self.modules)
end
return parts.compact.join("\n").gsub(/(\s+)$/, "")
return parts.compact.join("\n").gsub(/([[:blank:]]+)$/, "")
end

# @return [String]
Expand Down
2 changes: 1 addition & 1 deletion lib/ginny/version.rb
@@ -1,3 +1,3 @@
module Ginny
VERSION = "0.5.3".freeze
VERSION = "0.5.4".freeze
end
44 changes: 44 additions & 0 deletions test/ginny/class_test.rb
Expand Up @@ -127,4 +127,48 @@ def initialize()
assert_equal(want.strip, have.strip)
end

def test_preserving_newlines
want = <<~RUBY.strip
module Eddy
module Elements
class SecurityInformationQualifier < Eddy::Element::ID
# @return [void]
def initialize()
@id = "I03"
end
# @return [Array<String>]
def code_list()
return [
"00",
"01"
]
end
end
end
end
RUBY
constructor = Ginny::Func.create({
name: "initialize",
body: '@id = "I03"',
}).render()
code_list = Ginny::Func.create({
name: "code_list",
return_type: "Array<String>",
body: <<~FUNC_BODY,
return [
"00",
"01"
]
FUNC_BODY
}).render()
have = Ginny::Class.create({
name: "SecurityInformationQualifier",
parent: "Eddy::Element::ID",
modules: ["Eddy", "Elements"],
body: constructor + "\n\n" + code_list,
}).render()
assert_equal(want, have)
end

end

0 comments on commit 293dd78

Please sign in to comment.