Skip to content

Commit 206d3d9

Browse files
committed
Format Dart code and add format script
- Ran 'dart format' on lib/ and test/ directories - Formatted 8 test files with proper Dart code style - Added scripts/format.sh for consistent formatting - All Dart code now follows official Dart style guidelines Files formatted: - test/extensions/string_test.dart - test/extensions/uri_test.dart - test/http/http_methods_test.dart - test/http/intercepted_client_test.dart - test/models/http_interceptor_exception_test.dart - test/models/interceptor_contract_test.dart - test/models/retry_policy_test.dart - test/utils/query_parameters_test.dart
1 parent c908331 commit 206d3d9

File tree

9 files changed

+552
-366
lines changed

9 files changed

+552
-366
lines changed

scripts/format.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Format script for HTTP Interceptor library
4+
# Only formats lib/ and test/ directories to avoid SDK file issues
5+
6+
set -e
7+
8+
echo "🎯 Formatting Dart code in lib/ and test/ directories..."
9+
10+
# Check if dart is available
11+
if ! command -v dart &> /dev/null; then
12+
echo "❌ Error: dart command not found"
13+
echo "Please ensure Dart SDK is installed and available in PATH"
14+
exit 1
15+
fi
16+
17+
# Format lib directory
18+
if [ -d "lib" ]; then
19+
echo "📁 Formatting lib/ directory..."
20+
dart format lib/ --set-exit-if-changed
21+
lib_status=$?
22+
else
23+
echo "⚠️ Warning: lib/ directory not found"
24+
lib_status=0
25+
fi
26+
27+
# Format test directory
28+
if [ -d "test" ]; then
29+
echo "📁 Formatting test/ directory..."
30+
dart format test/ --set-exit-if-changed
31+
test_status=$?
32+
else
33+
echo "⚠️ Warning: test/ directory not found"
34+
test_status=0
35+
fi
36+
37+
# Check results
38+
if [ $lib_status -eq 0 ] && [ $test_status -eq 0 ]; then
39+
echo "✅ All Dart files are properly formatted!"
40+
exit 0
41+
else
42+
echo "❌ Some files were not properly formatted"
43+
echo "Files have been reformatted. Please review and commit the changes."
44+
exit 1
45+
fi

