From ff688d85cdf2a308efa84e15ba4cba47a030aa7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Thu, 23 May 2024 23:14:25 +0200 Subject: [PATCH] Fix pattern match docs executbale test --- docs/ast-pattern.md | 4 +-- spec/unit/mutant/ast/pattern_spec.rb | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/ast-pattern.md b/docs/ast-pattern.md index e08910bad..377b4bf8e 100644 --- a/docs/ast-pattern.md +++ b/docs/ast-pattern.md @@ -30,7 +30,7 @@ specific: ``` send { selector = info - , receiver = send{selector=logger} + receiver = send{selector=logger} } ``` @@ -84,7 +84,7 @@ But could be made required via: block { receiver = send { selector = log - , receiver = send{selector=logger} + receiver = send{selector=logger} } } ``` diff --git a/spec/unit/mutant/ast/pattern_spec.rb b/spec/unit/mutant/ast/pattern_spec.rb index 569d30db1..74cb75fcd 100644 --- a/spec/unit/mutant/ast/pattern_spec.rb +++ b/spec/unit/mutant/ast/pattern_spec.rb @@ -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