properly enclose strings in ""

This commit is contained in:
Gwenhael Le Moine 2021-12-15 16:34:57 +01:00
parent f234dffa59
commit 90415fc07e
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 10 additions and 10 deletions

View file

@ -10,7 +10,7 @@ module Rpl
stack, args = Rpl::Lang::Core.stack_extract( stack, [:any] )
stack << { type: :string,
value: args[0][:value].to_s }
value: "\"#{args[0][:value]}\"" }
[stack, dictionary]
end
@ -31,7 +31,7 @@ module Rpl
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric]] )
stack << { type: :string,
value: args[0][:value].chr }
value: "\"#{args[0][:value].chr}\"" }
[stack, dictionary]
end
@ -74,7 +74,7 @@ module Rpl
stack, args = Rpl::Lang::Core.stack_extract( stack, [%i[numeric], %i[numeric], %i[string]] )
stack << { type: :string,
value: args[2][:value][args[1][:value]..args[0][:value]] }
value: "\"#{args[2][:value][args[1][:value]..args[0][:value]]}\"" }
[stack, dictionary]
end

View file

@ -10,7 +10,7 @@ module Rpl
# time in local format
def time( stack, dictionary )
stack << { type: :string,
value: Time.now.to_s }
value: "\"#{Time.now}\"" }
[stack, dictionary]
end
@ -18,7 +18,7 @@ module Rpl
# date in local format
def date( stack, dictionary )
stack << { type: :string,
value: Date.today.to_s }
value: "\"#{Date.today}\"" }
[stack, dictionary]
end

View file

@ -10,7 +10,7 @@ class TestLanguageString < Test::Unit::TestCase
lang = Rpl::Language.new
lang.run '2 →str'
assert_equal [{ value: '2', type: :string }],
assert_equal [{ value: '"2"', type: :string }],
lang.stack
end
@ -34,7 +34,7 @@ class TestLanguageString < Test::Unit::TestCase
lang = Rpl::Language.new
lang.run '71 chr'
assert_equal [{ value: 'G', type: :string }],
assert_equal [{ value: '"G"', type: :string }],
lang.stack
end
@ -66,7 +66,7 @@ class TestLanguageString < Test::Unit::TestCase
lang = Rpl::Language.new
lang.run '"my string to sub" 4 6 sub'
assert_equal [{ value: 'str', type: :string }],
assert_equal [{ value: '"str"', type: :string }],
lang.stack
end

View file

@ -11,7 +11,7 @@ class TestLanguageTimeDate < Test::Unit::TestCase
lang = Rpl::Language.new
lang.run 'time'
assert_equal [{ value: now, type: :string }],
assert_equal [{ value: "\"#{now}\"", type: :string }],
lang.stack
end
@ -20,7 +20,7 @@ class TestLanguageTimeDate < Test::Unit::TestCase
lang = Rpl::Language.new
lang.run 'date'
assert_equal [{ value: now, type: :string }],
assert_equal [{ value: "\"#{now}\"", type: :string }],
lang.stack
end