From ea6970995987b6618dd9325b68f625e065c55d8e Mon Sep 17 00:00:00 2001 From: Athish Pranav D Date: Wed, 7 Aug 2024 10:35:29 +0530 Subject: [PATCH] Added UTs for the String interpolation in Hash and array forms Signed-off-by: Athish Pranav D --- test/config/test_literal_parser.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/config/test_literal_parser.rb b/test/config/test_literal_parser.rb index 9f6130ff2a..c5b9b18898 100644 --- a/test/config/test_literal_parser.rb +++ b/test/config/test_literal_parser.rb @@ -259,6 +259,17 @@ def test_falseX test('[ "a" , "b" ]') { assert_text_parsed_as_json(["a","b"], '[ "a" , "b" ]') } test("[\n\"a\"\n,\n\"b\"\n]") { assert_text_parsed_as_json(["a","b"], "[\n\"a\"\n,\n\"b\"\n]") } test('["ab","cd"]') { assert_text_parsed_as_json(["ab","cd"], '["ab","cd"]') } + test('["a","#{v1}"') { assert_text_parsed_as_json(["a","#{v1}"], '["a","#{v1}"]') } + test('["a","#{v1}","#{v2}"]') { assert_text_parsed_as_json(["a","#{v1}","#{v2}"], '["a","#{v1}","#{v2}"]') } + test('["a","#{v1} #{v2}"]') { assert_text_parsed_as_json(["a","#{v1} #{v2}"], '["a","#{v1} #{v2}"]') } + test('["a","#{hostname}"]') { assert_text_parsed_as_json(["a","#{Socket.gethostname}"], '["a","#{hostname}"]') } + test('["a","foo#{worker_id}"]') { + ENV.delete('SERVERENGINE_WORKER_ID') + assert_text_parsed_as('["a","foo"]', '["a","foo#{worker_id}"]') + ENV['SERVERENGINE_WORKER_ID'] = '1' + assert_text_parsed_as('["a","foo1"]', '["a","foo#{worker_id}"]') + ENV.delete('SERVERENGINE_WORKER_ID') + } json_array_with_js_comment = <"b","c"=>"d"}, '{"a":"b","c":"d"}') } test('{ "a" : "b" , "c" : "d" }') { assert_text_parsed_as_json({"a"=>"b","c"=>"d"}, '{ "a" : "b" , "c" : "d" }') } test('{\n\"a\"\n:\n\"b\"\n,\n\"c\"\n:\n\"d\"\n}') { assert_text_parsed_as_json({"a"=>"b","c"=>"d"}, "{\n\"a\"\n:\n\"b\"\n,\n\"c\"\n:\n\"d\"\n}") } + test('{"a":"b","c":"#{v1}"}') { assert_text_parsed_as_json({"a"=>"b","c"=>"#{v1}"}, '{"a":"b","c":"#{v1}"}') } + test('{"a":"b","#{v1}":"d"}') { assert_text_parsed_as_json({"a"=>"b","#{v1}"=>"d"}, '{"a":"b","#{v1}":"d"}') } + test('{"a":"#{v1}","c":"#{v2}"}') { assert_text_parsed_as_json({"a"=>"#{v1}","c"=>"#{v2}"}, '{"a":"#{v1}","c":"#{v2}"}') } + test('{"a":"b","c":"d #{v1} #{v2}"}') { assert_text_parsed_as_json({"a"=>"b","c"=>"d #{v1} #{v2}"}, '{"a":"b","c":"d #{v1} #{v2}"}') } + test('{"a":"#{hostname}"}') { assert_text_parsed_as_json({"a"=>"#{Socket.gethostname}"}, '{"a":"#{hostname}"}') } + test('{"a":"foo#{worker_id}"}') { + ENV.delete('SERVERENGINE_WORKER_ID') + assert_text_parsed_as('{"a":"foo"}', '{"a":"foo#{worker_id}"}') + ENV['SERVERENGINE_WORKER_ID'] = '1' + assert_text_parsed_as('{"a":"foo1"}', '{"a":"foo#{worker_id}"}') + ENV.delete('SERVERENGINE_WORKER_ID') + } json_hash_with_comment = <