Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit999292b

Browse files
authored
Merge pull request#183 from eregon/truffleruby-ci
Make the test suite pass on TruffleRuby and add it in CI
2 parentsbd9a1c3 +570a2d1 commit999292b

File tree

9 files changed

+74
-58
lines changed

9 files changed

+74
-58
lines changed

‎.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ jobs:
1212
-'3.0'
1313
-'3.1'
1414
-head
15+
-truffleruby-head
1516
name:CI
1617
runs-on:ubuntu-latest
1718
env:
1819
CI:true
20+
TESTOPTS:--verbose
1921
steps:
2022
-uses:actions/checkout@master
2123
-uses:ruby/setup-ruby@v1

‎Rakefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ require "syntax_tree/rake_tasks"
77
Rake::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+
ifRUBY_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
1117
end
1218

1319
taskdefault::test

‎lib/syntax_tree/cli.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ def run(item)
192192
# would match the first expression of the input given.
193193
classExpr <Action
194194
defrun(item)
195-
caseitem.handler.parse(item.source)
196-
inProgram[statements:Statements[body:[expression]]]
197-
putsexpression.construct_keys
195+
program=item.handler.parse(item.source)
196+
ifProgram ===programandexpressions=program.statements.bodyand
197+
expressions.size ==1
198+
putsexpressions.first.construct_keys
198199
else
199200
warn("The input to `stree expr` must be a single expression.")
200201
exit(1)

‎lib/syntax_tree/pattern.rb

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def combine_or(left, right)
8484
end
8585

8686
defcompile_node(root)
87-
caseroot
88-
inAryPtn[constant:,requireds:,rest:nil,posts:[]]
87+
ifAryPtn ===rootandroot.rest.nil?androot.posts.empty?
88+
constant=root.constant
8989
compiled_constant=compile_node(constant)ifconstant
9090

91-
preprocessed=requireds.map{ |required|compile_node(required)}
91+
preprocessed=root.requireds.map{ |required|compile_node(required)}
9292

9393
compiled_requireds=->(node)do
9494
deconstructed=node.deconstruct
@@ -104,34 +104,37 @@ def compile_node(root)
104104
else
105105
compiled_requireds
106106
end
107-
inBinary[left:,operator::|,right:]
108-
combine_or(compile_node(left),compile_node(right))
109-
inConst[value:]ifSyntaxTree.const_defined?(value)
110-
clazz=SyntaxTree.const_get(value)
107+
elsifBinary ===rootandroot.operator ==:|
108+
combine_or(compile_node(root.left),compile_node(root.right))
109+
elsifConst ===rootandSyntaxTree.const_defined?(root.value)
110+
clazz=SyntaxTree.const_get(root.value)
111111

112112
->(node){node.is_a?(clazz)}
113-
inConst[value:]ifObject.const_defined?(value)
114-
clazz=Object.const_get(value)
113+
elsifConst ===rootandObject.const_defined?(root.value)
114+
clazz=Object.const_get(root.value)
115115

116116
->(node){node.is_a?(clazz)}
117-
inConstPathRef[
118-
parent:VarRef[value:Const[value:"SyntaxTree"]],constant:
119-
]
120-
compile_node(constant)
121-
inDynaSymbol[parts:[]]
117+
elsifConstPathRef ===rootandVarRef ===root.parentand
118+
Const ===root.parent.valueand
119+
root.parent.value.value =="SyntaxTree"
120+
compile_node(root.constant)
121+
elsifDynaSymbol ===rootandroot.parts.empty?
122122
symbol=:""
123123

124124
->(node){node ==symbol}
125-
inDynaSymbol[parts:[TStringContent[value:]]]
126-
symbol=value.to_sym
125+
elsifDynaSymbol ===rootandparts=root.partsandparts.size ==1and
126+
TStringContent ===parts[0]
127+
symbol=parts[0].value.to_sym
127128

128-
->(attribute){attribute ==value}
129-
inHshPtn[constant:,keywords:,keyword_rest:nil]
130-
compiled_constant=compile_node(constant)
129+
->(node){node ==symbol}
130+
elsifHshPtn ===rootandroot.keyword_rest.nil?
131+
compiled_constant=compile_node(root.constant)
131132

