Skip to content

Commit 0c5041e

Browse files
committed
Update specs
1 parent 095497d commit 0c5041e

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

spec/generate_spec_from_json.cr

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def inspect_hash(hash)
77
else
88
pairs = hash.map do |key, value|
99
if key == "lambda"
10-
"#{key.inspect} => #{((value as Hash(String, JSON::Type))["ruby"] as String).gsub(/^proc \{ (?:(?:\|)([^|]+)(?:\|))?/){|m, p| "->(#{p[1]? ? "#{p[1]} : String" : ""}){"}.gsub(/1/, "1; $calls.to_s").gsub(/false/, "false.to_s")}"
10+
"#{key.inspect} => #{((value.as(Hash(String, JSON::Type)))["ruby"].as String).gsub(/^proc \{ (?:(?:\|)([^|]+)(?:\|))?/){|m, p| "->(#{p[1]? ? "#{p[1]} : String" : ""}){"}.gsub(/\$/, "Global.").gsub(/1/, "1; Global.calls.to_s").gsub(/false/, "false.to_s")}"
1111
else
1212
"#{key.inspect} => #{inspect_hash value}"
1313
end
@@ -19,7 +19,7 @@ def inspect_hash(hash)
1919
if hash.empty?
2020
"[] of String"
2121
else
22-
vals = hash.map{|x| inspect_hash(x) as String}
22+
vals = hash.map{|x| inspect_hash(x).as String}
2323
"[#{vals.join ","}]"
2424
end
2525
else
@@ -29,11 +29,11 @@ end
2929

3030
filename = ARGV[0]
3131

32-
file = (JSON.parse File.read "./spec/mustache-spec/specs/#{filename}").as_h as Hash(String, JSON::Type)
32+
file = (JSON.parse File.read "./spec/mustache-spec/specs/#{filename}").as_h.as Hash(String, JSON::Type)
3333

3434
puts "describe #{filename.inspect} do"
35-
(file["tests"] as Array(JSON::Type)).each do |test|
36-
test = test as Hash(String, JSON::Type)
35+
(file["tests"].as Array(JSON::Type)).each do |test|
36+
test = test.as Hash(String, JSON::Type)
3737

3838
puts " it #{test["desc"].inspect} do"
3939
puts " template = Crustache.parse #{test["template"].inspect}"
@@ -43,7 +43,7 @@ puts "describe #{filename.inspect} do"
4343

4444
puts " fs = Crustache::HashFileSystem.new"
4545
if test.has_key?("partials")
46-
(test["partials"] as Hash(String, JSON::Type)).each do |name, tmpl|
46+
(test["partials"].as Hash(String, JSON::Type)).each do |name, tmpl|
4747
puts " fs.register #{name.inspect}, Crustache.parse #{tmpl.inspect}"
4848
end
4949
end

spec/mustache_spec.cr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
require "./spec_helper"
22

33
# for ~lambda.json test
4-
$calls = 0
4+
class Global
5+
@@calls = 0
6+
7+
def self.calls
8+
@@calls
9+
end
10+
11+
def self.calls=(value)
12+
@@calls = value
13+
end
14+
end
515

616
{% for name in %w(interpolation sections inverted delimiters comments partials ~lambdas) %}
717
{{ run "./generate_spec_from_json", "#{name.id}.json" }}

0 commit comments

Comments
 (0)