code-ruby 0.6.3 → 0.6.5
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 +2 -0
- data/Gemfile.lock +3 -3
- data/bin/code +25 -24
- data/code-ruby.gemspec +6 -4
- data/lib/code/node/base_10.rb +1 -3
- data/lib/code/node/call.rb +5 -4
- data/lib/code/node/decimal.rb +1 -3
- data/lib/code/node/dictionary.rb +1 -1
- data/lib/code/node/if.rb +5 -5
- data/lib/code/node/nothing.rb +2 -1
- data/lib/code/object/decimal.rb +1 -3
- data/lib/code/object/dictionary.rb +9 -15
- data/lib/code/object/function.rb +1 -1
- data/lib/code/object/integer.rb +1 -9
- data/lib/code/object/ruby_function.rb +2 -2
- data/lib/code/object/string.rb +3 -3
- data/lib/code/object.rb +2 -4
- data/lib/code/parser/string.rb +1 -1
- data/lib/code/ruby.rb +2 -17
- data/lib/code/type/hash.rb +2 -0
- data/lib/code/type/repeat.rb +1 -1
- data/lib/code/version.rb +3 -1
- data/lib/code-ruby.rb +2 -0
- data/spec/code/node/call_spec.rb +31 -33
- data/spec/code/object/function_spec.rb +10 -12
- data/spec/code_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -0
- metadata +10 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e265eb7980e078c895b92b71d1e5b0e3e3a35cb833537bdc0f1614ce2ac76b
|
4
|
+
data.tar.gz: 9d2f374bb8a627bc3b0fbb2325630a692fa01bef52a9a81750db643454163f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b43ac0ea5ad94cdf569518df455be616c0a1a21ba90ec548c278080eaf36b8466707960ff07bc90739a3ebb2cd9e31e481da4646eebd47ef9cd4e5d543b7c7a2
|
7
|
+
data.tar.gz: 33c41f911e6a9043f79a2c89a58e373fd200715f35bfcd8c0bea5554a10c2eca2c8b4fd145f4676c33a7723e5d5fb15179a6af568b079e43170fa0ce09eced15
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (0.6.
|
4
|
+
code-ruby (0.6.4)
|
5
5
|
bigdecimal (~> 3)
|
6
6
|
language-ruby (~> 0)
|
7
7
|
zeitwerk (~> 2)
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
bigdecimal (3.1.6)
|
13
13
|
diff-lcs (1.5.0)
|
14
|
-
language-ruby (0.6.
|
14
|
+
language-ruby (0.6.1)
|
15
15
|
zeitwerk (~> 2)
|
16
16
|
rspec (3.12.0)
|
17
17
|
rspec-core (~> 3.12.0)
|
@@ -42,4 +42,4 @@ RUBY VERSION
|
|
42
42
|
ruby 3.3.0p0
|
43
43
|
|
44
44
|
BUNDLED WITH
|
45
|
-
2.5.
|
45
|
+
2.5.6
|
data/bin/code
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require_relative
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/code-ruby'
|
5
6
|
|
6
|
-
options = { timeout: 0, profile: false, profiler:
|
7
|
+
options = { timeout: 0, profile: false, profiler: 'text' }
|
7
8
|
|
8
9
|
OptionParser
|
9
10
|
.new do |opts|
|
10
|
-
opts.banner =
|
11
|
+
opts.banner = 'Usage: template [options]'
|
11
12
|
|
12
|
-
opts.on(
|
13
|
+
opts.on('-v', '--version', 'Version of template') do |_input|
|
13
14
|
puts Code::Version
|
14
15
|
exit
|
15
16
|
end
|
16
17
|
|
17
18
|
opts.on(
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
'-i INPUT',
|
20
|
+
'--input=INPUT',
|
21
|
+
'Input in the code language (String or File)'
|
21
22
|
) do |input|
|
22
23
|
input = File.read(input) if File.exist?(input)
|
23
24
|
|
@@ -25,43 +26,43 @@ OptionParser
|
|
25
26
|
end
|
26
27
|
|
27
28
|
opts.on(
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
'-c CONTEXT',
|
30
|
+
'--context=CONTEXT',
|
31
|
+
'Context in the code language (String or File)'
|
31
32
|
) do |context|
|
32
33
|
context = File.read(context) if File.exist?(context)
|
33
34
|
|
34
35
|
options[:context] = context
|
35
36
|
end
|
36
37
|
|
37
|
-
opts.on(
|
38
|
+
opts.on('-p', '--parse', 'Get parser results for input') do |parse|
|
38
39
|
options[:parse] = parse
|
39
40
|
end
|
40
41
|
|
41
42
|
opts.on(
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
'-t TIMEOUT',
|
44
|
+
'--timeout=TIMEOUT',
|
45
|
+
'Set timeout in seconds'
|
45
46
|
) { |timeout| options[:timeout] = timeout.to_f }
|
46
47
|
|
47
|
-
opts.on(
|
48
|
-
require
|
48
|
+
opts.on('--profile', 'Profile Ruby code') do |_timeout|
|
49
|
+
require 'ruby-prof'
|
49
50
|
options[:profile] = true
|
50
51
|
end
|
51
52
|
|
52
53
|
opts.on(
|
53
|
-
|
54
|
-
|
54
|
+
'--profiler TYPE',
|
55
|
+
'Profiler output type (text (default) or html)'
|
55
56
|
) do |profiler|
|
56
|
-
require
|
57
|
+
require 'ruby-prof'
|
57
58
|
options[:profile] = true
|
58
59
|
options[:profiler] = profiler
|
59
60
|
end
|
60
61
|
end
|
61
62
|
.parse!
|
62
63
|
|
63
|
-
input = options.fetch(:input,
|
64
|
-
context = options.fetch(:context,
|
64
|
+
input = options.fetch(:input, '')
|
65
|
+
context = options.fetch(:context, '')
|
65
66
|
|
66
67
|
RubyProf.start if options[:profile]
|
67
68
|
|
@@ -73,10 +74,10 @@ end
|
|
73
74
|
|
74
75
|
if options[:profile]
|
75
76
|
result = RubyProf.stop
|
76
|
-
if options[:profiler] ==
|
77
|
+
if options[:profiler] == 'text'
|
77
78
|
printer = RubyProf::FlatPrinter.new(result)
|
78
79
|
printer.print($stdout)
|
79
|
-
elsif options[:profiler] ==
|
80
|
+
elsif options[:profiler] == 'html'
|
80
81
|
printer = RubyProf::GraphHtmlPrinter.new(result)
|
81
82
|
printer.print($stdout)
|
82
83
|
else
|
data/code-ruby.gemspec
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
1
4
|
require_relative "lib/code/version"
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
@@ -7,14 +10,13 @@ Gem::Specification.new do |s|
|
|
7
10
|
s.description = 'A programming language, like Code.evaluate("1 + 1") # => 2'
|
8
11
|
s.authors = ["Dorian Marié"]
|
9
12
|
s.email = "dorian@dorianmarie.fr"
|
10
|
-
s.files = `git ls-files`.split(
|
11
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
12
14
|
s.require_paths = ["lib"]
|
13
15
|
s.homepage = "https://github.com/dorianmariefr/code-ruby"
|
14
16
|
s.license = "MIT"
|
15
17
|
s.executables = "code"
|
16
18
|
|
17
|
-
s.add_dependency "zeitwerk", "~> 2"
|
18
|
-
s.add_dependency "language-ruby", "~> 0"
|
19
19
|
s.add_dependency "bigdecimal", "~> 3"
|
20
|
+
s.add_dependency "language-ruby", "~> 0"
|
21
|
+
s.add_dependency "zeitwerk", "~> 2"
|
20
22
|
end
|
data/lib/code/node/base_10.rb
CHANGED
@@ -6,9 +6,7 @@ class Code
|
|
6
6
|
def initialize(parsed)
|
7
7
|
@whole = parsed.delete(:whole)
|
8
8
|
|
9
|
-
if parsed.key?(:exponent)
|
10
|
-
@exponent = Node::Statement.new(parsed.delete(:exponent))
|
11
|
-
end
|
9
|
+
@exponent = Node::Statement.new(parsed.delete(:exponent)) if parsed.key?(:exponent)
|
12
10
|
|
13
11
|
super(parsed)
|
14
12
|
end
|
data/lib/code/node/call.rb
CHANGED
@@ -40,13 +40,14 @@ class Code
|
|
40
40
|
@arguments.each do |argument|
|
41
41
|
if argument.keyword?
|
42
42
|
if arguments.last&.value.is_a?(Object::Dictionary)
|
43
|
-
arguments.last.value
|
44
|
-
|
45
|
-
|
43
|
+
arguments.last.value.code_set(
|
44
|
+
argument.name,
|
45
|
+
argument.evaluate(**args).value
|
46
|
+
)
|
46
47
|
else
|
47
48
|
arguments << Object::Argument.new(
|
48
49
|
Object::Dictionary.new(
|
49
|
-
{
|
50
|
+
{argument.name => argument.evaluate(**args).value}
|
50
51
|
)
|
51
52
|
)
|
52
53
|
end
|
data/lib/code/node/decimal.rb
CHANGED
@@ -6,9 +6,7 @@ class Code
|
|
6
6
|
def initialize(parsed)
|
7
7
|
@decimal = parsed.delete(:decimal)
|
8
8
|
|
9
|
-
if parsed.key?(:exponent)
|
10
|
-
@exponent = Node::Statement.new(parsed.delete(:exponent))
|
11
|
-
end
|
9
|
+
@exponent = Node::Statement.new(parsed.delete(:exponent)) if parsed.key?(:exponent)
|
12
10
|
|
13
11
|
super(parsed)
|
14
12
|
end
|
data/lib/code/node/dictionary.rb
CHANGED
@@ -8,7 +8,7 @@ class Code
|
|
8
8
|
if parsed.key?(:statement)
|
9
9
|
@key = Node::Statement.new(parsed.delete(:statement))
|
10
10
|
elsif parsed.key?(:name)
|
11
|
-
@key = Node::String.new([{
|
11
|
+
@key = Node::String.new([{text: parsed.delete(:name)}])
|
12
12
|
end
|
13
13
|
|
14
14
|
@value = Node::Code.new(parsed.delete(:value)) if parsed[:value]
|
data/lib/code/node/if.rb
CHANGED
@@ -32,21 +32,21 @@ class Code
|
|
32
32
|
|
33
33
|
def evaluate(**args)
|
34
34
|
if @first_operator == IF_KEYWORD &&
|
35
|
-
|
35
|
+
@first_statement.evaluate(**args).truthy?
|
36
36
|
@first_body.evaluate(**args)
|
37
37
|
elsif @first_operator == UNLESS_KEYWORD &&
|
38
|
-
|
38
|
+
@first_statement.evaluate(**args).falsy?
|
39
39
|
@first_body.evaluate(**args)
|
40
40
|
else
|
41
41
|
@elses.each do |elses|
|
42
42
|
if elses.operator == ELSIF_KEYWORD &&
|
43
|
-
|
43
|
+
elses.statement.evaluate(**args).truthy?
|
44
44
|
return elses.body.evaluate(**args)
|
45
45
|
elsif elses.operator == IF_KEYWORD &&
|
46
|
-
|
46
|
+
elses.statement.evaluate(**args).truthy?
|
47
47
|
return elses.body.evaluate(**args)
|
48
48
|
elsif elses.operator == UNLESS_KEYWORD &&
|
49
|
-
|
49
|
+
elses.statement.evaluate(**args).falsy?
|
50
50
|
return elses.body.evaluate(**args)
|
51
51
|
elsif elses.operator == ELSE_KEYWORD
|
52
52
|
return elses.body.evaluate(**args)
|
data/lib/code/node/nothing.rb
CHANGED
data/lib/code/object/decimal.rb
CHANGED
@@ -9,9 +9,7 @@ class Code
|
|
9
9
|
@raw = BigDecimal(decimal)
|
10
10
|
|
11
11
|
return unless exponent
|
12
|
-
unless exponent.is_a?(Number)
|
13
|
-
raise ::Code::Error::TypeError, "exponent is not a number"
|
14
|
-
end
|
12
|
+
raise ::Code::Error::TypeError, "exponent is not a number" unless exponent.is_a?(Number)
|
15
13
|
|
16
14
|
@raw *= 10**exponent.raw
|
17
15
|
end
|
@@ -215,9 +215,7 @@ class Code
|
|
215
215
|
def code_delete(*arguments, index: Integer.new(0), **globals)
|
216
216
|
default =
|
217
217
|
(
|
218
|
-
if arguments.last.is_a?(Function) && arguments.size > 1
|
219
|
-
arguments.last
|
220
|
-
end
|
218
|
+
arguments.last if arguments.last.is_a?(Function) && arguments.size > 1
|
221
219
|
)
|
222
220
|
|
223
221
|
arguments = arguments[..-2] if default
|
@@ -307,8 +305,8 @@ class Code
|
|
307
305
|
self
|
308
306
|
end
|
309
307
|
|
310
|
-
def code_dig(*
|
311
|
-
raw.dig(*
|
308
|
+
def code_dig(*)
|
309
|
+
raw.dig(*) || Nothing.new
|
312
310
|
end
|
313
311
|
|
314
312
|
def code_each(argument, **globals)
|
@@ -335,16 +333,14 @@ class Code
|
|
335
333
|
Boolean.new(raw.empty?)
|
336
334
|
end
|
337
335
|
|
338
|
-
def code_except(*
|
339
|
-
self.class.new(raw.except(*
|
336
|
+
def code_except(*)
|
337
|
+
self.class.new(raw.except(*))
|
340
338
|
end
|
341
339
|
|
342
340
|
def code_fetch(*arguments, index: Integer.new(0), **globals)
|
343
341
|
default =
|
344
342
|
(
|
345
|
-
if arguments.last.is_a?(Function) && arguments.size > 1
|
346
|
-
arguments.last
|
347
|
-
end
|
343
|
+
arguments.last if arguments.last.is_a?(Function) && arguments.size > 1
|
348
344
|
)
|
349
345
|
|
350
346
|
arguments = arguments[..-2] if default
|
@@ -394,8 +390,8 @@ class Code
|
|
394
390
|
end
|
395
391
|
end
|
396
392
|
|
397
|
-
def code_fetch_values(*
|
398
|
-
List.new(raw.fetch_values(*
|
393
|
+
def code_fetch_values(*)
|
394
|
+
List.new(raw.fetch_values(*))
|
399
395
|
end
|
400
396
|
|
401
397
|
def code_five?
|
@@ -494,9 +490,7 @@ class Code
|
|
494
490
|
def code_merge(*arguments, **globals)
|
495
491
|
conflict =
|
496
492
|
(
|
497
|
-
if arguments.last.is_a?(Function) && arguments.size > 1
|
498
|
-
arguments.last
|
499
|
-
end
|
493
|
+
arguments.last if arguments.last.is_a?(Function) && arguments.size > 1
|
500
494
|
)
|
501
495
|
|
502
496
|
arguments = arguments[..-2] if conflict
|
data/lib/code/object/function.rb
CHANGED
data/lib/code/object/integer.rb
CHANGED
@@ -10,9 +10,7 @@ class Code
|
|
10
10
|
|
11
11
|
return unless exponent
|
12
12
|
|
13
|
-
unless exponent.is_a?(Number)
|
14
|
-
raise Code::Error::TypeError, "exponent is not a number"
|
15
|
-
end
|
13
|
+
raise Code::Error::TypeError, "exponent is not a number" unless exponent.is_a?(Number)
|
16
14
|
|
17
15
|
@raw *= 10**exponent.raw
|
18
16
|
end
|
@@ -40,15 +38,9 @@ class Code
|
|
40
38
|
when "**", "power"
|
41
39
|
sig(args) { Number }
|
42
40
|
code_power(value)
|
43
|
-
when "+", "plus"
|
44
|
-
sig(args) { Object.maybe }
|
45
|
-
value ? code_plus(value) : self
|
46
41
|
when "+", "plus", "self"
|
47
42
|
sig(args) { Object.maybe }
|
48
43
|
value ? code_plus(value) : code_self
|
49
|
-
when "-", "minus"
|
50
|
-
sig(args) { Number.maybe }
|
51
|
-
value ? code_minus(value) : code_unary_minus
|
52
44
|
when "-", "minus", "unary_minus"
|
53
45
|
sig(args) { Number.maybe }
|
54
46
|
value ? code_minus(value) : code_unary_minus
|
@@ -25,8 +25,8 @@ class Code
|
|
25
25
|
args
|
26
26
|
.select(&:keyword?)
|
27
27
|
.map do |argument|
|
28
|
-
|
29
|
-
|
28
|
+
[argument.name.to_sym, Ruby.from_code(argument.value)]
|
29
|
+
end
|
30
30
|
.to_h
|
31
31
|
|
32
32
|
Ruby.to_code(raw.call(*regular_arguments, **keyword_arguments))
|
data/lib/code/object/string.rb
CHANGED
@@ -33,7 +33,7 @@ class Code
|
|
33
33
|
sig(args)
|
34
34
|
code_downcase
|
35
35
|
when "include?"
|
36
|
-
sig(args) {
|
36
|
+
sig(args) { String }
|
37
37
|
code_include?(value)
|
38
38
|
when "reverse"
|
39
39
|
sig(args)
|
@@ -68,7 +68,7 @@ class Code
|
|
68
68
|
[
|
69
69
|
{
|
70
70
|
function: {
|
71
|
-
parameters: [{
|
71
|
+
parameters: [{name: "_"}],
|
72
72
|
body: [
|
73
73
|
{
|
74
74
|
left_operation: {
|
@@ -78,7 +78,7 @@ class Code
|
|
78
78
|
}
|
79
79
|
},
|
80
80
|
others: [
|
81
|
-
{
|
81
|
+
{operator: ".", statement: {call: {name: raw}}}
|
82
82
|
]
|
83
83
|
}
|
84
84
|
}
|
data/lib/code/object.rb
CHANGED
@@ -33,7 +33,7 @@ class Code
|
|
33
33
|
other == self
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
alias_method :eql?, :==
|
37
37
|
|
38
38
|
def call(**args)
|
39
39
|
operator = args.fetch(:operator, nil)
|
@@ -149,9 +149,7 @@ class Code
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def hash
|
152
|
-
unless respond_to?(:raw)
|
153
|
-
raise NotImplementedError, "#{self.class.name}#hash"
|
154
|
-
end
|
152
|
+
raise NotImplementedError, "#{self.class.name}#hash" unless respond_to?(:raw)
|
155
153
|
|
156
154
|
[self.class, raw].hash
|
157
155
|
end
|
data/lib/code/parser/string.rb
CHANGED
data/lib/code/ruby.rb
CHANGED
@@ -54,19 +54,8 @@ class Code
|
|
54
54
|
|
55
55
|
def from_code
|
56
56
|
if code?
|
57
|
-
if code_nothing?
|
58
|
-
|
59
|
-
elsif code_boolean?
|
60
|
-
raw.raw
|
61
|
-
elsif code_decimal?
|
62
|
-
raw.raw
|
63
|
-
elsif code_integer?
|
64
|
-
raw.raw
|
65
|
-
elsif code_nothing?
|
66
|
-
raw.raw
|
67
|
-
elsif code_range?
|
68
|
-
raw.raw
|
69
|
-
elsif code_string?
|
57
|
+
if code_nothing? || code_boolean? || code_decimal? || code_integer? ||
|
58
|
+
code_range? || code_string?
|
70
59
|
raw.raw
|
71
60
|
elsif code_dictionnary?
|
72
61
|
raw
|
@@ -153,10 +142,6 @@ class Code
|
|
153
142
|
raw.is_a?(::Code::Object::Integer)
|
154
143
|
end
|
155
144
|
|
156
|
-
def code_nothing?
|
157
|
-
raw.is_a?(::Code::Object::Nothing)
|
158
|
-
end
|
159
|
-
|
160
145
|
def code_range?
|
161
146
|
raw.is_a?(::Code::Object::Range)
|
162
147
|
end
|
data/lib/code/type/hash.rb
CHANGED
@@ -11,9 +11,11 @@ class Code
|
|
11
11
|
|
12
12
|
def valid?(argument)
|
13
13
|
return false unless argument.is_a?(Object::Dictionary)
|
14
|
+
|
14
15
|
argument = argument.raw
|
15
16
|
(argument.keys + hash.keys).uniq.all? do |key|
|
16
17
|
next false unless hash[key] && argument[key]
|
18
|
+
|
17
19
|
valid_for?(expected: hash[key], actual: argument[key])
|
18
20
|
end
|
19
21
|
end
|
data/lib/code/type/repeat.rb
CHANGED
data/lib/code/version.rb
CHANGED
data/lib/code-ruby.rb
CHANGED
data/spec/code/node/call_spec.rb
CHANGED
@@ -3,37 +3,35 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Code::Node::Call do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
[
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
=end
|
6
|
+
# let(:context) { <<~CONTEXT }
|
7
|
+
# render = (*args, **kargs, &block) => {
|
8
|
+
# [args, kargs, block&.call(:dorian)]
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# { render:, user: { name: :Dorian } }"
|
12
|
+
# CONTEXT
|
13
|
+
#
|
14
|
+
# [
|
15
|
+
# ["render", "[[], {}, nothing]"],
|
16
|
+
# ["render()", "[[], {}, nothing]"],
|
17
|
+
# ["render(user)", "[[user], {}, nothing]"],
|
18
|
+
# [
|
19
|
+
# "render(user, first_name: :Dorian)",
|
20
|
+
# "[[user], { first_name: :Dorian }, nothing]"
|
21
|
+
# ],
|
22
|
+
# ["render { }", "[[], {}, nothing]"],
|
23
|
+
# ["render do end", "[[], {}, nothing]"],
|
24
|
+
# ["render { |name| name.upcase }", "[[], {}, :Dorian]"],
|
25
|
+
# ["render(user) { |name| name.upcase }", "[[user], {}, :Dorian]"],
|
26
|
+
# ["render(user) do |name| name.upcase end", "[[user], {}, :Dorian]"],
|
27
|
+
# ["render { :Dorian }", "[[], {}, :Dorian]"],
|
28
|
+
# ["render(user) { :Dorian }", "[[user], {}, :Dorian]"],
|
29
|
+
# ["render(user) do :Dorian end", "[[user], {}, :Dorian]"]
|
30
|
+
# ].each do |input, expected|
|
31
|
+
# it "#{input} == #{expected}" do
|
32
|
+
# expect(Code.evaluate(input, context)).to eq(
|
33
|
+
# Code.evaluate(expected, context)
|
34
|
+
# )
|
35
|
+
# end
|
36
|
+
# end
|
39
37
|
end
|
@@ -3,18 +3,16 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe Code::Object::Function do
|
6
|
-
|
7
|
-
[
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
=end
|
6
|
+
# [
|
7
|
+
# ["even? = (i) => { i.even? } even?(2)", "true"],
|
8
|
+
# ["even? = (i:) => { i.even? } even?(i: 2)", "true"],
|
9
|
+
# ["add = (a, b) => { a + b } add(1, 2)", "3"],
|
10
|
+
# ["minus = (a:, b:) => { a - b } minus(b: 1, a: 2)", "1"]
|
11
|
+
# ].each do |input, expected|
|
12
|
+
# it "#{input} == #{expected}" do
|
13
|
+
# expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
14
|
+
# end
|
15
|
+
# end
|
18
16
|
|
19
17
|
context "valid" do
|
20
18
|
[
|
data/spec/code_spec.rb
CHANGED
@@ -109,7 +109,7 @@ RSpec.describe Code do
|
|
109
109
|
['"Hello \\{name}"', '"Hello \\{" + "name}"'],
|
110
110
|
["'Hello {1}'", '"Hello 1"'],
|
111
111
|
['"Hello {1}"', '"Hello 1"'],
|
112
|
-
[
|
112
|
+
%w[:Hello.include?(:H) true],
|
113
113
|
%w["Hello".downcase :hello],
|
114
114
|
["true ? 1", "1"],
|
115
115
|
["false ? 1", ""],
|
@@ -141,7 +141,7 @@ RSpec.describe Code do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it "converts nil" do
|
144
|
-
ruby = Code::Ruby.from_code(Code.evaluate("a", ruby: {
|
144
|
+
ruby = Code::Ruby.from_code(Code.evaluate("a", ruby: {a: nil}))
|
145
145
|
|
146
146
|
expect(ruby).to eq(nil)
|
147
147
|
end
|
@@ -154,7 +154,7 @@ RSpec.describe Code do
|
|
154
154
|
|
155
155
|
it "works with nested objects" do
|
156
156
|
expect(
|
157
|
-
Code.evaluate("items.first.title", ruby: {
|
157
|
+
Code.evaluate("items.first.title", ruby: {items: [{title: "Hello"}]})
|
158
158
|
).to eq(Code.evaluate(":Hello"))
|
159
159
|
end
|
160
160
|
|
@@ -163,7 +163,7 @@ RSpec.describe Code do
|
|
163
163
|
Code.evaluate(
|
164
164
|
"items.map { |item| item.title }",
|
165
165
|
ruby: {
|
166
|
-
items: [{
|
166
|
+
items: [{title: "Hello"}]
|
167
167
|
}
|
168
168
|
)
|
169
169
|
).to eq(Code.evaluate("[:Hello]"))
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bigdecimal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: language-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: zeitwerk
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2'
|
55
55
|
description: 'A programming language, like Code.evaluate("1 + 1") # => 2'
|
56
56
|
email: dorian@dorianmarie.fr
|
57
57
|
executables:
|
@@ -206,30 +206,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
206
|
- !ruby/object:Gem::Version
|
207
207
|
version: '0'
|
208
208
|
requirements: []
|
209
|
-
rubygems_version: 3.5.
|
209
|
+
rubygems_version: 3.5.3
|
210
210
|
signing_key:
|
211
211
|
specification_version: 4
|
212
212
|
summary: A programming language
|
213
|
-
test_files:
|
214
|
-
- spec/code/node/call_spec.rb
|
215
|
-
- spec/code/object/boolean_spec.rb
|
216
|
-
- spec/code/object/decimal_spec.rb
|
217
|
-
- spec/code/object/dictionary_spec.rb
|
218
|
-
- spec/code/object/function_spec.rb
|
219
|
-
- spec/code/object/integer_spec.rb
|
220
|
-
- spec/code/object/list_spec.rb
|
221
|
-
- spec/code/object/nothing_spec.rb
|
222
|
-
- spec/code/object/range_spec.rb
|
223
|
-
- spec/code/parser/boolean_spec.rb
|
224
|
-
- spec/code/parser/chained_call.rb
|
225
|
-
- spec/code/parser/dictionary_spec.rb
|
226
|
-
- spec/code/parser/function_spec.rb
|
227
|
-
- spec/code/parser/group_spec.rb
|
228
|
-
- spec/code/parser/if_modifier_spec.rb
|
229
|
-
- spec/code/parser/list_spec.rb
|
230
|
-
- spec/code/parser/number_spec.rb
|
231
|
-
- spec/code/parser/string_spec.rb
|
232
|
-
- spec/code/parser_spec.rb
|
233
|
-
- spec/code/type_spec.rb
|
234
|
-
- spec/code_spec.rb
|
235
|
-
- spec/spec_helper.rb
|
213
|
+
test_files: []
|