-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from ruby/schneems/fix-run-on-sentence
Fix missing line break due to puts logic
- Loading branch information
Showing
5 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module SyntaxSuggest | ||
# Mini String IO [Private] | ||
# | ||
# Acts like a StringIO with reduced API, but without having to require that | ||
# class. | ||
class MiniStringIO | ||
EMPTY_ARG = Object.new | ||
|
||
def initialize(isatty: $stderr.isatty) | ||
@string = +"" | ||
@isatty = isatty | ||
end | ||
|
||
attr_reader :isatty | ||
def puts(value = EMPTY_ARG, **) | ||
if !value.equal?(EMPTY_ARG) | ||
@string << value | ||
end | ||
@string << $/ | ||
end | ||
|
||
attr_reader :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../spec_helper" | ||
|
||
module SyntaxSuggest | ||
RSpec.describe "MiniStringIO" do | ||
it "#puts with no inputs" do | ||
io = MiniStringIO.new | ||
io.puts | ||
expect(io.string).to eq($/) | ||
end | ||
|
||
it "#puts with an input" do | ||
io = MiniStringIO.new | ||
io.puts "Hello" | ||
expect(io.string).to eq(["Hello", $/].join) | ||
end | ||
|
||
it "#puts with an input with a newline" do | ||
io = MiniStringIO.new | ||
io.puts "Hello\n" | ||
expect(io.string).to eq(["Hello\n", $/].join) | ||
end | ||
end | ||
end |