Skip to content

Commit b1329a2

Browse files
authored
Merge pull request #121 from softmoth/json-code-tag
Fix Rakefile to add __tag__: code for ~lambda test data
2 parents 86fe766 + 42ac090 commit b1329a2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Rakefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ require 'json'
22
require 'yaml'
33

44
# Our custom YAML tags must retain their magic.
5-
%w[ code ].each do |tag|
6-
YAML::add_builtin_type(tag) { |_,val| val.merge(:__tag__ => tag) }
5+
class TaggedMap < Hash
6+
yaml_tag '!code'
7+
def init_with(psych_coder)
8+
self.replace({:__tag__ => 'code'}.merge(psych_coder.map))
9+
end
710
end
811

12+
YAML::add_tag('code', TaggedMap)
13+
914
desc 'Build all alternate versions of the specs.'
1015
multitask :build => [ 'build:json' ]
1116

specs/~lambdas.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"desc": "A lambda's return value should be interpolated.",
88
"data": {
99
"lambda": {
10+
"__tag__": "code",
1011
"ruby": "proc { \"world\" }",
1112
"raku": "sub { \"world\" }",
1213
"perl": "sub { \"world\" }",
@@ -26,6 +27,7 @@
2627
"data": {
2728
"planet": "world",
2829
"lambda": {
30+
"__tag__": "code",
2931
"ruby": "proc { \"{{planet}}\" }",
3032
"raku": "sub { q+{{planet}}+ }",
3133
"perl": "sub { \"{{planet}}\" }",
@@ -45,6 +47,7 @@
4547
"data": {
4648
"planet": "world",
4749
"lambda": {
50+
"__tag__": "code",
4851
"ruby": "proc { \"|planet| => {{planet}}\" }",
4952
"raku": "sub { q+|planet| => {{planet}}+ }",
5053
"perl": "sub { \"|planet| => {{planet}}\" }",
@@ -63,6 +66,7 @@
6366
"desc": "Interpolated lambdas should not be cached.",
6467
"data": {
6568
"lambda": {
69+
"__tag__": "code",
6670
"ruby": "proc { $calls ||= 0; $calls += 1 }",
6771
"raku": "sub { state $calls += 1 }",
6872
"perl": "sub { no strict; $calls += 1 }",
@@ -81,6 +85,7 @@
8185
"desc": "Lambda results should be appropriately escaped.",
8286
"data": {
8387
"lambda": {
88+
"__tag__": "code",
8489
"ruby": "proc { \">\" }",
8590
"raku": "sub { \">\" }",
8691
"perl": "sub { \">\" }",
@@ -100,6 +105,7 @@
100105
"data": {
101106
"x": "Error!",
102107
"lambda": {
108+
"__tag__": "code",
103109
"ruby": "proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }",
104110
"raku": "sub { $^section eq q+{{x}}+ ?? \"yes\" !! \"no\" }",
105111
"perl": "sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }",
@@ -119,6 +125,7 @@
119125
"data": {
120126
"planet": "Earth",
121127
"lambda": {
128+
"__tag__": "code",
122129
"ruby": "proc { |text| \"#{text}{{planet}}#{text}\" }",
123130
"raku": "sub { $^section ~ q+{{planet}}+ ~ $^section }",
124131
"perl": "sub { $_[0] . \"{{planet}}\" . $_[0] }",
@@ -138,6 +145,7 @@
138145
"data": {
139146
"planet": "Earth",
140147
"lambda": {
148+
"__tag__": "code",
141149
"ruby": "proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }",
142150
"raku": "sub { $^section ~ q+{{planet}} => |planet|+ ~ $^section }",
143151
"perl": "sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }",
@@ -156,6 +164,7 @@
156164
"desc": "Lambdas used for sections should not be cached.",
157165
"data": {
158166
"lambda": {
167+
"__tag__": "code",
159168
"ruby": "proc { |text| \"__#{text}__\" }",
160169
"raku": "sub { \"__\" ~ $^section ~ \"__\" }",
161170
"perl": "sub { \"__\" . $_[0] . \"__\" }",
@@ -175,6 +184,7 @@
175184
"data": {
176185
"static": "static",
177186
"lambda": {
187+
"__tag__": "code",
178188
"ruby": "proc { |text| false }",
179189
"raku": "sub { 0 }",
180190
"perl": "sub { 0 }",

0 commit comments

Comments
 (0)