Skip to content

Commit

Permalink
Fix pattern match docs executbale test
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious authored and mbj committed Jun 29, 2024
1 parent e0f16de commit ff688d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/ast-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ specific:
```
send
{ selector = info
, receiver = send{selector=logger}
receiver = send{selector=logger}
}
```

Expand Down Expand Up @@ -84,7 +84,7 @@ But could be made required via:
block
{ receiver = send
{ selector = log
, receiver = send{selector=logger}
receiver = send{selector=logger}
}
}
```
42 changes: 42 additions & 0 deletions spec/unit/mutant/ast/pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,47 @@ def apply
expect(apply).to eql(right(expected_node))
end
end

context 'example from docs' do
let(:string) { <<~'PATTERN' }
block
{ receiver = send
{ selector = log
receiver = send{selector=logger}
}
}
PATTERN

let(:expected_node) do
Mutant::AST::Pattern::Node.new(
type: :block,
descendant: Mutant::AST::Pattern::Node::Descendant.new(
name: :receiver,
pattern: Mutant::AST::Pattern::Node.new(
type: :send,
attribute: Mutant::AST::Pattern::Node::Attribute.new(
name: :selector,
value: Mutant::AST::Pattern::Node::Attribute::Value::Single.new(value: :log)
),
descendant: Mutant::AST::Pattern::Node::Descendant.new(
name: :receiver,
pattern: Mutant::AST::Pattern::Node.new(
type: :send,
attribute: Mutant::AST::Pattern::Node::Attribute.new(
name: :selector,
value: Mutant::AST::Pattern::Node::Attribute::Value::Single.new(value: :logger)
)
)
)
)
)
)
end

it 'returns expected node' do
expect(apply).to eql(right(expected_node))
end
end

end
end

0 comments on commit ff688d8

Please sign in to comment.