File tree Expand file tree Collapse file tree 7 files changed +38
-13
lines changed Expand file tree Collapse file tree 7 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -332,7 +332,21 @@ def highlight_error(error, source)
332332 # Take a line of Ruby source and colorize the output.
333333 def colorize_line ( line )
334334 require "irb"
335- IRB ::Color . colorize_code ( line , complete : false , ignore_error : true )
335+ IRB ::Color . colorize_code ( line , **colorize_options )
336+ end
337+
338+ # These are the options we're going to pass into IRB::Color.colorize_code.
339+ # Since we support multiple versions of IRB, we're going to need to do
340+ # some reflection to make sure we always pass valid options.
341+ def colorize_options
342+ options = { complete : false }
343+
344+ parameters = IRB ::Color . method ( :colorize_code ) . parameters
345+ if parameters . any? { |( _type , name ) | name == :ignore_error }
346+ options [ :ignore_error ] = true
347+ end
348+
349+ options
336350 end
337351 end
338352 end
Original file line number Diff line number Diff line change @@ -1388,14 +1388,19 @@ def format(q)
13881388 module HashKeyFormatter
13891389 # Formats the keys of a hash literal using labels.
13901390 class Labels
1391+ LABEL = /^[@$_A-Za-z]([_A-Za-z0-9]*)?([!_=?A-Za-z0-9])?$/
1392+
13911393 def format_key ( q , key )
13921394 case key
1393- when Label
1395+ in Label
13941396 q . format ( key )
1395- when SymbolLiteral
1397+ in SymbolLiteral
13961398 q . format ( key . value )
13971399 q . text ( ":" )
1398- when DynaSymbol
1400+ in DynaSymbol [ parts : [ TStringContent [ value : LABEL ] => part ] ]
1401+ q . format ( part )
1402+ q . text ( ":" )
1403+ in DynaSymbol
13991404 q . format ( key )
14001405 q . text ( ":" )
14011406 end
Original file line number Diff line number Diff line change @@ -119,8 +119,10 @@ def test_help_default
119119 end
120120
121121 def test_no_arguments
122- *, stderr = capture_io { SyntaxTree ::CLI . run ( [ "check" ] ) }
123- assert_includes ( stderr , "stree help" )
122+ $stdin. stub ( :tty? , true ) do
123+ *, stderr = capture_io { SyntaxTree ::CLI . run ( [ "check" ] ) }
124+ assert_includes ( stderr , "stree help" )
125+ end
124126 end
125127
126128 def test_no_arguments_no_tty
@@ -134,7 +136,7 @@ def test_no_arguments_no_tty
134136 end
135137
136138 def test_generic_error
137- SyntaxTree . stub ( :format , -> ( *) { raise } ) do
139+ SyntaxTree . stub ( :format , -> ( *) { raise } ) do
138140 result = run_cli ( "format" )
139141 refute_equal ( 0 , result . status )
140142 end
@@ -154,9 +156,7 @@ def run_cli(command, file: nil)
154156
155157 status = nil
156158 stdio , stderr =
157- capture_io do
158- status = SyntaxTree ::CLI . run ( [ command , file . path ] )
159- end
159+ capture_io { status = SyntaxTree ::CLI . run ( [ command , file . path ] ) }
160160
161161 Result . new ( status : status , stdio : stdio , stderr : stderr )
162162 ensure
Original file line number Diff line number Diff line change 4040}
4141% # >= 3.1.0
4242{ foo: }
43+ %
44+ { "foo": "bar" }
45+ -
46+ { foo: "bar" }
47+ %
48+ { "foo #{ bar } ": "baz" }
Original file line number Diff line number Diff line change 77%
88foo(:"bar" => bar)
99-
10- foo(" bar" : bar)
10+ foo(bar: bar)
1111%
1212foo(bar => bar, baz: baz)
1313-
Original file line number Diff line number Diff line change 1515%
1616{ %s[foo] => bar }
1717-
18- { " foo" : bar }
18+ { foo: bar }
1919%
2020%s[
2121 foo
Original file line number Diff line number Diff line change 99%
1010{ :"bar" => bar }
1111-
12- { " bar" : bar }
12+ { bar: bar }
1313%
1414{ bar => bar, baz: baz }
1515-
You can’t perform that action at this time.
0 commit comments