code-ruby 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/node/code.rb +5 -0
- data/lib/code/object/class.rb +4 -0
- data/lib/code/object/function.rb +35 -1
- data/spec/code_spec.rb +4 -7
- metadata +1 -2
- data/spec/code/object/http_spec.rb +0 -99
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 289eba7ee8807b4660bba3a8df2458d5d7b615deea52b66b3475eb2c306aa9e9
|
|
4
|
+
data.tar.gz: 6394f2e3a44499cdf85ecb315d1a303a52df7784f8c385c76b170702298d7d3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1bb7bf8488694f407300e3a18258601ada0eba25cd54ab8e0184a05889ac1171c87f5c62de341a26bae7876372cec80e194c82a993277b85fc8bc11d2bba10ef
|
|
7
|
+
data.tar.gz: bf4b7f896dc52eb6afabcc25e863d96fbf71a801bd469344887f7cff95d3879442757b3d0723a5d0594ee11aff671d78da4abdcfad0d889672f0e407c040fa95
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.0.
|
|
1
|
+
2.0.1
|
data/lib/code/node/code.rb
CHANGED
|
@@ -6,6 +6,7 @@ class Code
|
|
|
6
6
|
def initialize(parsed)
|
|
7
7
|
return if parsed.blank?
|
|
8
8
|
|
|
9
|
+
@parsed = parsed.deep_dup
|
|
9
10
|
@statements =
|
|
10
11
|
(parsed.presence || []).map { |statement| Statement.new(statement) }
|
|
11
12
|
end
|
|
@@ -57,6 +58,10 @@ class Code
|
|
|
57
58
|
def to_code
|
|
58
59
|
@statements.blank? ? Object::Nothing.new : Object::Code.new(self)
|
|
59
60
|
end
|
|
61
|
+
|
|
62
|
+
def to_raw
|
|
63
|
+
@parsed.deep_dup
|
|
64
|
+
end
|
|
60
65
|
end
|
|
61
66
|
end
|
|
62
67
|
end
|
data/lib/code/object/class.rb
CHANGED
data/lib/code/object/function.rb
CHANGED
|
@@ -152,7 +152,18 @@ class Code
|
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
def code_to_string
|
|
155
|
-
String.new(
|
|
155
|
+
String.new(
|
|
156
|
+
Format.format(
|
|
157
|
+
[
|
|
158
|
+
{
|
|
159
|
+
function: {
|
|
160
|
+
parameters: code_parameters.raw.map { |parameter| parameter_to_raw(parameter) },
|
|
161
|
+
body: code_body.raw.to_raw
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
)
|
|
166
|
+
)
|
|
156
167
|
end
|
|
157
168
|
|
|
158
169
|
def code_extend(function)
|
|
@@ -202,6 +213,29 @@ class Code
|
|
|
202
213
|
|
|
203
214
|
nil
|
|
204
215
|
end
|
|
216
|
+
|
|
217
|
+
def parameter_to_raw(parameter)
|
|
218
|
+
code_parameter = parameter.to_code
|
|
219
|
+
raw_parameter = { name: code_parameter.code_name.to_s }
|
|
220
|
+
|
|
221
|
+
if code_parameter.keyword?
|
|
222
|
+
raw_parameter[:keyword] = ":"
|
|
223
|
+
elsif code_parameter.keyword_splat?
|
|
224
|
+
raw_parameter[:keyword_splat] = "**"
|
|
225
|
+
elsif code_parameter.regular_splat?
|
|
226
|
+
raw_parameter[:regular_splat] = "*"
|
|
227
|
+
elsif code_parameter.block?
|
|
228
|
+
raw_parameter[:block] = "&"
|
|
229
|
+
elsif code_parameter.spread?
|
|
230
|
+
raw_parameter[:spread] = "..."
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
unless code_parameter.code_default.nothing?
|
|
234
|
+
raw_parameter[:default] = code_parameter.code_default.code_to_string.raw == "nothing" ? [] : Code.parse(code_parameter.code_default.to_s)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
raw_parameter
|
|
238
|
+
end
|
|
205
239
|
end
|
|
206
240
|
end
|
|
207
241
|
end
|
data/spec/code_spec.rb
CHANGED
|
@@ -239,6 +239,9 @@ RSpec.describe Code do
|
|
|
239
239
|
%w[Class(Time) Time],
|
|
240
240
|
%w[Class(nothing) Nothing],
|
|
241
241
|
%w[Class(true) Boolean],
|
|
242
|
+
%w[String String],
|
|
243
|
+
%w[Time Time],
|
|
244
|
+
%w[Class Class],
|
|
242
245
|
%w[Class.new Nothing],
|
|
243
246
|
%w[Class.new Nothing],
|
|
244
247
|
%w[Class.new(2.days.ago) Time],
|
|
@@ -331,15 +334,9 @@ RSpec.describe Code do
|
|
|
331
334
|
["a = 0 [1, 2, 3].each { |i| next if i == 2 a += i } a", "4"],
|
|
332
335
|
["a = 0\nb = 0\nwhile a < 4\n a += 1\n continue if a == 2\n b += a\nend\nb", "8"],
|
|
333
336
|
["a = 0 loop a += 1 break end a", "1"],
|
|
334
|
-
["a = 1\nbegin\n a += 1\n break if a > 3\n retry\nend\na", "4"],
|
|
335
337
|
["x = loop break(42) end x", "42"],
|
|
336
|
-
["a = 0 a += 1 retry if a < 3 a", "3"],
|
|
337
338
|
["a = 0\nuntil a > 10 a += 1 end a", "11"],
|
|
338
339
|
["a = 0\nwhile a < 10 a += 1 end a", "10"],
|
|
339
|
-
[
|
|
340
|
-
"a = 0\nretried = false\nwhile a < 2\n a += 1\n retry if a == 1 && !retried && (retried = true)\nend\na",
|
|
341
|
-
"2"
|
|
342
|
-
],
|
|
343
340
|
["a = 1 3.times { a += 1 } a", "4"],
|
|
344
341
|
["a = 1 a *= 2 a", "2"],
|
|
345
342
|
["a = 1 a += 1 a", "2"],
|
|
@@ -377,7 +374,6 @@ RSpec.describe Code do
|
|
|
377
374
|
["next(7)", "7"],
|
|
378
375
|
["not not false", "false"],
|
|
379
376
|
["not true", "false"],
|
|
380
|
-
["retry(8)", "8"],
|
|
381
377
|
["return(9)", "9"],
|
|
382
378
|
["f = () => { return(3) 4 } f()", "3"],
|
|
383
379
|
["a = 1 orirginal = 2 orirginal", "2"],
|
|
@@ -488,6 +484,7 @@ RSpec.describe Code do
|
|
|
488
484
|
["", ""]
|
|
489
485
|
].each do |input, expected|
|
|
490
486
|
it "#{input} == #{expected}" do
|
|
487
|
+
puts input
|
|
491
488
|
formatted = format_input(input)
|
|
492
489
|
|
|
493
490
|
output = StringIO.new
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -346,7 +346,6 @@ files:
|
|
|
346
346
|
- spec/code/object/decimal_spec.rb
|
|
347
347
|
- spec/code/object/dictionary_spec.rb
|
|
348
348
|
- spec/code/object/function_spec.rb
|
|
349
|
-
- spec/code/object/http_spec.rb
|
|
350
349
|
- spec/code/object/identifier_list_spec.rb
|
|
351
350
|
- spec/code/object/integer_spec.rb
|
|
352
351
|
- spec/code/object/list_spec.rb
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Code::Object::Http do
|
|
6
|
-
def self.verbs
|
|
7
|
-
%w[get head post put delete options trace patch]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.response_codes
|
|
11
|
-
{
|
|
12
|
-
continue: 100,
|
|
13
|
-
switching_protocols: 101,
|
|
14
|
-
processing: 102,
|
|
15
|
-
early_hints: 103,
|
|
16
|
-
ok: 200,
|
|
17
|
-
created: 201,
|
|
18
|
-
accepted: 202,
|
|
19
|
-
non_authoritative_information: 203,
|
|
20
|
-
no_content: 204,
|
|
21
|
-
reset_content: 205,
|
|
22
|
-
partial_content: 206,
|
|
23
|
-
multi_status: 207,
|
|
24
|
-
already_reported: 208,
|
|
25
|
-
im_used: 226,
|
|
26
|
-
multiple_choices: 300,
|
|
27
|
-
moved_permanently: 301,
|
|
28
|
-
found: 302,
|
|
29
|
-
see_other: 303,
|
|
30
|
-
not_modified: 304,
|
|
31
|
-
use_proxy: 305,
|
|
32
|
-
reserved: 306,
|
|
33
|
-
temporary_redirect: 307,
|
|
34
|
-
permanent_redirect: 308,
|
|
35
|
-
bad_request: 400,
|
|
36
|
-
unauthorized: 401,
|
|
37
|
-
payment_required: 402,
|
|
38
|
-
forbidden: 403,
|
|
39
|
-
not_found: 404,
|
|
40
|
-
method_not_allowed: 405,
|
|
41
|
-
not_acceptable: 406,
|
|
42
|
-
proxy_authentication_required: 407,
|
|
43
|
-
request_timeout: 408,
|
|
44
|
-
conflict: 409,
|
|
45
|
-
gone: 410,
|
|
46
|
-
length_required: 411,
|
|
47
|
-
precondition_failed: 412,
|
|
48
|
-
request_entity_too_large: 413,
|
|
49
|
-
request_uri_too_long: 414,
|
|
50
|
-
unsupported_media_type: 415,
|
|
51
|
-
requested_range_not_satisfiable: 416,
|
|
52
|
-
expectation_failed: 417,
|
|
53
|
-
misdirected_request: 421,
|
|
54
|
-
unprocessable_entity: 422,
|
|
55
|
-
locked: 423,
|
|
56
|
-
failed_dependency: 424,
|
|
57
|
-
too_early: 425,
|
|
58
|
-
upgrade_required: 426,
|
|
59
|
-
precondition_required: 428,
|
|
60
|
-
too_many_requests: 429,
|
|
61
|
-
request_header_fields_too_large: 431,
|
|
62
|
-
unavailable_for_legal_reasons: 451,
|
|
63
|
-
internal_server_error: 500,
|
|
64
|
-
not_implemented: 501,
|
|
65
|
-
bad_gateway: 502,
|
|
66
|
-
service_unavailable: 503,
|
|
67
|
-
gateway_timeout: 504,
|
|
68
|
-
http_version_not_supported: 505,
|
|
69
|
-
variant_also_negotiates: 506,
|
|
70
|
-
insufficient_storage: 507,
|
|
71
|
-
loop_detected: 508,
|
|
72
|
-
bandwidth_limit_exceeded: 509,
|
|
73
|
-
not_extended: 510,
|
|
74
|
-
network_authentication_required: 511
|
|
75
|
-
}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
verbs.each do |verb|
|
|
79
|
-
describe ".#{verb}" do
|
|
80
|
-
response_codes.each do |status, code|
|
|
81
|
-
it "returns #{code} as code and #{status} as status" do
|
|
82
|
-
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
|
83
|
-
response = Http.#{verb}("https://httpbin.org/status/#{code}")
|
|
84
|
-
[response.code, response.status]
|
|
85
|
-
INPUT
|
|
86
|
-
[#{code}, "#{status}"]
|
|
87
|
-
OUTPUT
|
|
88
|
-
|
|
89
|
-
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
|
90
|
-
response = Http.fetch("#{verb}", "https://httpbin.org/status/#{code}")
|
|
91
|
-
[response.code, response.status]
|
|
92
|
-
INPUT
|
|
93
|
-
[#{code}, "#{status}"]
|
|
94
|
-
OUTPUT
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|