Skip to content

Commit 7c9eac8

Browse files
committed
Prepare new hash symbols implementation
1 parent ab1dacb commit 7c9eac8

File tree

3 files changed

+157
-90
lines changed

3 files changed

+157
-90
lines changed

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ def ws(obj) puts Wirb::Tokenizer.run(obj.inspect).map{|*x| x.inspect + ','}*$/ e
8989

9090
def spaced_hashes?
9191
RUBY_VERSION >= "3.4.0"
92+
end
93+
94+
def symbol_hash_keys?
95+
RUBY_VERSION >= "3.4.0"
9296
end

spec/tokenizer_hash_spec.rb

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,94 @@
1515
].compact
1616
end
1717

18-
# FIXME 3.4 symbol hash keys
19-
# please do check({:hallo => {1=>Set[2,3,4]}})
20-
# tokens.should be_like [
21-
# [:open_hash, "{"],
22-
# [:symbol_prefix, ":"],
23-
# [:symbol, "hallo"],
24-
# [:refers, "=>"],
25-
# [:open_hash, "{"],
26-
# [:number, "1"],
27-
# ([:whitespace, " "] if spaced_hashes?),
28-
# [:refers, "=>"],
29-
# ([:whitespace, " "] if spaced_hashes?),
30-
# [:open_object, "#<"],
31-
# [:object_class, "Set"],
32-
# [:object_description_prefix, ":"],
33-
# [:whitespace, " "],
34-
# [:open_set, "{"],
35-
# [:number, /\d+/],
36-
# [:comma, ","],
37-
# [:whitespace, " "],
38-
# [:number, /\d+/],
39-
# [:comma, ","],
40-
# [:whitespace, " "],
41-
# [:number, /\d+/],
42-
# [:close_set, "}"],
43-
# [:close_object, ">"],
44-
# [:close_hash, "}"],
45-
# [:close_hash, "}"],
46-
# ].compact
47-
# end
18+
please do check({:"simplekey" => :value})
19+
if symbol_hash_keys?
20+
tokens.should == [
21+
[:open_hash, "{"],
22+
[:symbol, "simplekey"],
23+
[:symbol_prefix, ":"],
24+
[:whitespace, " "],
25+
[:symbol_prefix, ":"],
26+
[:symbol, "value"],
27+
[:close_hash, "}"],
28+
]
29+
else
30+
tokens.should == [
31+
[:open_hash, "{"],
32+
[:symbol_prefix, ":"],
33+
[:symbol, "simplekey"],
34+
[:refers, "=>"],
35+
[:symbol_prefix, ":"],
36+
[:symbol, "value"],
37+
[:close_hash, "}"],
38+
]
39+
end
40+
end
41+
42+
please do check({:"string key" => :value})
43+
if symbol_hash_keys?
44+
tokens.should == [
45+
[:open_hash, "{"],
46+
[:open_symbol_string, "\""],
47+
[:symbol_string, "string key"],
48+
[:close_symbol_string, "\""],
49+
[:symbol_prefix, ":"],
50+
[:whitespace, " "],
51+
[:symbol_prefix, ":"],
52+
[:symbol, "value"],
53+
[:close_hash, "}"],
54+
]
55+
else
56+
tokens.should == [
57+
[:open_hash, "{"],
58+
[:symbol_prefix, ":"],
59+
[:open_symbol_string, "\""],
60+
[:symbol_string, "string key"],
61+
[:close_symbol_string, "\""],
62+
[:refers, "=>"],
63+
[:symbol_prefix, ":"],
64+
[:symbol, "value"],
65+
[:close_hash, "}"],
66+
]
67+
end
68+
end
69+
70+
please do check({:hallo => {1=>Set[2,3,4]}})
71+
if symbol_hash_keys?
72+
fail
73+
tokens.should == [
74+
# TODO
75+
]
76+
else
77+
tokens.should be_like [
78+
[:open_hash, "{"],
79+
[:symbol_prefix, ":"],
80+
[:symbol, "hallo"],
81+
[:refers, "=>"],
82+
[:open_hash, "{"],
83+
[:number, "1"],
84+
([:whitespace, " "] if spaced_hashes?),
85+
[:refers, "=>"],
86+
([:whitespace, " "] if spaced_hashes?),
87+
[:open_object, "#<"],
88+
[:object_class, "Set"],
89+
[:object_description_prefix, ":"],
90+
[:whitespace, " "],
91+
[:open_set, "{"],
92+
[:number, /\d+/],
93+
[:comma, ","],
94+
[:whitespace, " "],
95+
[:number, /\d+/],
96+
[:comma, ","],
97+
[:whitespace, " "],
98+
[:number, /\d+/],
99+
[:close_set, "}"],
100+
[:close_object, ">"],
101+
[:close_hash, "}"],
102+
[:close_hash, "}"],
103+
].compact
104+
end
105+
end
48106