132133
preprocessed=
133-
keywords.to_hdo |keyword,value|
134-
raiseNoMatchingPatternErrorunlesskeyword.is_a?(Label)
134+
root.keywords.to_hdo |keyword,value|
135+
unlesskeyword.is_a?(Label)
136+
raiseCompilationError,PP.pp(root, +"").chomp
137+
end
135138
[keyword.value.chomp(":").to_sym,compile_node(value)]
136139
end
137140

@@ -148,25 +151,28 @@ def compile_node(root)
148151
else
149152
compiled_keywords
150153
end
151-
inRegexpLiteral[parts:[TStringContent[value:]]]
152-
regexp=/#{value}/
154+
elsifRegexpLiteral ===rootandparts=root.partsand
155+
parts.size ==1andTStringContent ===parts[0]
156+
regexp=/#{parts[0].value}/
153157

154158
->(attribute){regexp.match?(attribute)}
155-
inStringLiteral[parts:[]]
159+
elsifStringLiteral ===rootandroot.parts.empty?
156160
->(attribute){attribute ==""}
157-
inStringLiteral[parts:[TStringContent[value:]]]
161+
elsifStringLiteral ===rootandparts=root.partsand
162+
parts.size ==1andTStringContent ===parts[0]
163+
value=parts[0].value
158164
->(attribute){attribute ==value}
159-
inSymbolLiteral[value:]
160-
symbol=value.value.to_sym
165+
elsifSymbolLiteral ===root
166+
symbol=root.value.value.to_sym
161167

162168
->(attribute){attribute ==symbol}
163-
inVarRef[value:Const=>value]
164-
compile_node(value)
165-
inVarRef[value:Kw[value:"nil"]]
169+
elsifVarRef ===rootandConst ===root.value
170+
compile_node(root.value)
171+
elsifVarRef ===rootandKw ===root.valueandroot.value.value.nil?
166172
->(attribute){attribute.nil?}
173+
else
174+
raiseCompilationError,PP.pp(root, +"").chomp
167175
end
168-
rescueNoMatchingPatternError
169-
raiseCompilationError,PP.pp(root, +"").chomp
170176
end
171177
end
172178
end

‎test/cli_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def test_inline_script
148148
end
149149

150150
deftest_multiple_inline_scripts
151+
skipifRUBY_ENGINE =="truffleruby"# Relies on a thread-safe StringIO
151152
stdio,=capture_io{SyntaxTree::CLI.run(%w[format-e1+1-e2+2])}
152153
assert_equal(["1 + 1","2 + 2"],stdio.split("\n").sort)
153154
end
@@ -172,6 +173,7 @@ def test_plugins
172173
deftest_language_server
173174
prev_stdin= $stdin
174175
prev_stdout= $stdout
176+
skipunlessSUPPORTS_PATTERN_MATCHING
175177

176178
request={method:"shutdown"}.merge(jsonrpc:"2.0").to_json
177179
$stdin=

‎test/idempotency_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
returnunlessENV["CI"]
3+
returnunlessENV["CI"]andRUBY_ENGINE !="truffleruby"
44
require_relative"test_helper"
55

66
moduleSyntaxTree

‎test/location_test.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@ def test_lines
1414
deftest_deconstruct
1515
location=Location.fixed(line:1,char:0,column:0)
1616

17-
caselocation
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
deftest_deconstruct_keys
2423
location=Location.fixed(line:1,char:0,column:0)
2524

26-
caselocation
27-
instart_line:
28-
assert_equal(1,start_line)
29-
end
25+
assert_equal(1,location.start_line)
3026
end
3127
end
3228
end

‎test/node_test.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,9 @@ def test_program
759759
program=parser.parse
760760
refute(parser.error?)
761761

762-
caseprogram
763-
instatements:{body:[statement]}
764-
assert_kind_of(VCall,statement)
765-
end
762+
statements=program.statements.body
763+
assert_equal1,statements.size
764+
assert_kind_of(VCall,statements.first)
766765

767766
json=JSON.parse(program.to_json)
768767
io=StringIO.new

‎test/test_helper.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
require"pp"
1818
require"minitest/autorun"
1919

20+
SUPPORTS_PATTERN_MATCHING=RUBY_ENGINE !="truffleruby"
21+
2022
moduleSyntaxTree
2123
moduleAssertions
2224
classRecorder
@@ -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+
ifSUPPORTS_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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp