sorcerer 0.3.5 → 0.3.6
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.
- data/lib/sorcerer/subexpression.rb +8 -1
- data/lib/sorcerer/version.rb +1 -1
- data/test/sorcerer/subexpression_test.rb +61 -2
- metadata +2 -2
@@ -32,7 +32,9 @@ module Sorcerer
|
|
32
32
|
|
33
33
|
def tagged_sexp(sexp)
|
34
34
|
case sexp.first
|
35
|
-
when :var_ref
|
35
|
+
when :var_ref
|
36
|
+
list_sexp(sexp)
|
37
|
+
when :vcall, :binary, :array, :hash, :unary, :defined
|
36
38
|
@result << sexp
|
37
39
|
list_sexp(sexp)
|
38
40
|
when :aref
|
@@ -43,6 +45,11 @@ module Sorcerer
|
|
43
45
|
when :call, :method_add_block, :method_add_arg
|
44
46
|
@result << sexp
|
45
47
|
method_sexp(sexp)
|
48
|
+
when :@kw
|
49
|
+
# ignore
|
50
|
+
when :zsuper, :super
|
51
|
+
@result << sexp
|
52
|
+
list_sexp(sexp)
|
46
53
|
else
|
47
54
|
list_sexp(sexp)
|
48
55
|
end
|
data/lib/sorcerer/version.rb
CHANGED
@@ -61,8 +61,16 @@ class SubexpressionTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_hash_literal
|
64
|
-
assert_subexpressions "{ :a => aa,
|
65
|
-
"{ :a => aa,
|
64
|
+
assert_subexpressions "{ :a => aa, b => bb }", [
|
65
|
+
"{ :a => aa, b => bb }",
|
66
|
+
"aa",
|
67
|
+
"b",
|
68
|
+
"bb",
|
69
|
+
]
|
70
|
+
assert_subexpressions "{ a: aa, b: bb }", [
|
71
|
+
"{ a: aa, b: bb }",
|
72
|
+
"aa",
|
73
|
+
"bb",
|
66
74
|
]
|
67
75
|
end
|
68
76
|
|
@@ -70,6 +78,10 @@ class SubexpressionTest < Test::Unit::TestCase
|
|
70
78
|
assert_subexpressions "a =~ /r/", ["a =~ /r/", "a"]
|
71
79
|
end
|
72
80
|
|
81
|
+
def test_defined_is_not_omitted
|
82
|
+
assert_subexpressions "defined?(a)", ["defined?(a)", "a"]
|
83
|
+
end
|
84
|
+
|
73
85
|
def test_complex_expression
|
74
86
|
assert_subexpressions "o.f(a+b, c*d, x.y, z(k, 2, 3)) { xx }", [
|
75
87
|
"o.f(a + b, c * d, x.y, z(k, 2, 3)) { xx }",
|
@@ -81,4 +93,51 @@ class SubexpressionTest < Test::Unit::TestCase
|
|
81
93
|
]
|
82
94
|
end
|
83
95
|
|
96
|
+
def test_numeric_literals_are_omitted
|
97
|
+
assert_subexpressions "a+1", ["a + 1", "a"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_boolean_literals_are_omitted
|
101
|
+
assert_subexpressions "a||true||false", [
|
102
|
+
"a || true || false",
|
103
|
+
"a || true",
|
104
|
+
"a",
|
105
|
+
]
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_nil_literals_are_omitted
|
109
|
+
assert_subexpressions "a || nil", [
|
110
|
+
"a || nil",
|
111
|
+
"a",
|
112
|
+
]
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_symbols_literals_are_omitted
|
116
|
+
assert_subexpressions "a || :x", [
|
117
|
+
"a || :x",
|
118
|
+
"a",
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_string_literals_are_omitted
|
123
|
+
assert_subexpressions "a || 'x'", [
|
124
|
+
"a || \"x\"",
|
125
|
+
"a",
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_super_is_not_omitted
|
130
|
+
assert_subexpressions "a || super", [
|
131
|
+
"a || super",
|
132
|
+
"a",
|
133
|
+
"super",
|
134
|
+
]
|
135
|
+
assert_subexpressions "a || super(b)", [
|
136
|
+
"a || super(b)",
|
137
|
+
"a",
|
138
|
+
"super(b)",
|
139
|
+
"b",
|
140
|
+
]
|
141
|
+
end
|
142
|
+
|
84
143
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorcerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Generate the original Ruby source from a Ripper-style abstract syntax
|
15
15
|
tree.
|