49107
please do check( {1=>2, 3=>8, {} => {}} )
50108
tokens.should be_sorted [

spec/tokenizer_symbol_spec.rb

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -90,69 +90,74 @@
9090

9191
please do check :'hello"word'
9292
tokens.should == [
93-
[:symbol_prefix, ":"], [:open_symbol_string, "\""],
94-
[:symbol_string, "hello\\\"word"], [:close_symbol_string, "\""]
93+
[:symbol_prefix, ":"],
94+
[:open_symbol_string, "\""],
95+
[:symbol_string, "hello\\\"word"],
96+
[:close_symbol_string, "\""]
9597
]
9698
end
9799

98-
# FIXME 3.4 symbol hash keys
99-
# please do check [[:hallo],{:'hallo'=>:'test'}, {:'hallo='=>:'test='}, {:'<'=>9}, {:'<=>'=>9}, {:'<'=>:'<=>'}]
100-
# tokens.should == [
101-
# [:open_array, "["],
102-
# [:open_array, "["],
103-
# [:symbol_prefix, ":"],
104-
# [:symbol, "hallo"],
105-
# [:close_array, "]"],
106-
# [:comma, ","],
107-
# [:whitespace, " "],
108-
# [:open_hash, "{"],
109-
# [:symbol_prefix, ":"],
110-
# [:symbol, "hallo"],
111-
# [:refers, "=>"],
112-
# [:symbol_prefix, ":"],
113-
# [:symbol, "test"],
114-
# [:close_hash, "}"],
115-
# [:comma, ","],
116-
# [:whitespace, " "],
117-
# [:open_hash, "{"],
118-
# [:symbol_prefix, ":"],
119-
# [:symbol, "hallo="],
120-
# [:refers, "=>"],
121-
# [:symbol_prefix, ":"],
122-
# [:symbol, "test="],
123-
# [:close_hash, "}"],
124-
# [:comma, ","],
125-
# [:whitespace, " "],
126-
# [:open_hash, "{"],
127-
# [:symbol_prefix, ":"],
128-
# [:symbol, "<"],
129-
# [:refers, "=>"],
130-
# [:number, "9"],
131-
# [:close_hash, "}"],
132-
# [:comma, ","],
133-
# [:whitespace, " "],
134-
# [:open_hash, "{"],
135-
# [:symbol_prefix, ":"],
136-
# # [:symbol, "<=>"], # MAYBE fixme
137-
# [:symbol, "<"],
138-
# [:symbol, "=>"],
139-
# [:refers, "=>"],
140-
# [:number, "9"],
141-
# [:close_hash, "}"],
142-
# [:comma, ","],
143-
# [:whitespace, " "],
144-
# [:open_hash, "{"],
145-
# [:symbol_prefix, ":"],
146-
# [:symbol, "<"],
147-
# [:refers, "=>"],
148-
# [:symbol_prefix, ":"],
149-
# # [:symbol, "<=>"], # MAYBE fixme
150-
# [:symbol, "<"],
151-
# [:symbol, "=>"],
152-
# [:close_hash, "}"],
153-
# [:close_array, "]"],
154-
# ]
155-
# end
100+
please do check [[:hallo],{:'hallo'=>:'test'}, {:'hallo='=>:'test='}, {:'<'=>9}, {:'<=>'=>9}, {:'<'=>:'<=>'}]
101+
if symbol_hash_keys?
102+
fail
103+
else
104+
tokens.should == [
105+
[:open_array, "["],
106+
[:open_array, "["],
107+
[:symbol_prefix, ":"],
108+
[:symbol, "hallo"],
109+
[:close_array, "]"],
110+
[:comma, ","],
111+
[:whitespace, " "],
112+
[:open_hash, "{"],
113+
[:symbol_prefix, ":"],
114+
[:symbol, "hallo"],
115+
[:refers, "=>"],
116+
[:symbol_prefix, ":"],
117+
[:symbol, "test"],
118+
[:close_hash, "}"],
119+
[:comma, ","],
120+
[:whitespace, " "],
121+
[:open_hash, "{"],
122+
[:symbol_prefix, ":"],
123+
[:symbol, "hallo="],
124+
[:refers, "=>"],
125+
[:symbol_prefix, ":"],
126+
[:symbol, "test="],
127+
[:close_hash, "}"],
128+
[:comma, ","],
129+
[:whitespace, " "],
130+
[:open_hash, "{"],
131+
[:symbol_prefix, ":"],
132+
[:symbol, "<"],
133+
[:refers, "=>"],
134+
[:number, "9"],
135+
[:close_hash, "}"],
136+
[:comma, ","],
137+
[:whitespace, " "],
138+
[:open_hash, "{"],
139+
[:symbol_prefix, ":"],
140+
# [:symbol, "<=>"], # MAYBE fixme
141+
[:symbol, "<"],
142+
[:symbol, "=>"],
143+
[:refers, "=>"],
144+
[:number, "9"],
145+
[:close_hash, "}"],
146+
[:comma, ","],
147+
[:whitespace, " "],
148+
[:open_hash, "{"],
149+
[:symbol_prefix, ":"],
150+
[:symbol, "<"],
151+
[:refers, "=>"],
152+
[:symbol_prefix, ":"],
153+
# [:symbol, "<=>"], # MAYBE fixme
154+
[:symbol, "<"],
155+
[:symbol, "=>"],
156+
[:close_hash, "}"],
157+
[:close_array, "]"],
158+
]
159+
end
160+
end
156161

157162
please do check [:"42"]
158163
tokens.should == [

0 commit comments

Comments
 (0)