mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-04-26 22:39:48 +08:00
feat: add XML and HTML formatting support (#721)
This commit is contained in:
43
test/html_format_test.dart
Normal file
43
test/html_format_test.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:proxypin/network/http/content_type.dart';
|
||||
import 'package:proxypin/network/http/http.dart';
|
||||
import 'package:proxypin/utils/html_formatter.dart';
|
||||
|
||||
void main() {
|
||||
test('HTML.pretty formats nested markup', () {
|
||||
const input = '<div><h1>Hello</h1><p>World <strong>!</strong></p></div>';
|
||||
|
||||
expect(
|
||||
HTML.pretty(input),
|
||||
'<div>\n'
|
||||
' <h1>Hello</h1>\n'
|
||||
' <p>\n'
|
||||
' World\n'
|
||||
' <strong>!</strong>\n'
|
||||
' </p>\n'
|
||||
'</div>',
|
||||
);
|
||||
});
|
||||
|
||||
test('HTML.pretty tolerates malformed HTML', () {
|
||||
const input = '<div><span>hello</div>';
|
||||
|
||||
expect(
|
||||
HTML.pretty(input),
|
||||
'<div>\n'
|
||||
' <span>hello</span>\n'
|
||||
'</div>',
|
||||
);
|
||||
});
|
||||
|
||||
test('HTML.pretty leaves plain text unchanged', () {
|
||||
expect(HTML.pretty('plain text body'), 'plain text body');
|
||||
});
|
||||
|
||||
test('xhtml content type maps to html', () {
|
||||
final response = HttpResponse(HttpStatus.ok);
|
||||
response.headers.set('content-type', 'application/xhtml+xml; charset=utf-8');
|
||||
|
||||
expect(response.contentType, ContentType.html);
|
||||
});
|
||||
}
|
||||
46
test/xml_format_test.dart
Normal file
46
test/xml_format_test.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:proxypin/network/http/content_type.dart';
|
||||
import 'package:proxypin/network/http/http.dart';
|
||||
import 'package:proxypin/utils/xml_formatter.dart';
|
||||
|
||||
void main() {
|
||||
test('XML.pretty formats nested document', () {
|
||||
const input = '<root><a>1</a><b><c>2</c></b></root>';
|
||||
|
||||
expect(
|
||||
XML.pretty(input),
|
||||
'<root>\n'
|
||||
' <a>1</a>\n'
|
||||
' <b>\n'
|
||||
' <c>2</c>\n'
|
||||
' </b>\n'
|
||||
'</root>',
|
||||
);
|
||||
});
|
||||
|
||||
test('XML.pretty falls back for malformed XML', () {
|
||||
const input = '<root><a></root>';
|
||||
expect(XML.pretty(input), input);
|
||||
});
|
||||
|
||||
test('xml content types map to ContentType.xml', () {
|
||||
final response = HttpResponse(HttpStatus.ok);
|
||||
|
||||
response.headers.set('content-type', 'application/xml; charset=utf-8');
|
||||
expect(response.contentType, ContentType.xml);
|
||||
|
||||
response.headers.set('content-type', 'text/xml; charset=utf-8');
|
||||
expect(response.contentType, ContentType.xml);
|
||||
|
||||
response.headers.set('content-type', 'application/soap+xml; charset=utf-8');
|
||||
expect(response.contentType, ContentType.xml);
|
||||
});
|
||||
|
||||
test('xhtml keeps html content type', () {
|
||||
final response = HttpResponse(HttpStatus.ok);
|
||||
response.headers.set('content-type', 'application/xhtml+xml; charset=utf-8');
|
||||
|
||||
expect(response.contentType, ContentType.html);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user