File tree 6 files changed +32
-25
lines changed
6 files changed +32
-25
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,13 @@ require "syntax_tree/rake_tasks"
7
7
Rake ::TestTask . new ( :test ) do |t |
8
8
t . libs << "test"
9
9
t . libs << "lib"
10
- t . test_files = FileList [ "test/**/*_test.rb" ]
10
+ test_files = FileList [ "test/**/*_test.rb" ]
11
+ if RUBY_ENGINE == "truffleruby"
12
+ # language_server.rb uses pattern matching
13
+ test_files -= FileList [ "test/language_server/*_test.rb" ]
14
+ test_files -= FileList [ "test/language_server_test.rb" ]
15
+ end
16
+ t . test_files = test_files
11
17
end
12
18
13
19
task default : :test
Original file line number Diff line number Diff line change @@ -192,9 +192,9 @@ def run(item)
192
192
# would match the first expression of the input given.
193
193
class Expr < Action
194
194
def run ( item )
195
- case item . handler . parse ( item . source )
196
- in Program [ statements : Statements [ body : [ expression ] ] ]
197
- puts expression . construct_keys
195
+ program = item . handler . parse ( item . source )
196
+ if Program === program and expressions = program . statements . body and expressions . size == 1
197
+ puts expressions . first . construct_keys
198
198
else
199
199
warn ( "The input to `stree expr` must be a single expression." )
200
200
exit ( 1 )
Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ def test_inline_script
148
148
end
149
149
150
150
def test_multiple_inline_scripts
151
+ skip if RUBY_ENGINE == "truffleruby" # Relies on a thread-safe StringIO
151
152
stdio , = capture_io { SyntaxTree ::CLI . run ( %w[ format -e 1+1 -e 2+2 ] ) }
152
153
assert_equal ( [ "1 + 1" , "2 + 2" ] , stdio . split ( "\n " ) . sort )
153
154
end
@@ -172,6 +173,7 @@ def test_plugins
172
173
def test_language_server
173
174
prev_stdin = $stdin
174
175
prev_stdout = $stdout
176
+ skip unless SUPPORTS_PATTERN_MATCHING
175
177
176
178
request = { method : "shutdown" } . merge ( jsonrpc : "2.0" ) . to_json
177
179
$stdin =
Original file line number Diff line number Diff line change @@ -14,19 +14,15 @@ def test_lines
14
14
def test_deconstruct
15
15
location = Location . fixed ( line : 1 , char : 0 , column : 0 )
16
16
17
- case location
18
- in [ start_line , 0 , 0 , *]
19
- assert_equal ( 1 , start_line )
20
- end
17
+ assert_equal ( 1 , location . start_line )
18
+ assert_equal ( 0 , location . start_char )
19
+ assert_equal ( 0 , location . start_column )
21
20
end
22
21
23
22
def test_deconstruct_keys
24
23
location = Location . fixed ( line : 1 , char : 0 , column : 0 )
25
24
26
- case location
27
- in start_line :
28
- assert_equal ( 1 , start_line )
29
- end
25
+ assert_equal ( 1 , location . start_line )
30
26
end
31
27
end
32
28
end
Original file line number Diff line number Diff line change @@ -759,10 +759,9 @@ def test_program
759
759
program = parser . parse
760
760
refute ( parser . error? )
761
761
762
- case program
763
- in statements : { body : [ statement ] }
764
- assert_kind_of ( VCall , statement )
765
- end
762
+ statements = program . statements . body
763
+ assert_equal 1 , statements . size
764
+ assert_kind_of ( VCall , statements . first )
766
765
767
766
json = JSON . parse ( program . to_json )
768
767
io = StringIO . new
Original file line number Diff line number Diff line change 17
17
require "pp"
18
18
require "minitest/autorun"
19
19
20
+ SUPPORTS_PATTERN_MATCHING = RUBY_ENGINE != "truffleruby"
21
+
20
22
module SyntaxTree
21
23
module Assertions
22
24
class Recorder
@@ -67,15 +69,17 @@ def assert_syntax_tree(node)
67
69
refute_includes ( json , "#<" )
68
70
assert_equal ( type , JSON . parse ( json ) [ "type" ] )
69
71
70
- # Get a match expression from the node, then assert that it can in fact
71
- # match the node.
72
- # rubocop:disable all
73
- assert ( eval ( <<~RUBY ) )
74
- case node
75
- in #{ node . construct_keys }
76
- true
77
- end
78
- RUBY
72
+ if SUPPORTS_PATTERN_MATCHING
73
+ # Get a match expression from the node, then assert that it can in fact
74
+ # match the node.
75
+ # rubocop:disable all
76
+ assert ( eval ( <<~RUBY ) )
77
+ case node
78
+ in #{ node . construct_keys }
79
+ true
80
+ end
81
+ RUBY
82
+ end
79
83
end
80
84
81
85
Minitest ::Test . include ( self )
You can’t perform that action at this time.
0 commit comments