code-ruby 1.9.7 → 1.9.8
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/format.rb +13 -8
- data/lib/code/object/identifier_list.rb +1 -1
- data/spec/code/format_spec.rb +4 -0
- data/spec/code/object/identifier_list_spec.rb +34 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56fcf3ffc17f9740302bc6bd52c6aeb204eb3799883920fa35d7140829070464
|
|
4
|
+
data.tar.gz: 6e8b2521a80535fbf094771f4c105c56f6ccaef4d492dfbec9b0d51d099ab875
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fccf82958c319089713c3e00ec779f06adb23f315bff2fd4e2af5bac36b74cf91dbff74c7a5cd7d807cb4353e043e689b372fc4f3302d7e806e48a7c6d021c0b
|
|
7
|
+
data.tar.gz: 8424f8d97d597e00c3390ace61a8038fc151415f7a87573912be0cd43f342686a2d6dac70a775a86a7033f8cd40197376e1e1a6d7eb654f1c842180f2804904e
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.8
|
data/lib/code/format.rb
CHANGED
|
@@ -220,30 +220,35 @@ class Code
|
|
|
220
220
|
components.flat_map do |component|
|
|
221
221
|
value = component[:value].to_s
|
|
222
222
|
if component[:type] == :code
|
|
223
|
-
[value]
|
|
223
|
+
[{ value: value, splittable: false }]
|
|
224
224
|
else
|
|
225
|
-
value
|
|
225
|
+
value
|
|
226
|
+
.split(/(\s+)/)
|
|
227
|
+
.reject(&:empty?)
|
|
228
|
+
.map { |unit| { value: unit, splittable: true } }
|
|
226
229
|
end
|
|
227
|
-
end
|
|
230
|
+
end
|
|
228
231
|
|
|
229
232
|
chunks = [""]
|
|
230
233
|
units.each do |unit|
|
|
231
|
-
|
|
234
|
+
value = unit[:value]
|
|
235
|
+
|
|
236
|
+
if unit[:splittable] && value.length > limit
|
|
232
237
|
if chunks.last.empty?
|
|
233
|
-
segments =
|
|
238
|
+
segments = value.scan(/.{1,#{limit}}/m)
|
|
234
239
|
chunks[-1] = segments.shift.to_s
|
|
235
240
|
segments.each { |segment| chunks << segment }
|
|
236
241
|
else
|
|
237
|
-
chunks <<
|
|
242
|
+
chunks << value
|
|
238
243
|
end
|
|
239
244
|
next
|
|
240
245
|
end
|
|
241
246
|
|
|
242
247
|
current = chunks.last
|
|
243
|
-
candidate = "#{current}#{
|
|
248
|
+
candidate = "#{current}#{value}"
|
|
244
249
|
if !current.empty? && candidate.length > limit
|
|
245
250
|
chunks[-1] = current
|
|
246
|
-
chunks <<
|
|
251
|
+
chunks << value
|
|
247
252
|
else
|
|
248
253
|
chunks[-1] = candidate
|
|
249
254
|
end
|
data/spec/code/format_spec.rb
CHANGED
|
@@ -30,6 +30,10 @@ RSpec.describe Code::Format do
|
|
|
30
30
|
[
|
|
31
31
|
"Http.post(\"https://api.openai.com/v1/chat/completions\", headers: { authorization: \"Bearer {open_ai_api_key}\", \"content-type\": \"application/json\" }, body: { model: model, messages: [{ role: \"system\", content: \"hello\" }, { role: \"user\", content: \"world\" }] }.to_json)",
|
|
32
32
|
"Http.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers: {\n authorization: \"Bearer {open_ai_api_key}\",\n \"content-type\": \"application/json\"\n },\n body: {\n model: model,\n messages: [\n { role: :system, content: :hello },\n { role: :user, content: :world }\n ]\n }.to_json\n)"
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"proxy_url = (url) => { \"{proxy_base_url}?{{ url: url, disposition: proxy_inline_disposition }.to_query}\" }",
|
|
36
|
+
"proxy_url = (url) => {\n \"{proxy_base_url}?\"\n + \"{{\n url: url,\n disposition: proxy_inline_disposition\n }.to_query}\"\n}"
|
|
33
37
|
]
|
|
34
38
|
].each do |input, expected|
|
|
35
39
|
it "formats #{input.inspect}" do
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Code::Object::IdentifierList do
|
|
6
|
+
it "keeps context for ||= assignments in nested context receivers" do
|
|
7
|
+
code_context = Code::Object::Context.new
|
|
8
|
+
code_identifier = Code::Object::String.new("value")
|
|
9
|
+
code_key = Code::Object::String.new("key")
|
|
10
|
+
|
|
11
|
+
code_context.code_set(
|
|
12
|
+
code_identifier,
|
|
13
|
+
Code::Object::Dictionary.new(code_key => Code::Object::Dictionary.new(a: 1))
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
identifier_list = described_class.new([code_identifier, code_key])
|
|
17
|
+
|
|
18
|
+
expect do
|
|
19
|
+
identifier_list.send(
|
|
20
|
+
:assign_in_context,
|
|
21
|
+
context: code_context,
|
|
22
|
+
assignment_operator: "||=",
|
|
23
|
+
code_value: Code::Object::Dictionary.new(b: 2),
|
|
24
|
+
arguments: Code::Object::List.new([Code::Object::Dictionary.new(b: 2)]),
|
|
25
|
+
operator: "||=",
|
|
26
|
+
error: StringIO.new,
|
|
27
|
+
input: StringIO.new,
|
|
28
|
+
object: Code::Object::Global.new,
|
|
29
|
+
output: StringIO.new,
|
|
30
|
+
source: ""
|
|
31
|
+
)
|
|
32
|
+
end.not_to raise_error
|
|
33
|
+
end
|
|
34
|
+
end
|
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: 1.9.
|
|
4
|
+
version: 1.9.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -346,6 +346,7 @@ files:
|
|
|
346
346
|
- spec/code/object/dictionary_spec.rb
|
|
347
347
|
- spec/code/object/function_spec.rb
|
|
348
348
|
- spec/code/object/http_spec.rb
|
|
349
|
+
- spec/code/object/identifier_list_spec.rb
|
|
349
350
|
- spec/code/object/integer_spec.rb
|
|
350
351
|
- spec/code/object/list_spec.rb
|
|
351
352
|
- spec/code/object/nothing_spec.rb
|