-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmutation_test.rb
47 lines (39 loc) · 1.12 KB
/
mutation_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
require_relative "test_helper"
module SyntaxTree
class MutationTest < Minitest::Test
def test_mutates_based_on_patterns
source = <<~RUBY
if a = b
c
end
RUBY
expected = <<~RUBY
if (a = b)
c
end
RUBY
program = SyntaxTree.parse(source).accept(build_mutation)
assert_equal(expected, SyntaxTree::Formatter.format(source, program))
end
private
def build_mutation
SyntaxTree.mutation do |mutation|
mutation.mutate("IfNode[predicate: Assign | OpAssign]") do |node|
# Get the existing If's predicate node
predicate = node.predicate
# Create a new predicate node that wraps the existing predicate node
# in parentheses
predicate =
SyntaxTree::Paren.new(
lparen: SyntaxTree::LParen.default,
contents: predicate,
location: predicate.location
)
# Return a copy of this node with the new predicate
node.copy(predicate: predicate)
end
end
end
end
end