sexpistol 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sexpistol/sexpistol.rb +20 -10
- data/sexpistol.gemspec +1 -1
- data/test/unit/to_sexp_test.rb +24 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/sexpistol/sexpistol.rb
CHANGED
@@ -118,20 +118,30 @@ class Sexpistol
|
|
118
118
|
|
119
119
|
# Convert a set of nested arrays back into an S-Expression
|
120
120
|
def to_sexp( data )
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
if(item === false)
|
126
|
-
"#f"
|
127
|
-
elsif(item === true)
|
128
|
-
"#t"
|
121
|
+
if( data.is_a?(Array))
|
122
|
+
mapped = data.map do |item|
|
123
|
+
if( item.is_a?(Array))
|
124
|
+
to_sexp(item)
|
129
125
|
else
|
130
|
-
item
|
126
|
+
if(item === false)
|
127
|
+
"#f"
|
128
|
+
elsif(item === true)
|
129
|
+
"#t"
|
130
|
+
else
|
131
|
+
item.to_s
|
132
|
+
end
|
131
133
|
end
|
132
134
|
end
|
135
|
+
"(" + mapped.join(" ") + ")"
|
136
|
+
else
|
137
|
+
if(data === false)
|
138
|
+
"#f"
|
139
|
+
elsif(data === true)
|
140
|
+
"#t"
|
141
|
+
else
|
142
|
+
data.to_s
|
143
|
+
end
|
133
144
|
end
|
134
|
-
"(" + mapped.join(" ") + ")"
|
135
145
|
end
|
136
146
|
|
137
147
|
private
|
data/sexpistol.gemspec
CHANGED
data/test/unit/to_sexp_test.rb
CHANGED
@@ -23,5 +23,29 @@ class ToSexpTest < Test::Unit::TestCase
|
|
23
23
|
sexp = @parser.to_sexp(ast)
|
24
24
|
assert_equal "(#t (#f (#t #f)))", sexp
|
25
25
|
end
|
26
|
+
|
27
|
+
test "when not passed array to_sexp should print value (integer)" do
|
28
|
+
ast = 1
|
29
|
+
sexp = @parser.to_sexp(ast)
|
30
|
+
assert_equal "1", sexp
|
31
|
+
end
|
32
|
+
|
33
|
+
test "when not passed array to_sexp should print value (string)" do
|
34
|
+
ast = "test"
|
35
|
+
sexp = @parser.to_sexp(ast)
|
36
|
+
assert_equal "test", sexp
|
37
|
+
end
|
38
|
+
|
39
|
+
test "when not passed array to_sexp should print value (symbol)" do
|
40
|
+
ast = :test
|
41
|
+
sexp = @parser.to_sexp(ast)
|
42
|
+
assert_equal "test", sexp
|
43
|
+
end
|
44
|
+
|
45
|
+
test "lists passed to to_sexp should have not extraneous spaces" do
|
46
|
+
ast = [1, 2, 3]
|
47
|
+
sexp = @parser.to_sexp(ast)
|
48
|
+
assert_equal "(1 2 3)", sexp
|
49
|
+
end
|
26
50
|
|
27
51
|
end
|