test/extensions/string_test.dart

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ void main() {
66
test('should convert valid URL string to URI', () {
77
const urlString = 'https://example.com';
88
final uri = urlString.toUri();
9-
9+
1010
expect(uri, isA<Uri>());
1111
expect(uri.toString(), equals(urlString));
1212
});
1313

1414
test('should convert URL with path to URI', () {
1515
const urlString = 'https://example.com/api/v1/users';
1616
final uri = urlString.toUri();
17-
17+
1818
expect(uri, isA<Uri>());
1919
expect(uri.scheme, equals('https'));
2020
expect(uri.host, equals('example.com'));
@@ -24,7 +24,7 @@ void main() {
2424
test('should convert URL with query parameters to URI', () {
2525
const urlString = 'https://example.com/search?q=test&limit=10';
2626
final uri = urlString.toUri();
27-
27+
2828
expect(uri, isA<Uri>());
2929
expect(uri.scheme, equals('https'));
3030
expect(uri.host, equals('example.com'));
@@ -36,7 +36,7 @@ void main() {
3636
test('should convert URL with fragment to URI', () {
3737
const urlString = 'https://example.com/page#section';
3838
final uri = urlString.toUri();
39-
39+
4040
expect(uri, isA<Uri>());
4141
expect(uri.scheme, equals('https'));
4242
expect(uri.host, equals('example.com'));
@@ -47,7 +47,7 @@ void main() {
4747
test('should convert URL with port to URI', () {
4848
const urlString = 'https://example.com:8080/api';
4949
final uri = urlString.toUri();
50-
50+
5151
expect(uri, isA<Uri>());
5252
expect(uri.scheme, equals('https'));
5353
expect(uri.host, equals('example.com'));
@@ -58,7 +58,7 @@ void main() {
5858
test('should convert URL with userinfo to URI', () {
5959
const urlString = 'https://user:[email protected]/secure';
6060
final uri = urlString.toUri();
61-
61+
6262
expect(uri, isA<Uri>());
6363
expect(uri.scheme, equals('https'));
6464
expect(uri.host, equals('example.com'));
@@ -73,7 +73,7 @@ void main() {
7373
'ftp://example.com',
7474
'file:///path/to/file',
7575
];
76-
76+
7777
for (final urlString in testUrls) {
7878
final uri = urlString.toUri();
7979
expect(uri, isA<Uri>());
@@ -82,9 +82,10 @@ void main() {
8282
});
8383

8484
test('should handle complex query parameters', () {
85-
const urlString = 'https://example.com/api?name=John%20Doe&age=30&tags=red,blue,green&special=!@#';
85+
const urlString =
86+
'https://example.com/api?name=John%20Doe&age=30&tags=red,blue,green&special=!@#';
8687
final uri = urlString.toUri();
87-
88+
8889
expect(uri, isA<Uri>());
8990
expect(uri.queryParameters['name'], equals('John Doe'));
9091
expect(uri.queryParameters['age'], equals('30'));
@@ -97,7 +98,7 @@ void main() {
9798
'not a url',
9899
'ftp://invalid space',
99100
];
100-
101+
101102
for (final invalidUrl in invalidUrls) {
102103
final uri = invalidUrl.toUri();
103104
expect(uri, isA<Uri>());
@@ -116,15 +117,15 @@ void main() {
116117
test('should handle empty string', () {
117118
const emptyString = '';
118119
final uri = emptyString.toUri();
119-
120+
120121
expect(uri, isA<Uri>());
121122
expect(uri.toString(), equals(''));
122123
});
123124

124125
test('should handle file URLs', () {
125126
const fileUrl = 'file:///home/user/document.txt';
126127
final uri = fileUrl.toUri();
127-
128+
128129
expect(uri, isA<Uri>());
129130
expect(uri.scheme, equals('file'));
130131
expect(uri.path, equals('/home/user/document.txt'));
@@ -133,7 +134,7 @@ void main() {
133134
test('should handle relative URLs', () {
134135
const relativeUrl = '/api/users';
135136
final uri = relativeUrl.toUri();
136-
137+
137138
expect(uri, isA<Uri>());
138139
expect(uri.path, equals('/api/users'));
139140
expect(uri.scheme, isEmpty);
@@ -142,7 +143,7 @@ void main() {
142143
test('should handle query-only URLs', () {
143144
const queryUrl = '?q=search&page=1';
144145
final uri = queryUrl.toUri();
145-
146+
146147
expect(uri, isA<Uri>());
147148
expect(uri.query, equals('q=search&page=1'));
148149
expect(uri.queryParameters['q'], equals('search'));
@@ -152,15 +153,16 @@ void main() {
152153
test('should handle fragment-only URLs', () {
153154
const fragmentUrl = '#section-1';
154155
final uri = fragmentUrl.toUri();
155-
156+
156157
expect(uri, isA<Uri>());
157158
expect(uri.fragment, equals('section-1'));
158159
});
159160

160161
test('should handle URLs with encoded characters', () {
161-
const encodedUrl = 'https://example.com/path%20with%20spaces?param=value%20with%20spaces';
162+
const encodedUrl =
163+
'https://example.com/path%20with%20spaces?param=value%20with%20spaces';
162164
final uri = encodedUrl.toUri();
163-
165+
164166
expect(uri, isA<Uri>());
165167
expect(uri.path, equals('/path with spaces'));
166168
expect(uri.queryParameters['param'], equals('value with spaces'));
@@ -169,17 +171,19 @@ void main() {
169171
test('should handle URLs with international domain names', () {
170172
const idnUrl = 'https://例え.テスト/path';
171173
final uri = idnUrl.toUri();
172-
174+
173175
expect(uri, isA<Uri>());
174176
expect(uri.scheme, equals('https'));
175177
expect(uri.host, equals('例え.テスト'));
176178
expect(uri.path, equals('/path'));
177179
});
178180

179-
test('should handle URLs with multiple query parameters with same name', () {
180-
const multiParamUrl = 'https://example.com/search?tag=red&tag=blue&tag=green';
181+
test('should handle URLs with multiple query parameters with same name',
182+
() {
183+
const multiParamUrl =
184+
'https://example.com/search?tag=red&tag=blue&tag=green';
181185
final uri = multiParamUrl.toUri();
182-
186+
183187
expect(uri, isA<Uri>());
184188
expect(uri.query, equals('tag=red&tag=blue&tag=green'));
185189
// Note: queryParameters only returns the last value for duplicate keys
@@ -194,11 +198,11 @@ void main() {
194198
'tel:+1234567890',
195199
'data:text/plain;base64,SGVsbG8gV29ybGQ=',
196200
];
197-
201+
198202
for (final urlString in testUrls) {
199203
final uriFromExtension = urlString.toUri();
200204
final uriFromParse = Uri.parse(urlString);
201-
205+
202206
expect(uriFromExtension.toString(), equals(uriFromParse.toString()));
203207
expect(uriFromExtension.scheme, equals(uriFromParse.scheme));
204208
expect(uriFromExtension.host, equals(uriFromParse.host));

0 commit comments

Comments
 (0)