From 58cfcff626ee7e4a042cc1a1f9f94df270727f54 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Sun, 15 Jun 2025 16:56:36 +0530 Subject: [PATCH] Create http_request_utils.dart --- .../test/utils/http_request_utils.dart | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 packages/apidash_core/test/utils/http_request_utils.dart diff --git a/packages/apidash_core/test/utils/http_request_utils.dart b/packages/apidash_core/test/utils/http_request_utils.dart new file mode 100644 index 00000000..a19ef8e8 --- /dev/null +++ b/packages/apidash_core/test/utils/http_request_utils.dart @@ -0,0 +1,74 @@ +import 'package:apidash_core/utils/http_request_utils.dart'; +import 'package:test/test.dart'; + +void main() { + group('Testing RemoveJsonComments', () { + test('Removes single-line comments', () { + String input = ''' + { + // This is a single-line comment + "key": "value" + } + '''; + + String expected = '''{ + "key": "value" +}'''; + expect(removeJsonComments(input), expected); + }); + + test('Removes multi-line comments', () { + String input = ''' + { + /* + This is a multi-line comment + */ + "key": "value" + } + '''; + + String expected = '''{ + "key": "value" +}'''; + expect(removeJsonComments(input), expected); + }); + + test('Handles valid JSON without comments', () { + String input = '{"key":"value"}'; + String expected = '''{ + "key": "value" +}'''; + expect(removeJsonComments(input), expected); + }); + + test('Returns original string if invalid JSON', () { + String input = '{key: value}'; + String expected = '{key: value}'; + expect(removeJsonComments(input), expected); + }); + + test('Removes trailing commas', () { + String input = ''' + { + "key1": "value1", + "key2": "value2", // trailing comma + } + '''; + + String expected = '''{ + "key1": "value1", + "key2": "value2" +}'''; + expect(removeJsonComments(input), expected); + }); + + test('Test blank json', () { + String input = ''' + {} + '''; + + String expected = '{}'; + expect(removeJsonComments(input), expected); + }); + }); +}