synvert-core 0.62.1 → 0.63.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79777679e6001f32c8b4bc587e2f007f396eeecd9c0c7e29926e01a3628b4244
4
- data.tar.gz: df4d3eda62e9b2f49ec1cf8da96bd98952d7d5af70fd4d6861b206bbc923cca9
3
+ metadata.gz: a008b0eb8cb6152ae896c550c0b5317f7c9679f9b23f4203c270e34b04f6f76a
4
+ data.tar.gz: 38ac175aabd6f7b8f598408bcc0615905bc9ee237070d514da3bc2aee30b96be
5
5
  SHA512:
6
- metadata.gz: c9744e62dc972253304018ac041aa1f4cd01efd8a80a207a77145e088d4d69713ef4ec10ade9fe4d251811b6a8166d8e33b575ea91265fbec4f989a9e29ac376
7
- data.tar.gz: cad73e2d256e25370b535a0f623fee47c02f4d5a56e3feaed50f81a798cf3c1dbb0ffd4d6ad04ab167be78fc390703a2a01f0377b79ea621f1674399aa2c7534
6
+ metadata.gz: e4d2c687d3f1f77ef46347718eec9753d920de3cefe410add119197814a24b8cd246c9442dd5ab09e163b719b9cd326088974d2c3519aa78a14a0fef38986457
7
+ data.tar.gz: 75dd1ce3fa81439af5667eedf08b5b071394e6f025d3f31887527393c8cfd9057d8d58e9b3306cb8b3150898b065c85c1094f015308b6091844f12f9b0aa4464
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.62.1 (2022-01-14)
3
+ ## 0.63.0 (2022-02-26)
4
4
 
5
5
  * Add `to` option to `InsertAction`
6
+ * Add `gt`, `gte`, `lt` and `lte` rules
6
7
 
7
8
  ## 0.62.0 (2021-12-24)
8
9
 
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in synvert.gemspec
6
6
  gemspec
7
-
8
- gem 'coveralls', require: false
@@ -487,27 +487,29 @@ module Parser::AST
487
487
  # @param rules [Hash] rules to match.
488
488
  # @return true if matches.
489
489
  def match?(rules)
490
+ keywords = %i[any contain not in not_in gt gte lt lte]
490
491
  flat_hash(rules).keys.all? do |multi_keys|
491
- case multi_keys.last
492
+ last_key = multi_keys.last
493
+ actual = keywords.include?(last_key) ? actual_value(multi_keys[0...-1]) : actual_value(multi_keys)
494
+ expected = expected_value(rules, multi_keys)
495
+ case last_key
492
496
  when :any, :contain
493
- actual_values = actual_value(self, multi_keys[0...-1])
494
- expected = expected_value(rules, multi_keys)
495
- actual_values.any? { |actual| match_value?(actual, expected) }
497
+ actual.any? { |actual_value| match_value?(actual_value, expected) }
496
498
  when :not
497
- actual = actual_value(self, multi_keys[0...-1])
498
- expected = expected_value(rules, multi_keys)
499
499
  !match_value?(actual, expected)
500
500
  when :in
501
- actual = actual_value(self, multi_keys[0...-1])
502
- expected_values = expected_value(rules, multi_keys)
503
- expected_values.any? { |expected| match_value?(actual, expected) }
501
+ expected.any? { |expected_value| match_value?(actual, expected_value) }
504
502
  when :not_in
505
- actual = actual_value(self, multi_keys[0...-1])
506
- expected_values = expected_value(rules, multi_keys)
507
- expected_values.all? { |expected| !match_value?(actual, expected) }
503
+ expected.all? { |expected_value| !match_value?(actual, expected_value) }
504
+ when :gt
505
+ actual > expected
506
+ when :gte
507
+ actual >= expected
508
+ when :lt
509
+ actual < expected
510
+ when :lte
511
+ actual <= expected
508
512
  else
509
- actual = actual_value(self, multi_keys)
510
- expected = expected_value(rules, multi_keys)
511
513
  match_value?(actual, expected)
512
514
  end
513
515
  end
@@ -696,8 +698,8 @@ module Parser::AST
696
698
  # @param node [Parser::AST::Node]
697
699
  # @param multi_keys [Array<Symbol>]
698
700
  # @return [Object] actual value.
699
- def actual_value(node, multi_keys)
700
- multi_keys.inject(node) { |n, key| n.send(key) if n }
701
+ def actual_value(multi_keys)
702
+ multi_keys.inject(self) { |n, key| n.send(key) if n }
701
703
  end
702
704
 
703
705
  # Get expected value from rules.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.62.1'
5
+ VERSION = '0.63.0'
6
6
  end
7
7
  end
data/spec/spec_helper.rb CHANGED
@@ -4,9 +4,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
 
5
5
  require 'synvert/core'
6
6
 
7
- require 'coveralls'
8
- Coveralls.wear!
9
-
10
7
  Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
11
8
  require path
12
9
  end
@@ -567,6 +567,34 @@ describe Parser::AST::Node do
567
567
  node = parse(source)
568
568
  expect(node).not_to be_match(type: 'send', message: { not_in: %i[create build] })
569
569
  end
570
+
571
+ it 'matches gt' do
572
+ source = 'foobar(foo, bar)'
573
+ node = parse(source)
574
+ expect(node).to be_match(type: 'send', arguments: { size: { gt: 1 } })
575
+ expect(node).not_to be_match(type: 'send', arguments: { size: { gt: 2 } })
576
+ end
577
+
578
+ it 'matches gte' do
579
+ source = 'foobar(foo, bar)'
580
+ node = parse(source)
581
+ expect(node).to be_match(type: 'send', arguments: { size: { gte: 2 } })
582
+ expect(node).not_to be_match(type: 'send', arguments: { size: { gte: 3 } })
583
+ end
584
+
585
+ it 'matches lt' do
586
+ source = 'foobar(foo, bar)'
587
+ node = parse(source)
588
+ expect(node).to be_match(type: 'send', arguments: { size: { lt: 3 } })
589
+ expect(node).not_to be_match(type: 'send', arguments: { size: { lt: 2 } })
590
+ end
591
+
592
+ it 'matches lte' do
593
+ source = 'foobar(foo, bar)'
594
+ node = parse(source)
595
+ expect(node).to be_match(type: 'send', arguments: { size: { lte: 2 } })
596
+ expect(node).not_to be_match(type: 'send', arguments: { size: { lte: 1 } })
597
+ end
570
598
  end
571
599
 
572
600
  describe '#child_node_by_name' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.62.1
4
+ version: 0.63.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport