53 lines
2.1 KiB
Dart
53 lines
2.1 KiB
Dart
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
group('URL Extraction from HTML', () {
|
|
|
|
test('should extract URL from HTML anchor tag', () {
|
|
// Access the private method through reflection or create a test helper
|
|
// For now, let's test the functionality indirectly by testing the regex pattern
|
|
final input = '<a href="https://www.youtube.com/watch?v=dpx6L15oA4k">https://www.youtube.com/watch?v=dpx6L15oA4k</a>';
|
|
final aTagRegex = RegExp(r'<a\s+href="([^"]+)"[^>]*>.*?</a>', caseSensitive: false);
|
|
final match = aTagRegex.firstMatch(input);
|
|
|
|
expect(match, isNotNull);
|
|
expect(match!.group(1), equals('https://www.youtube.com/watch?v=dpx6L15oA4k'));
|
|
});
|
|
|
|
test('should return original string if not HTML anchor tag', () {
|
|
final input = 'https://www.youtube.com/watch?v=dpx6L15oA4k';
|
|
final aTagRegex = RegExp(r'<a\s+href="([^"]+)"[^>]*>.*?</a>', caseSensitive: false);
|
|
final match = aTagRegex.firstMatch(input);
|
|
|
|
expect(match, isNull);
|
|
});
|
|
|
|
test('should handle various HTML anchor tag formats', () {
|
|
final testCases = [
|
|
'<a href="https://example.com">Link</a>',
|
|
'<a href="https://example.com" target="_blank">Link</a>',
|
|
'<A HREF="https://example.com">Link</A>',
|
|
'<a href="https://example.com" class="link">Link Text</a>',
|
|
];
|
|
|
|
final aTagRegex = RegExp(r'<a\s+href="([^"]+)"[^>]*>.*?</a>', caseSensitive: false);
|
|
|
|
for (final testCase in testCases) {
|
|
final match = aTagRegex.firstMatch(testCase);
|
|
expect(match, isNotNull, reason: 'Failed to match: $testCase');
|
|
expect(match!.group(1), equals('https://example.com'));
|
|
}
|
|
});
|
|
|
|
test('should handle empty or whitespace input', () {
|
|
final testCases = ['', ' ', '\t\n'];
|
|
final aTagRegex = RegExp(r'<a\s+href="([^"]+)"[^>]*>.*?</a>', caseSensitive: false);
|
|
|
|
for (final testCase in testCases) {
|
|
final match = aTagRegex.firstMatch(testCase.trim());
|
|
expect(match, isNull, reason: 'Should not match empty/whitespace: "$testCase"');
|
|
}
|
|
});
|
|
});
|
|
}
|