File tree Expand file tree Collapse file tree 6 files changed +32
-25
lines changed Expand file tree Collapse file tree 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"
77Rake ::TestTask . new ( :test ) do |t |
88 t . libs << "test"
99 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
1117end
1218
1319task default : :test
Original file line number Diff line number Diff line change @@ -192,9 +192,9 @@ def run(item)
192192 # would match the first expression of the input given.
193193 class Expr < Action
194194 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
198198 else
199199 warn ( "The input to `stree expr` must be a single expression." )
200200 exit ( 1 )
Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ def test_inline_script
148148 end
149149
150150 def test_multiple_inline_scripts
151+ skip if RUBY_ENGINE == "truffleruby" # Relies on a thread-safe StringIO
151152 stdio , = capture_io { SyntaxTree ::CLI . run ( %w[ format -e 1+1 -e 2+2 ] ) }
152153 assert_equal ( [ "1 + 1" , "2 + 2" ] , stdio . split ( "\n " ) . sort )
153154 end
@@ -172,6 +173,7 @@ def test_plugins
172173 def test_language_server
173174 prev_stdin = $stdin
174175 prev_stdout = $stdout
176+ skip unless SUPPORTS_PATTERN_MATCHING
175177
176178 request = { method : "shutdown" } . merge ( jsonrpc : "2.0" ) . to_json
177179 $stdin =
Original file line number Diff line number Diff line change @@ -14,19 +14,15 @@ def test_lines
1414 def test_deconstruct
1515 location = Location . fixed ( line : 1 , char : 0 , column : 0 )
1616
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 )
2120 end
2221
2322 def test_deconstruct_keys
2423 location = Location . fixed ( line : 1 , char : 0 , column : 0 )
2524
26- case location
27- in start_line :
28- assert_equal ( 1 , start_line )
29- end
25+ assert_equal ( 1 , location . start_line )
3026 end
3127 end
3228end
Original file line number Diff line number Diff line change @@ -759,10 +759,9 @@ def test_program
759759 program = parser . parse
760760 refute ( parser . error? )
761761
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 )
766765
767766 json = JSON . parse ( program . to_json )
768767 io = StringIO . new
Original file line number Diff line number Diff line change 1717require "pp"
1818require "minitest/autorun"
1919
20+ SUPPORTS_PATTERN_MATCHING = RUBY_ENGINE != "truffleruby"
21+
2022module SyntaxTree
2123 module Assertions
2224 class Recorder
@@ -67,15 +69,17 @@ def assert_syntax_tree(node)
6769 refute_includes ( json , "#<" )
6870 assert_equal ( type , JSON . parse ( json ) [ "type" ] )
6971
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
7983 end
8084
8185 Minitest ::Test . include ( self )
You can’t perform that action at this time.
0 commit comments