sexp_processor 4.12.1 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +13 -0
- data/Manifest.txt +1 -0
- data/lib/sexp.rb +9 -1051
- data/lib/sexp_matcher.rb +1063 -0
- data/lib/sexp_processor.rb +1 -1
- data/test/test_sexp.rb +171 -125
- metadata +6 -5
- metadata.gz.sig +0 -0
data/lib/sexp_processor.rb
CHANGED
data/test/test_sexp.rb
CHANGED
@@ -233,16 +233,16 @@ class TestSexp < SexpTestCase # ZenTest FULL
|
|
233
233
|
end
|
234
234
|
|
235
235
|
def test_equal3_subset_match
|
236
|
-
assert_match s{
|
237
|
-
assert_equal3 s{
|
238
|
-
assert_equal3 s{
|
239
|
-
assert_equal3 s{
|
240
|
-
assert_equal3 s{
|
236
|
+
assert_match s{q(:a)}, s(s(:a), s(:b)) # left - =~
|
237
|
+
assert_equal3 s{q(:a)}, s(s(:a), s(:b)) # left - ===
|
238
|
+
assert_equal3 s{q(:a)}, s(:blah, s(:a ), s(:b)) # mid 1
|
239
|
+
assert_equal3 s{q(:a, 1)}, s(:blah, s(:a, 1), s(:b)) # mid 2
|
240
|
+
assert_equal3 s{q(:a)}, s(:blah, s(:blah, s(:a))) # left deeper
|
241
241
|
end
|
242
242
|
|
243
243
|
def test_equalstilde_fancy
|
244
|
-
assert_match s{
|
245
|
-
assert_match s(:a, s(:b), :c), s{
|
244
|
+
assert_match s{ q(:b) }, s(:a, s(:b), :c)
|
245
|
+
assert_match s(:a, s(:b), :c), s{ q(:b) }
|
246
246
|
|
247
247
|
e = assert_raises ArgumentError do
|
248
248
|
s(:b) =~ s(:a, s(:b), :c)
|
@@ -256,8 +256,8 @@ class TestSexp < SexpTestCase # ZenTest FULL
|
|
256
256
|
end
|
257
257
|
|
258
258
|
def test_equalstilde_plain
|
259
|
-
s{
|
260
|
-
s(:data) =~ s{
|
259
|
+
s{ q(:re) } =~ s(:data) # pattern on LHS
|
260
|
+
s(:data) =~ s{ q(:re) } # pattern on RHS
|
261
261
|
|
262
262
|
e = assert_raises ArgumentError do
|
263
263
|
s(:re) =~ s(:data) # no pattern
|
@@ -297,10 +297,10 @@ class TestSexp < SexpTestCase # ZenTest FULL
|
|
297
297
|
end
|
298
298
|
|
299
299
|
def test_gsub_matcher
|
300
|
-
assert_gsub s(:a, :b, :c), s(:a, s(:b, 42), :c), s{
|
301
|
-
assert_gsub s(:a, s(:b), :c), s(:a, s(:b), :c), s{
|
302
|
-
assert_gsub s(:a, s(:c, :b), :d), s(:a, s(:c, s(:b, 42)), :d), s{
|
303
|
-
assert_gsub s(:a, s(:q), :c), s(:a, s(:q), :c), s{
|
300
|
+
assert_gsub s(:a, :b, :c), s(:a, s(:b, 42), :c), s{ q(:b, _) }, :b
|
301
|
+
assert_gsub s(:a, s(:b), :c), s(:a, s(:b), :c), s{ q(:b, _) }, :b
|
302
|
+
assert_gsub s(:a, s(:c, :b), :d), s(:a, s(:c, s(:b, 42)), :d), s{ q(:b, _) }, :b
|
303
|
+
assert_gsub s(:a, s(:q), :c), s(:a, s(:q), :c), s{ q(:b, _) }, :b
|
304
304
|
end
|
305
305
|
|
306
306
|
def with_env key
|
@@ -589,14 +589,14 @@ class TestSexp < SexpTestCase # ZenTest FULL
|
|
589
589
|
end
|
590
590
|
|
591
591
|
def test_sub_matcher
|
592
|
-
assert_sub s(:c), s(:b), s{
|
593
|
-
assert_sub s(:a, s(:c), s(:b)), s(:a, s(:b), s(:b)), s{
|
594
|
-
assert_sub s(:a, s(:c), s(:a)), s(:a, s(:b), s(:a)), s{
|
592
|
+
assert_sub s(:c), s(:b), s{ q(:b) }, s(:c)
|
593
|
+
assert_sub s(:a, s(:c), s(:b)), s(:a, s(:b), s(:b)), s{ q(:b) }, s(:c)
|
594
|
+
assert_sub s(:a, s(:c), s(:a)), s(:a, s(:b), s(:a)), s{ q(:b) }, s(:c)
|
595
595
|
|
596
|
-
assert_sub s(:a, :b, :c), s(:a, s(:b, 42), :c), s{
|
597
|
-
assert_sub s(:a, s(:b), :c), s(:a, s(:b), :c), s{
|
598
|
-
assert_sub s(:a, s(:c, :b), :d), s(:a, s(:c, s(:b, 42)), :d), s{
|
599
|
-
assert_sub s(:a, s(:q), :c), s(:a, s(:q), :c), s{
|
596
|
+
assert_sub s(:a, :b, :c), s(:a, s(:b, 42), :c), s{ q(:b, _) }, :b
|
597
|
+
assert_sub s(:a, s(:b), :c), s(:a, s(:b), :c), s{ q(:b, _) }, :b
|
598
|
+
assert_sub s(:a, s(:c, :b), :d), s(:a, s(:c, s(:b, 42)), :d), s{ q(:b, _) }, :b
|
599
|
+
assert_sub s(:a, s(:q), :c), s(:a, s(:q), :c), s{ q(:b, _) }, :b
|
600
600
|
end
|
601
601
|
|
602
602
|
def test_sub_structure
|
@@ -682,7 +682,7 @@ end # TestSexp
|
|
682
682
|
|
683
683
|
class TestSexpMatcher < SexpTestCase
|
684
684
|
def test_cls_s
|
685
|
-
assert_equal M.
|
685
|
+
assert_equal M.q(:x), s{ q(:x) }
|
686
686
|
end
|
687
687
|
|
688
688
|
def test_cls_underscore
|
@@ -702,19 +702,19 @@ class TestSexpMatcher < SexpTestCase
|
|
702
702
|
end
|
703
703
|
|
704
704
|
def test_cls_any
|
705
|
-
assert_equal M::Any.new(M.
|
705
|
+
assert_equal M::Any.new(M.q(:a), M.q(:b)), s{ any(q(:a), q(:b)) }
|
706
706
|
end
|
707
707
|
|
708
708
|
def test_cls_all
|
709
|
-
assert_equal M::All.new(M.
|
709
|
+
assert_equal M::All.new(M.q(:a), M.q(:b)), s{ all(q(:a), q(:b)) }
|
710
710
|
end
|
711
711
|
|
712
712
|
def test_cls_not_eh
|
713
|
-
assert_equal M::Not.new(M.
|
713
|
+
assert_equal M::Not.new(M.q(:a)), s{ not?(q(:a)) }
|
714
714
|
end
|
715
715
|
|
716
716
|
def test_cls_child
|
717
|
-
assert_equal M::Child.new(M.
|
717
|
+
assert_equal M::Child.new(M.q(:a)), s{ child(q(:a)) }
|
718
718
|
end
|
719
719
|
|
720
720
|
def test_cls_t
|
@@ -730,37 +730,37 @@ class TestSexpMatcher < SexpTestCase
|
|
730
730
|
end
|
731
731
|
|
732
732
|
def test_amp
|
733
|
-
m = s{
|
734
|
-
e = M::All.new(M.
|
733
|
+
m = s{ q(:a) & q(:b) }
|
734
|
+
e = M::All.new(M.q(:a), M.q(:b))
|
735
735
|
|
736
736
|
assert_equal e, m
|
737
737
|
end
|
738
738
|
|
739
739
|
def test_pipe
|
740
|
-
m = s{
|
741
|
-
e = M::Any.new(M.
|
740
|
+
m = s{ q(:a) | q(:b) }
|
741
|
+
e = M::Any.new(M.q(:a), M.q(:b))
|
742
742
|
|
743
743
|
assert_equal e, m
|
744
744
|
end
|
745
745
|
|
746
746
|
def test_unary_minus
|
747
|
-
assert_equal M::Not.new(M.
|
747
|
+
assert_equal M::Not.new(M.q(:a)), s{ -q(:a) }
|
748
748
|
end
|
749
749
|
|
750
750
|
def test_rchevron
|
751
|
-
assert_equal M::Sibling.new(M.
|
751
|
+
assert_equal M::Sibling.new(M.q(:a), M.q(:b)), s{ q(:a) >> q(:b) }
|
752
752
|
end
|
753
753
|
|
754
754
|
def test_greedy_eh
|
755
|
-
refute_operator s{
|
755
|
+
refute_operator s{ q(:a) }, :greedy?
|
756
756
|
end
|
757
757
|
|
758
758
|
def test_inspect
|
759
|
-
assert_inspect "q(:a)", s{
|
759
|
+
assert_inspect "q(:a)", s{ q(:a) }
|
760
760
|
end
|
761
761
|
|
762
762
|
def test_pretty_print
|
763
|
-
assert_pretty_print "q(:a)", s{
|
763
|
+
assert_pretty_print "q(:a)", s{ q(:a) }
|
764
764
|
end
|
765
765
|
end # class TestSexpMatcher
|
766
766
|
|
@@ -790,11 +790,11 @@ class TestWild < MatcherTestCase
|
|
790
790
|
def test_wild_search # TODO: possibly remove
|
791
791
|
sexp = CLASS_SEXP.dup
|
792
792
|
|
793
|
-
assert_search 1, s(:add, :a, :b), s{
|
794
|
-
assert_search 1, sexp, s{
|
795
|
-
assert_search 2, sexp, s{
|
796
|
-
assert_search 1, s(:a, s()), s{
|
797
|
-
assert_search 1, s(:a, :b, :c), s{
|
793
|
+
assert_search 1, s(:add, :a, :b), s{ q(:add, _, :b) }
|
794
|
+
assert_search 1, sexp, s{ q(:defn, :bar, _, _) }
|
795
|
+
assert_search 2, sexp, s{ q(:defn, _, _, q(_, :a, :b) ) }
|
796
|
+
assert_search 1, s(:a, s()), s{ q(:a, _) }
|
797
|
+
assert_search 1, s(:a, :b, :c), s{ q(_, _, _) }
|
798
798
|
assert_search 7, sexp, s{ _ }
|
799
799
|
end
|
800
800
|
end
|
@@ -815,8 +815,8 @@ class TestRemaining < MatcherTestCase
|
|
815
815
|
def test_remaining_satisfy_eh # TODO: possibly remove
|
816
816
|
assert_satisfy s{ ___ }, s(:a)
|
817
817
|
assert_satisfy s{ ___ }, s(:a, :b, :c)
|
818
|
-
assert_satisfy s{
|
819
|
-
refute_satisfy s{
|
818
|
+
assert_satisfy s{ q(:x, ___ ) }, s(:x, :y)
|
819
|
+
refute_satisfy s{ q(:y, ___ ) }, s(:x, :y)
|
820
820
|
end
|
821
821
|
|
822
822
|
def test_greedy
|
@@ -826,7 +826,7 @@ end
|
|
826
826
|
|
827
827
|
class TestAny < MatcherTestCase
|
828
828
|
def matcher
|
829
|
-
s{
|
829
|
+
s{ q(:a) | q(:c) }
|
830
830
|
end
|
831
831
|
|
832
832
|
def inspect_str
|
@@ -838,26 +838,26 @@ class TestAny < MatcherTestCase
|
|
838
838
|
end
|
839
839
|
|
840
840
|
def test_any_search # TODO: possibly remove
|
841
|
-
assert_search 2, s(:foo, s(:a), s(:b)), s{
|
842
|
-
assert_search 1, s(:foo, s(:a), s(:b)), s{ any(
|
841
|
+
assert_search 2, s(:foo, s(:a), s(:b)), s{ q(any(:a, :b)) }
|
842
|
+
assert_search 1, s(:foo, s(:a), s(:b)), s{ any( q(:a), q(:c)) }
|
843
843
|
end
|
844
844
|
|
845
845
|
def test_or_satisfy_eh # TODO: possibly remove
|
846
|
-
assert_satisfy s{
|
847
|
-
refute_satisfy s{
|
846
|
+
assert_satisfy s{ q(:a) | q(:b) }, s(:a)
|
847
|
+
refute_satisfy s{ q(:a) | q(:b) }, s(:c)
|
848
848
|
end
|
849
849
|
|
850
850
|
def test_or_search # TODO: possibly remove
|
851
851
|
sexp = CLASS_SEXP.dup
|
852
852
|
|
853
|
-
assert_search 2, s(:a, s(:b, :c), s(:b, :d)), s{
|
854
|
-
assert_search 2, sexp, s{
|
853
|
+
assert_search 2, s(:a, s(:b, :c), s(:b, :d)), s{ q(:b, :c) | q(:b, :d) }
|
854
|
+
assert_search 2, sexp, s{ q(:add, :a, :b) | q(:defn, :bar, _, _) }
|
855
855
|
end
|
856
856
|
end
|
857
857
|
|
858
858
|
class TestAll < MatcherTestCase
|
859
859
|
def matcher
|
860
|
-
s{
|
860
|
+
s{ q(:a) & q(:a) }
|
861
861
|
end
|
862
862
|
|
863
863
|
def inspect_str
|
@@ -869,14 +869,14 @@ class TestAll < MatcherTestCase
|
|
869
869
|
end
|
870
870
|
|
871
871
|
def test_and_satisfy_eh # TODO: possibly remove
|
872
|
-
refute_satisfy s{
|
873
|
-
assert_satisfy s{
|
872
|
+
refute_satisfy s{ q(:a) & q(:b) }, s(:a)
|
873
|
+
assert_satisfy s{ q(:a) & q(atom) }, s(:a)
|
874
874
|
end
|
875
875
|
end
|
876
876
|
|
877
877
|
class TestNot < MatcherTestCase
|
878
878
|
def matcher
|
879
|
-
s{ not?
|
879
|
+
s{ not? q(:b) } # TODO: test unary minus
|
880
880
|
end
|
881
881
|
|
882
882
|
def inspect_str
|
@@ -889,16 +889,16 @@ class TestNot < MatcherTestCase
|
|
889
889
|
|
890
890
|
def test_not_satisfy_eh # TODO: possibly remove
|
891
891
|
refute_satisfy s{ -_ }, s(:a)
|
892
|
-
assert_satisfy s{ -
|
893
|
-
assert_satisfy s{ not?(
|
894
|
-
refute_satisfy s{ -
|
895
|
-
assert_satisfy s{
|
892
|
+
assert_satisfy s{ -q(:b) }, s(:a)
|
893
|
+
assert_satisfy s{ not?(q(:b)) }, s(:a)
|
894
|
+
refute_satisfy s{ -q(atom) }, s(:a)
|
895
|
+
assert_satisfy s{ q(not?(:b)) }, s(:a)
|
896
896
|
end
|
897
897
|
end
|
898
898
|
|
899
899
|
class TestChild < MatcherTestCase
|
900
900
|
def matcher
|
901
|
-
s{ child(
|
901
|
+
s{ child(q(:a)) }
|
902
902
|
end
|
903
903
|
|
904
904
|
def sexp
|
@@ -916,8 +916,8 @@ class TestChild < MatcherTestCase
|
|
916
916
|
def test_child_search # TODO: possibly remove
|
917
917
|
sexp = CLASS_SEXP.dup
|
918
918
|
|
919
|
-
assert_search 1, sexp, s{
|
920
|
-
assert_search 1, sexp, s{
|
919
|
+
assert_search 1, sexp, s{ q(:class, :cake, _, _, child( q(:sub, :a, :b) ) ) }
|
920
|
+
assert_search 1, sexp, s{ q(:class, :cake, _, _, child(include(:a))) }
|
921
921
|
end
|
922
922
|
|
923
923
|
def test_satisfy_eh_by_child
|
@@ -954,15 +954,15 @@ class TestAtom < MatcherTestCase
|
|
954
954
|
def test_atom_search # TODO: possibly remove
|
955
955
|
sexp = CLASS_SEXP.dup
|
956
956
|
|
957
|
-
assert_search 1, s(:add, :a, :b), s{
|
958
|
-
assert_search 2, sexp, s{
|
959
|
-
assert_search 0, s(:a, s()), s{
|
957
|
+
assert_search 1, s(:add, :a, :b), s{ q(:add, atom, :b) }
|
958
|
+
assert_search 2, sexp, s{ q(:defn, atom, _, q(atom, :a, :b) ) }
|
959
|
+
assert_search 0, s(:a, s()), s{ q(:a, atom) }
|
960
960
|
end
|
961
961
|
end
|
962
962
|
|
963
963
|
class TestPattern < MatcherTestCase
|
964
964
|
def matcher
|
965
|
-
s{
|
965
|
+
s{ q(:a, m(/a/)) }
|
966
966
|
end
|
967
967
|
|
968
968
|
def sexp
|
@@ -984,15 +984,15 @@ class TestPattern < MatcherTestCase
|
|
984
984
|
def test_pattern_search # TODO: possibly remove
|
985
985
|
sexp = CLASS_SEXP.dup
|
986
986
|
|
987
|
-
assert_search 2, sexp, s{
|
987
|
+
assert_search 2, sexp, s{ q(m(/\w{3}/), :a, :b) }
|
988
988
|
|
989
989
|
assert_search 0, s(:a), s{ m(/\w/) }
|
990
|
-
assert_search 1, s(:a), s{
|
990
|
+
assert_search 1, s(:a), s{ q(m(/\w/)) }
|
991
991
|
assert_search 0, s(:a), s{ m(/\w/,/\d/) }
|
992
|
-
assert_search 1, s(:a), s{
|
992
|
+
assert_search 1, s(:a), s{ q(m(/\w/,/\d/)) }
|
993
993
|
|
994
994
|
assert_search 0, s(:tests, s(s(:test_a), s(:test_b))), s{ m(/test_\w/) }
|
995
|
-
assert_search 2, s(:tests, s(s(:test_a), s(:test_b))), s{
|
995
|
+
assert_search 2, s(:tests, s(s(:test_a), s(:test_b))), s{ q(m(/test_\w/)) }
|
996
996
|
end
|
997
997
|
end
|
998
998
|
|
@@ -1021,7 +1021,7 @@ class TestInclude < MatcherTestCase
|
|
1021
1021
|
end
|
1022
1022
|
|
1023
1023
|
def matcher
|
1024
|
-
s{ include(
|
1024
|
+
s{ include(q(:a)) }
|
1025
1025
|
end
|
1026
1026
|
|
1027
1027
|
def inspect_str
|
@@ -1033,9 +1033,9 @@ class TestInclude < MatcherTestCase
|
|
1033
1033
|
|
1034
1034
|
assert_search 1, s(:add, :a, :b), s{ include(:a) }
|
1035
1035
|
assert_search 1, sexp, s{ include(:bar) }
|
1036
|
-
assert_search 2, sexp, s{
|
1036
|
+
assert_search 2, sexp, s{ q(:defn, atom, _, include(:a)) }
|
1037
1037
|
assert_search 2, sexp, s{ include(:a) }
|
1038
|
-
assert_search 0, s(:a, s(:b, s(:c))), s{
|
1038
|
+
assert_search 0, s(:a, s(:b, s(:c))), s{ q(:a, include(:c)) }
|
1039
1039
|
end
|
1040
1040
|
end
|
1041
1041
|
|
@@ -1045,7 +1045,7 @@ class TestSibling < MatcherTestCase
|
|
1045
1045
|
end
|
1046
1046
|
|
1047
1047
|
def matcher
|
1048
|
-
s{
|
1048
|
+
s{ q(:a) >> q(:b) }
|
1049
1049
|
end
|
1050
1050
|
|
1051
1051
|
def inspect_str
|
@@ -1053,15 +1053,15 @@ class TestSibling < MatcherTestCase
|
|
1053
1053
|
end
|
1054
1054
|
|
1055
1055
|
def test_pretty_print_distance
|
1056
|
-
m = s{ M::Sibling.new(
|
1056
|
+
m = s{ M::Sibling.new(q(:a), q(:b), 3) } # maybe q(:a) << q(:b) << 3 ?
|
1057
1057
|
assert_pretty_print "sibling(q(:a), q(:b), 3)", m
|
1058
1058
|
end
|
1059
1059
|
|
1060
1060
|
def test_sibling_satisfy_eh # TODO: possibly remove
|
1061
|
-
a_a = s{
|
1062
|
-
a_b = s{
|
1063
|
-
a_c = s{
|
1064
|
-
c_a = s{
|
1061
|
+
a_a = s{ q(:a) >> q(:a) }
|
1062
|
+
a_b = s{ q(:a) >> q(:b) }
|
1063
|
+
a_c = s{ q(:a) >> q(:c) }
|
1064
|
+
c_a = s{ q(:c) >> q(:a) }
|
1065
1065
|
|
1066
1066
|
assert_satisfy a_b, s(s(:a), s(:b))
|
1067
1067
|
assert_satisfy a_b, s(s(:a), s(:b), s(:c))
|
@@ -1093,8 +1093,8 @@ class TestMatchCollection < SexpTestCase
|
|
1093
1093
|
s(:defn, :foo, s(:args), s(:add, :a, :b)),
|
1094
1094
|
s(:defn, :bar, s(:args), s(:sub, :a, :b)))
|
1095
1095
|
|
1096
|
-
res = sexp / s{
|
1097
|
-
act = res / s{
|
1096
|
+
res = sexp / s{ q(:class, atom, _, ___) } # sexp / pat => MC
|
1097
|
+
act = res / s{ q(:defn, atom, ___) } # MC / pat => MC
|
1098
1098
|
|
1099
1099
|
_, _, _, defn1, defn2 = sexp
|
1100
1100
|
|
@@ -1150,8 +1150,43 @@ class TestSexpSearch < SexpTestCase
|
|
1150
1150
|
MR.new sexp.deep_clone, hash
|
1151
1151
|
end
|
1152
1152
|
|
1153
|
+
def test_sexp_hash
|
1154
|
+
s1 = s(:a)
|
1155
|
+
s2 = s(nil)
|
1156
|
+
refute_equal s1.hash, s2.hash
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
def test_matcher_inspect
|
1160
|
+
pat1 = M.parse "(a [m /b/] (c))"
|
1161
|
+
|
1162
|
+
assert_equal "q(:a, m(/b/), q(:c))", pat1.inspect
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
def test_matcher_hash
|
1166
|
+
a = M::Pattern.new(/x/) # M.parse "[m /x/]"
|
1167
|
+
b = M::Atom.new # M.parse "_"
|
1168
|
+
|
1169
|
+
refute_operator a, :eql?, b
|
1170
|
+
refute_equal a.hash, b.hash
|
1171
|
+
|
1172
|
+
h = {}
|
1173
|
+
h[a] = true
|
1174
|
+
refute_operator h, :key?, b
|
1175
|
+
|
1176
|
+
# original problem:
|
1177
|
+
a = M.parse "(call nil assert_equal (true) (call _ [m /include./] _))"
|
1178
|
+
b = M.parse "(call nil assert_equal (true) (call _ _ _))"
|
1179
|
+
|
1180
|
+
refute_operator a, :eql?, b
|
1181
|
+
refute_equal a.hash, b.hash
|
1182
|
+
|
1183
|
+
h = {}
|
1184
|
+
h[a] = true
|
1185
|
+
refute_operator h, :key?, b
|
1186
|
+
end
|
1187
|
+
|
1153
1188
|
def test_slash_simple
|
1154
|
-
act = sexp / s{
|
1189
|
+
act = sexp / s{ q(:class, atom, _, ___) }
|
1155
1190
|
|
1156
1191
|
exp = MC.new
|
1157
1192
|
exp << sexp.deep_clone
|
@@ -1160,7 +1195,7 @@ class TestSexpSearch < SexpTestCase
|
|
1160
1195
|
end
|
1161
1196
|
|
1162
1197
|
def test_slash_subsexp
|
1163
|
-
act = sexp / s{
|
1198
|
+
act = sexp / s{ q(:defn, atom, ___) }
|
1164
1199
|
|
1165
1200
|
exp = MC.new
|
1166
1201
|
exp << s(:defn, :foo, s(:args), s(:add, :a, :b))
|
@@ -1170,7 +1205,7 @@ class TestSexpSearch < SexpTestCase
|
|
1170
1205
|
end
|
1171
1206
|
|
1172
1207
|
def test_slash_data
|
1173
|
-
pat = s{
|
1208
|
+
pat = s{ q(:defn, m(/^test_.+/), ___ ) }
|
1174
1209
|
|
1175
1210
|
_, _, (_klass, _, _, _setup, t1, t2, t3) = TestUseCase.sexp.deep_clone
|
1176
1211
|
exp = [t1, t2, t3]
|
@@ -1199,27 +1234,27 @@ class TestSexpSearch < SexpTestCase
|
|
1199
1234
|
assert_search 0, sexp, :class # non-pattern should raise
|
1200
1235
|
end
|
1201
1236
|
|
1202
|
-
assert_search 0, sexp, s{
|
1203
|
-
assert_search 1, sexp, s{
|
1204
|
-
assert_search 1, s(:a, s(:b, s(:c))), s{
|
1205
|
-
assert_search 0, s(:a, s(:b, s(:c))), s{
|
1206
|
-
assert_search 1, sexp, s{
|
1237
|
+
assert_search 0, sexp, s{ q(:class) }
|
1238
|
+
assert_search 1, sexp, s{ q(:add, :a, :b) }
|
1239
|
+
assert_search 1, s(:a, s(:b, s(:c))), s{ q(:b, q(:c)) }
|
1240
|
+
assert_search 0, s(:a, s(:b, s(:c))), s{ q(:a, q(:c)) }
|
1241
|
+
assert_search 1, sexp, s{ q(:defn, :bar, _, q(:sub, :a, :b)) }
|
1207
1242
|
end
|
1208
1243
|
|
1209
1244
|
def test_satisfy_eh_any_capture # TODO: remove
|
1210
1245
|
sexp = s(:add, :a, :b)
|
1211
|
-
assert_satisfy s{ any(
|
1246
|
+
assert_satisfy s{ any(q(:add, :a, :b), q(:sub, :a, :b)) }, sexp
|
1212
1247
|
|
1213
|
-
assert_satisfy s{ any(
|
1248
|
+
assert_satisfy s{ any(q(atom, :a, :b), q(:sub, :a, :b)) }, sexp
|
1214
1249
|
end
|
1215
1250
|
|
1216
1251
|
def test_satisfy_eh_all_capture # TODO: remove
|
1217
1252
|
sexp = s(:add, :a, :b)
|
1218
|
-
assert_satisfy s{ all(
|
1253
|
+
assert_satisfy s{ all(q(_, :a, :b), q(atom, :a, :b)) }, sexp
|
1219
1254
|
|
1220
|
-
assert_satisfy s{ all(
|
1255
|
+
assert_satisfy s{ all(q(_, :a, :b), q(atom, :a, :b)) }, sexp
|
1221
1256
|
|
1222
|
-
assert_search 1, sexp, s{ all(
|
1257
|
+
assert_search 1, sexp, s{ all(q(_, :a, :b), q(atom, :a, :b)) }
|
1223
1258
|
end
|
1224
1259
|
end
|
1225
1260
|
|
@@ -1228,15 +1263,15 @@ class TestSexpPath < Minitest::Test
|
|
1228
1263
|
sexp = s(:a, :b, :c) # s called outside block
|
1229
1264
|
|
1230
1265
|
assert_instance_of Sexp, s{ sexp.deep_clone }
|
1231
|
-
assert_instance_of Sexp::Matcher, s{
|
1232
|
-
assert_instance_of Sexp::Matcher, s{
|
1266
|
+
assert_instance_of Sexp::Matcher, s{ q(:a, :b, :c) }
|
1267
|
+
assert_instance_of Sexp::Matcher, s{ q(:a, atom, :c) }
|
1233
1268
|
end
|
1234
1269
|
end
|
1235
1270
|
|
1236
1271
|
class TestSexpReplaceSexp < SexpTestCase
|
1237
1272
|
def test_replace_sexp
|
1238
1273
|
sexp = s(:a, s(:b), :c)
|
1239
|
-
actual = sexp.replace_sexp(s{
|
1274
|
+
actual = sexp.replace_sexp(s{ q(:b) }) { :b }
|
1240
1275
|
|
1241
1276
|
assert_equal s(:a, :b, :c), actual
|
1242
1277
|
end
|
@@ -1309,7 +1344,7 @@ class TestUseCase < SexpTestCase
|
|
1309
1344
|
end
|
1310
1345
|
|
1311
1346
|
def test_finding_classes_and_methods
|
1312
|
-
res = @sexp / s{
|
1347
|
+
res = @sexp / s{ q(:class, atom, ___ ) }
|
1313
1348
|
|
1314
1349
|
_klass, name, * = res.first
|
1315
1350
|
|
@@ -1321,7 +1356,7 @@ class TestUseCase < SexpTestCase
|
|
1321
1356
|
end
|
1322
1357
|
|
1323
1358
|
def test_finding_empty_test_methods
|
1324
|
-
empty_test = s{
|
1359
|
+
empty_test = s{ q(:defn, m(/^test_.+/), q(:args), q(:nil)) }
|
1325
1360
|
res = @sexp / empty_test
|
1326
1361
|
|
1327
1362
|
_, _, (_klass, _, _, _setup, _t1, t2, _t3) = TestUseCase.sexp.deep_clone
|
@@ -1330,7 +1365,7 @@ class TestUseCase < SexpTestCase
|
|
1330
1365
|
end
|
1331
1366
|
|
1332
1367
|
def test_search_each_finding_duplicate_test_names
|
1333
|
-
pat = s{
|
1368
|
+
pat = s{ q(:defn, m(/^test_.+/), ___ ) }
|
1334
1369
|
counts = Hash.new { |h, k| h[k] = 0 }
|
1335
1370
|
|
1336
1371
|
@sexp.search_each pat do |x|
|
@@ -1343,7 +1378,7 @@ class TestUseCase < SexpTestCase
|
|
1343
1378
|
end
|
1344
1379
|
|
1345
1380
|
def test_finding_duplicate_test_names_via_res
|
1346
|
-
pat = s{
|
1381
|
+
pat = s{ q(:defn, m(/^test_.+/), ___ ) }
|
1347
1382
|
res = @sexp / pat
|
1348
1383
|
counts = Hash.new { |h, k| h[k] = 0 }
|
1349
1384
|
|
@@ -1362,8 +1397,8 @@ class TestUseCase < SexpTestCase
|
|
1362
1397
|
end
|
1363
1398
|
|
1364
1399
|
def test_rewriting_colon2s
|
1365
|
-
colon2 = s{
|
1366
|
-
expected = s{
|
1400
|
+
colon2 = s{ q(:colon2, q(:const, atom), atom) }
|
1401
|
+
expected = s{ q(:const, "Minitest::Test") }
|
1367
1402
|
|
1368
1403
|
new_sexp = @sexp.replace_sexp(colon2) { |r|
|
1369
1404
|
(_, (_, a), b) = r
|
@@ -1388,46 +1423,46 @@ class TestSexpMatchers < SexpTestCase
|
|
1388
1423
|
SEXP = s(:class, :X, nil, s(:defn, :x, s(:args)))
|
1389
1424
|
|
1390
1425
|
def test_match_subset
|
1391
|
-
assert_match s{ child(
|
1392
|
-
assert_match s{ child(
|
1426
|
+
assert_match s{ child(q(:a)) }, s(:blah, s(:blah, s(:a)))
|
1427
|
+
assert_match s{ child(q(:a)) }, s(:a)
|
1393
1428
|
end
|
1394
1429
|
|
1395
1430
|
def test_match_simple
|
1396
|
-
assert_match s{
|
1431
|
+
assert_match s{ q(:lit, _) }, s(:lit, 42)
|
1397
1432
|
end
|
1398
1433
|
|
1399
1434
|
def test_match_mismatch_type
|
1400
|
-
refute_match s{
|
1435
|
+
refute_match s{ q(:xxx, 42) }, s(:lit, 42)
|
1401
1436
|
end
|
1402
1437
|
|
1403
1438
|
def test_match_mismatch_data
|
1404
|
-
refute_match s{
|
1439
|
+
refute_match s{ q(:lit, 24) }, s(:lit, 42)
|
1405
1440
|
end
|
1406
1441
|
|
1407
1442
|
def test_match_mismatch_length_shorter
|
1408
|
-
refute_match s{
|
1443
|
+
refute_match s{ q(:a, :b) }, s(:a, :b, :c)
|
1409
1444
|
end
|
1410
1445
|
|
1411
1446
|
def test_match_mismatch_length_longer
|
1412
|
-
refute_match s{
|
1447
|
+
refute_match s{ q(:a, :b, :c) }, s(:a, :b)
|
1413
1448
|
end
|
1414
1449
|
|
1415
1450
|
def test_match_wild
|
1416
|
-
assert_match s{
|
1451
|
+
assert_match s{ q(:class, _, _, _) }, SEXP
|
1417
1452
|
end
|
1418
1453
|
|
1419
1454
|
def test_match_rest_same_length
|
1420
|
-
assert_match s{
|
1455
|
+
assert_match s{ q(:class, _, _, ___) }, SEXP
|
1421
1456
|
end
|
1422
1457
|
|
1423
1458
|
def test_match_rest_diff_length
|
1424
1459
|
skip_if_strict
|
1425
1460
|
|
1426
|
-
assert_match s{
|
1461
|
+
assert_match s{ q(:class, ___) }, SEXP
|
1427
1462
|
end
|
1428
1463
|
|
1429
1464
|
def test_match_reversed
|
1430
|
-
assert_match SEXP, s{
|
1465
|
+
assert_match SEXP, s{ q(:class, _, _, ___) }
|
1431
1466
|
end
|
1432
1467
|
|
1433
1468
|
def assert_match_case pat, data
|
@@ -1440,7 +1475,7 @@ class TestSexpMatchers < SexpTestCase
|
|
1440
1475
|
end
|
1441
1476
|
|
1442
1477
|
def test_match_case
|
1443
|
-
assert_match_case s{
|
1478
|
+
assert_match_case s{ q(:class, _, _, ___) }, SEXP
|
1444
1479
|
end
|
1445
1480
|
|
1446
1481
|
# NOTE: eqt is =~ (equal-tilde)
|
@@ -1498,12 +1533,12 @@ class TestSexpMatchers < SexpTestCase
|
|
1498
1533
|
l_cls = s(:class, :X, nil,
|
1499
1534
|
s(:something_in_between),
|
1500
1535
|
s(:cdecl, :Y, s(:hash, s(:lit, :a), s(:lit, 1))))
|
1501
|
-
p_cls1 = s{
|
1502
|
-
p_cls2 = s{
|
1536
|
+
p_cls1 = s{ q(:class, ___) & include(q(:cdecl, _, q(:hash, ___))) }
|
1537
|
+
p_cls2 = s{ q(:class, _, _, q(:cdecl, _, q(:hash, ___))) }
|
1503
1538
|
|
1504
1539
|
x, o = true, false
|
1505
|
-
TestMatcherDirectMatch = cmt x, x, o, x, l_a, s{
|
1506
|
-
TestMatcherSubtree = cmt x, x, o, x, l_abc, s{
|
1540
|
+
TestMatcherDirectMatch = cmt x, x, o, x, l_a, s{ q(:a) }
|
1541
|
+
TestMatcherSubtree = cmt x, x, o, x, l_abc, s{ q(:c) }
|
1507
1542
|
TestMatcherSubtreeType = cmt x, x, o, x, l_abc, s{ t(:c) }
|
1508
1543
|
TestMatcherDisparateSubtree = cmt x, x, o, x, l_cls, p_cls1
|
1509
1544
|
TestMatcherDisparateSubtree2 = cmt o, o, o, o, l_cls, p_cls2 # TODO: make pass
|
@@ -1539,18 +1574,29 @@ class TestSexpMatcherParser < Minitest::Test
|
|
1539
1574
|
lambda { s(&b) }
|
1540
1575
|
end
|
1541
1576
|
|
1577
|
+
re = /(?-mix:\Aa\Z)|(?-mix:\Ab\Z)|(?-mix:\Ac\Z)/ # [m a b c]
|
1578
|
+
|
1542
1579
|
test_parse "nothing", nil, ""
|
1543
1580
|
test_parse "nil", delay{ nil }, "nil"
|
1544
|
-
test_parse "empty", delay{
|
1545
|
-
test_parse "simple", delay{
|
1546
|
-
test_parse "number", delay{
|
1547
|
-
test_parse "string", delay{
|
1548
|
-
test_parse "compound", delay{
|
1549
|
-
test_parse "complex", delay{
|
1550
|
-
test_parse "type", delay{
|
1551
|
-
test_parse "match", delay{
|
1552
|
-
test_parse "not_atom", delay{
|
1581
|
+
test_parse "empty", delay{ q() }, "()"
|
1582
|
+
test_parse "simple", delay{ q(:a) }, "(a)"
|
1583
|
+
test_parse "number", delay{ q(:a, 42) }, "(a 42)"
|
1584
|
+
test_parse "string", delay{ q(:a, "s") }, "(a \"s\")"
|
1585
|
+
test_parse "compound", delay{ q(:b) }, "(a) (b)"
|
1586
|
+
test_parse "complex", delay{ q(:a, _, q(:b, :cde), ___) }, "(a _ (b cde) ___)"
|
1587
|
+
test_parse "type", delay{ q(:a, t(:b)) }, "(a [t b])"
|
1588
|
+
test_parse "match", delay{ q(:a, m(/b/)) }, "(a [m /b/])"
|
1589
|
+
test_parse "not_atom", delay{ q(:atom) }, "(atom)"
|
1553
1590
|
test_parse "atom", delay{ atom }, "[atom]"
|
1591
|
+
test_parse "match_n", delay{ m(re) }, "[m a b c]"
|
1592
|
+
test_parse "ne", delay{ q(:call, _, :!=, _) }, "(call _ != _)"
|
1593
|
+
test_parse "eq", delay{ q(:call, _, :==, _) }, "(call _ == _)"
|
1594
|
+
test_parse "not", delay{ q(:call, _, :"!") }, "(call _ !)"
|
1595
|
+
test_parse "eh", delay{ q(:call, _, :include?, _) }, "(call _ include? _)"
|
1596
|
+
test_parse "under", delay{ q(:call, nil, :_, _) }, "(call nil :_ _)"
|
1597
|
+
test_parse "sym_nil", delay{ q(:call, nil, :nil, _) }, "(call nil :nil _)"
|
1598
|
+
# M::Not.new(M.q(:a)), s{ not?(q(:a)) }
|
1599
|
+
test_parse "not?", delay{ not?(m(/^_$/)) }, "[not? [m /^_$/]]"
|
1554
1600
|
|
1555
1601
|
test_bad_parse "open_sexp", "(a"
|
1556
1602
|
test_bad_parse "closed_sexp", "a)"
|