File tree 7 files changed +38
-13
lines changed
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)
332
332
# Take a line of Ruby source and colorize the output.
333
333
def colorize_line ( line )
334
334
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
336
350
end
337
351
end
338
352
end
Original file line number Diff line number Diff line change @@ -1388,14 +1388,19 @@ def format(q)
1388
1388
module HashKeyFormatter
1389
1389
# Formats the keys of a hash literal using labels.
1390
1390
class Labels
1391
+ LABEL = /^[@$_A-Za-z]([_A-Za-z0-9]*)?([!_=?A-Za-z0-9])?$/
1392
+
1391
1393
def format_key ( q , key )
1392
1394
case key
1393
- when Label
1395
+ in Label
1394
1396
q . format ( key )
1395
- when SymbolLiteral
1397
+ in SymbolLiteral
1396
1398
q . format ( key . value )
1397
1399
q . text ( ":" )
1398
- when DynaSymbol
1400
+ in DynaSymbol [ parts : [ TStringContent [ value : LABEL ] => part ] ]
1401
+ q . format ( part )
1402
+ q . text ( ":" )
1403
+ in DynaSymbol
1399
1404
q . format ( key )
1400
1405
q . text ( ":" )
1401
1406
end
Original file line number Diff line number Diff line change @@ -119,8 +119,10 @@ def test_help_default
119
119
end
120
120
121
121
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
124
126
end
125
127
126
128
def test_no_arguments_no_tty
@@ -134,7 +136,7 @@ def test_no_arguments_no_tty
134
136
end
135
137
136
138
def test_generic_error
137
- SyntaxTree . stub ( :format , -> ( *) { raise } ) do
139
+ SyntaxTree . stub ( :format , -> ( *) { raise } ) do
138
140
result = run_cli ( "format" )
139
141
refute_equal ( 0 , result . status )
140
142
end
@@ -154,9 +156,7 @@ def run_cli(command, file: nil)
154
156
155
157
status = nil
156
158
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 ] ) }
160
160
161
161
Result . new ( status : status , stdio : stdio , stderr : stderr )
162
162
ensure
Original file line number Diff line number Diff line change 40
40
}
41
41
% # >= 3.1.0
42
42
{ foo: }
43
+ %
44
+ { "foo": "bar" }
45
+ -
46
+ { foo: "bar" }
47
+ %
48
+ { "foo #{ bar } ": "baz" }
Original file line number Diff line number Diff line change 7
7
%
8
8
foo(:"bar" => bar)
9
9
-
10
- foo(" bar" : bar)
10
+ foo(bar: bar)
11
11
%
12
12
foo(bar => bar, baz: baz)
13
13
-
Original file line number Diff line number Diff line change 15
15
%
16
16
{ %s[foo] => bar }
17
17
-
18
- { " foo" : bar }
18
+ { foo: bar }
19
19
%
20
20
%s[
21
21
foo
Original file line number Diff line number Diff line change 9
9
%
10
10
{ :"bar" => bar }
11
11
-
12
- { " bar" : bar }
12
+ { bar: bar }
13
13
%
14
14
{ bar => bar, baz: baz }
15
15
-
You can’t perform that action at this time.
0 commit comments