Add support comments in JSON request body #599

This commit is contained in:
FreeBono
2025-02-25 21:38:05 +09:00
parent 5245052d6c
commit 4da5a49f44
5 changed files with 141 additions and 58 deletions

View File

@@ -306,4 +306,65 @@ Easily manipulate and play around with request inputs like headers, query parame
expect(audioPosition(dur4), dur4Expected);
});
});
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);
});
});
}