code-ruby 1.1.3 → 1.2.2
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/.github/dependabot.yml +13 -13
- data/.github/workflows/ci.yml +25 -24
- data/.npm-version +1 -0
- data/.rubocop.yml +14 -11
- data/Gemfile +5 -4
- data/Gemfile.lock +134 -28
- data/VERSION +1 -1
- data/bin/console +6 -0
- data/bin/dorian +31 -0
- data/code-ruby.gemspec +6 -1
- data/lib/code/error.rb +4 -25
- data/lib/code/node/code.rb +1 -1
- data/lib/code/node/function_parameter.rb +10 -8
- data/lib/code/node/while.rb +1 -1
- data/lib/code/object/boolean.rb +20 -16
- data/lib/code/object/class.rb +10 -4
- data/lib/code/object/code.rb +7 -3
- data/lib/code/object/context.rb +8 -8
- data/lib/code/object/date.rb +41 -7
- data/lib/code/object/decimal.rb +101 -56
- data/lib/code/object/dictionary.rb +245 -191
- data/lib/code/object/duration.rb +11 -7
- data/lib/code/object/function.rb +38 -25
- data/lib/code/object/global.rb +95 -42
- data/lib/code/object/html.rb +12 -14
- data/lib/code/object/http.rb +220 -0
- data/lib/code/object/identifier_list.rb +16 -16
- data/lib/code/object/integer.rb +129 -89
- data/lib/code/object/json.rb +18 -22
- data/lib/code/object/list.rb +154 -92
- data/lib/code/object/parameter.rb +9 -13
- data/lib/code/object/range.rb +77 -45
- data/lib/code/object/string.rb +15 -34
- data/lib/code/object/time.rb +17 -16
- data/lib/code/object.rb +126 -93
- data/lib/code/parser/string.rb +2 -1
- data/lib/code/type/sig.rb +3 -3
- data/lib/code-ruby.rb +119 -0
- data/package-lock.json +1 -1
- data/package.json +1 -1
- data/spec/code/object/http_spec.rb +91 -0
- data/spec/code/type_spec.rb +1 -1
- data/spec/code_spec.rb +10 -5
- data/spec/spec_helper.rb +18 -0
- metadata +51 -7
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe Code::Object::Http do
|
6
|
+
%w[get head post put delete connect options trace patch].each do |verb|
|
7
|
+
describe ".#{verb}" do
|
8
|
+
{
|
9
|
+
continue: 100,
|
10
|
+
switching_protocols: 101,
|
11
|
+
processing: 102,
|
12
|
+
early_hints: 103,
|
13
|
+
ok: 200,
|
14
|
+
created: 201,
|
15
|
+
accepted: 202,
|
16
|
+
non_authoritative_information: 203,
|
17
|
+
no_content: 204,
|
18
|
+
reset_content: 205,
|
19
|
+
partial_content: 206,
|
20
|
+
multi_status: 207,
|
21
|
+
already_reported: 208,
|
22
|
+
im_used: 226,
|
23
|
+
multiple_choices: 300,
|
24
|
+
moved_permanently: 301,
|
25
|
+
found: 302,
|
26
|
+
see_other: 303,
|
27
|
+
not_modified: 304,
|
28
|
+
use_proxy: 305,
|
29
|
+
reserved: 306,
|
30
|
+
temporary_redirect: 307,
|
31
|
+
permanent_redirect: 308,
|
32
|
+
bad_request: 400,
|
33
|
+
unauthorized: 401,
|
34
|
+
payment_required: 402,
|
35
|
+
forbidden: 403,
|
36
|
+
not_found: 404,
|
37
|
+
method_not_allowed: 405,
|
38
|
+
not_acceptable: 406,
|
39
|
+
proxy_authentication_required: 407,
|
40
|
+
request_timeout: 408,
|
41
|
+
conflict: 409,
|
42
|
+
gone: 410,
|
43
|
+
length_required: 411,
|
44
|
+
precondition_failed: 412,
|
45
|
+
request_entity_too_large: 413,
|
46
|
+
request_uri_too_long: 414,
|
47
|
+
unsupported_media_type: 415,
|
48
|
+
requested_range_not_satisfiable: 416,
|
49
|
+
expectation_failed: 417,
|
50
|
+
misdirected_request: 421,
|
51
|
+
unprocessable_entity: 422,
|
52
|
+
locked: 423,
|
53
|
+
failed_dependency: 424,
|
54
|
+
too_early: 425,
|
55
|
+
upgrade_required: 426,
|
56
|
+
precondition_required: 428,
|
57
|
+
too_many_requests: 429,
|
58
|
+
request_header_fields_too_large: 431,
|
59
|
+
unavailable_for_legal_reasons: 451,
|
60
|
+
internal_server_error: 500,
|
61
|
+
not_implemented: 501,
|
62
|
+
bad_gateway: 502,
|
63
|
+
service_unavailable: 503,
|
64
|
+
gateway_timeout: 504,
|
65
|
+
http_version_not_supported: 505,
|
66
|
+
variant_also_negotiates: 506,
|
67
|
+
insufficient_storage: 507,
|
68
|
+
loop_detected: 508,
|
69
|
+
bandwidth_limit_exceeded: 509,
|
70
|
+
not_extended: 510,
|
71
|
+
network_authentication_required: 511
|
72
|
+
}.each do |status, code|
|
73
|
+
it "returns #{code} as code and #{status} as status" do
|
74
|
+
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
75
|
+
response = Http.#{verb}("https://httpbin.org/status/#{code}")
|
76
|
+
[response.code, response.status]
|
77
|
+
INPUT
|
78
|
+
[#{code}, "#{status}"]
|
79
|
+
OUTPUT
|
80
|
+
|
81
|
+
expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
|
82
|
+
response = Http.fetch("#{verb}", "https://httpbin.org/status/#{code}")
|
83
|
+
[response.code, response.status]
|
84
|
+
INPUT
|
85
|
+
[#{code}, "#{status}"]
|
86
|
+
OUTPUT
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/code/type_spec.rb
CHANGED
@@ -14,7 +14,7 @@ RSpec.describe Code::Type do
|
|
14
14
|
describe "invalid" do
|
15
15
|
["1 - :a", "2 * true"].each do |input|
|
16
16
|
it input do
|
17
|
-
expect { Code.evaluate(input) }.to raise_error(Code::Error
|
17
|
+
expect { Code.evaluate(input) }.to raise_error(Code::Error)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/spec/code_spec.rb
CHANGED
@@ -74,6 +74,10 @@ RSpec.describe Code do
|
|
74
74
|
Html.link_to
|
75
75
|
Html.link_to('/')
|
76
76
|
Html.link_to('Home','/')
|
77
|
+
Json.parse('1')
|
78
|
+
Json.parse('[]')
|
79
|
+
Json.parse('{}')
|
80
|
+
Json.parse('random-string')
|
77
81
|
] + ["Time.hour >= 6 and Time.hour <= 23"]
|
78
82
|
).each { |input| it(input) { described_class.evaluate(input) } }
|
79
83
|
|
@@ -311,17 +315,18 @@ RSpec.describe Code do
|
|
311
315
|
["[1, 2, 3].none?", "false"],
|
312
316
|
["[1, 2, 3].none?(&:even?)", "false"],
|
313
317
|
["'{1} {2}'", "'1 2'"],
|
318
|
+
%w[Json.parse("1") 1],
|
314
319
|
["", ""]
|
315
320
|
].each do |input, expected|
|
316
321
|
it "#{input} == #{expected}" do
|
317
322
|
output = StringIO.new
|
318
|
-
|
319
|
-
|
320
|
-
expect(
|
323
|
+
code_input = described_class.evaluate(input, output:)
|
324
|
+
code_expected = described_class.evaluate(expected)
|
325
|
+
expect(code_input).to eq(code_expected)
|
321
326
|
expect(output.string).to eq("")
|
322
|
-
next if
|
327
|
+
next if code_input.is_a?(Code::Object::Decimal)
|
323
328
|
|
324
|
-
expect(
|
329
|
+
expect(code_input.to_json).to eq(code_expected.to_json)
|
325
330
|
end
|
326
331
|
end
|
327
332
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../lib/code-ruby"
|
4
|
+
require "sinatra"
|
5
|
+
require "webmock/rspec"
|
6
|
+
|
7
|
+
class FakeHttpBin < Sinatra::Base
|
8
|
+
set :host_authorization, { permitted_hosts: ["httpbin.org"] }
|
9
|
+
|
10
|
+
%w[GET HEAD POST PUT DELETE CONNECT OPTIONS TRACE PATCH].each do |verb|
|
11
|
+
route verb, "/status/:status" do
|
12
|
+
status params[:status].to_i
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
WebMock.disable_net_connect!
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.before { stub_request(:any, /httpbin\.org/).to_rack(FakeHttpBin) }
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-03 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -24,6 +23,20 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: base64
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
27
40
|
- !ruby/object:Gem::Dependency
|
28
41
|
name: bigdecimal
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +107,34 @@ dependencies:
|
|
94
107
|
- - ">="
|
95
108
|
- !ruby/object:Gem::Version
|
96
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: net-http
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
type: :runtime
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: uri
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
97
138
|
- !ruby/object:Gem::Dependency
|
98
139
|
name: zeitwerk
|
99
140
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +160,7 @@ files:
|
|
119
160
|
- ".github/workflows/ci.yml"
|
120
161
|
- ".gitignore"
|
121
162
|
- ".node-version"
|
163
|
+
- ".npm-version"
|
122
164
|
- ".prettierignore"
|
123
165
|
- ".rspec"
|
124
166
|
- ".rubocop.yml"
|
@@ -134,6 +176,8 @@ files:
|
|
134
176
|
- bin/bundle-audit
|
135
177
|
- bin/bundler-audit
|
136
178
|
- bin/code
|
179
|
+
- bin/console
|
180
|
+
- bin/dorian
|
137
181
|
- bin/rspec
|
138
182
|
- bin/rubocop
|
139
183
|
- bin/test
|
@@ -181,6 +225,7 @@ files:
|
|
181
225
|
- lib/code/object/function.rb
|
182
226
|
- lib/code/object/global.rb
|
183
227
|
- lib/code/object/html.rb
|
228
|
+
- lib/code/object/http.rb
|
184
229
|
- lib/code/object/identifier_list.rb
|
185
230
|
- lib/code/object/integer.rb
|
186
231
|
- lib/code/object/json.rb
|
@@ -245,6 +290,7 @@ files:
|
|
245
290
|
- spec/code/object/decimal_spec.rb
|
246
291
|
- spec/code/object/dictionary_spec.rb
|
247
292
|
- spec/code/object/function_spec.rb
|
293
|
+
- spec/code/object/http_spec.rb
|
248
294
|
- spec/code/object/integer_spec.rb
|
249
295
|
- spec/code/object/list_spec.rb
|
250
296
|
- spec/code/object/nothing_spec.rb
|
@@ -268,7 +314,6 @@ licenses:
|
|
268
314
|
- MIT
|
269
315
|
metadata:
|
270
316
|
rubygems_mfa_required: 'true'
|
271
|
-
post_install_message:
|
272
317
|
rdoc_options: []
|
273
318
|
require_paths:
|
274
319
|
- lib
|
@@ -276,15 +321,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
276
321
|
requirements:
|
277
322
|
- - ">="
|
278
323
|
- !ruby/object:Gem::Version
|
279
|
-
version: 3.
|
324
|
+
version: '3.1'
|
280
325
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
326
|
requirements:
|
282
327
|
- - ">="
|
283
328
|
- !ruby/object:Gem::Version
|
284
329
|
version: '0'
|
285
330
|
requirements: []
|
286
|
-
rubygems_version: 3.
|
287
|
-
signing_key:
|
331
|
+
rubygems_version: 3.6.2
|
288
332
|
specification_version: 4
|
289
333
|
summary: a programming language for the internet
|
290
334
|
test_files: []
|