...
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
module client
|
||||
|
||||
import os
|
||||
|
||||
// // extract_image_links extracts image file names from markdown content
|
||||
// // If exclude_http is true, it will skip images with http:// or https:// URLs
|
||||
// pub fn extract_image_links(s string, exclude_http bool) ![]string {
|
||||
// mut result := []string{}
|
||||
// mut current_pos := 0
|
||||
// for {
|
||||
// if current_pos >= s.len {
|
||||
// break
|
||||
// }
|
||||
|
||||
// // Find the start of an image markdown link
|
||||
// start_index := s.index_after('![', current_pos) or { -1 }
|
||||
// if start_index == -1 {
|
||||
// break // No more image links found
|
||||
// }
|
||||
|
||||
// // Find the closing bracket for alt text
|
||||
// alt_end_index := s.index_after(']', start_index) or { -1 }
|
||||
// if alt_end_index == -1 {
|
||||
// break
|
||||
// }
|
||||
|
||||
// // Check for opening parenthesis for URL
|
||||
// if alt_end_index + 1 >= s.len || s[alt_end_index + 1] != `(` {
|
||||
// current_pos = alt_end_index + 1 // Move past this invalid sequence
|
||||
// continue
|
||||
// }
|
||||
|
||||
// // Find the closing parenthesis for URL
|
||||
// url_start_index := alt_end_index + 2
|
||||
// url_end_index := s.index_after(')', url_start_index) or { -1 }
|
||||
// if url_end_index == -1 {
|
||||
// break
|
||||
// }
|
||||
|
||||
// // Extract the URL
|
||||
// url := s[url_start_index..url_end_index]
|
||||
// if exclude_http && (url.starts_with('http://') || url.starts_with('https://')) {
|
||||
// current_pos = url_end_index + 1
|
||||
// continue
|
||||
// }
|
||||
|
||||
// // Extract only the base name of the image from the URL
|
||||
// image_base_name := os.base(url)
|
||||
// result << image_base_name
|
||||
|
||||
// // Move current_pos past the found link to continue searching
|
||||
// current_pos = url_end_index + 1
|
||||
// }
|
||||
// return result
|
||||
// }
|
||||
@@ -1,298 +0,0 @@
|
||||
module client
|
||||
|
||||
// // Test basic image link extraction
|
||||
// fn test_extract_image_links_basic() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'image.png'
|
||||
// }
|
||||
|
||||
// // Test multiple image links
|
||||
// fn test_extract_image_links_multiple() {
|
||||
// content := ' some text  more text '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'logo.png'
|
||||
// assert result[1] == 'banner.jpg'
|
||||
// assert result[2] == 'icon.svg'
|
||||
// }
|
||||
|
||||
// // Test empty content
|
||||
// fn test_extract_image_links_empty() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test content with no images
|
||||
// fn test_extract_image_links_no_images() {
|
||||
// content := 'This is just plain text with no images'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test content with regular links (not images)
|
||||
// fn test_extract_image_links_regular_links() {
|
||||
// content := '[regular link](page.md) and [another](doc.html)'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test HTTP URLs with exclude_http = true
|
||||
// fn test_extract_image_links_exclude_http() {
|
||||
// content := '  '
|
||||
// result := extract_image_links(content, true) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'local.png'
|
||||
// }
|
||||
|
||||
// // Test HTTP URLs with exclude_http = false
|
||||
// fn test_extract_image_links_include_http() {
|
||||
// content := '  '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'local.png'
|
||||
// assert result[1] == 'image.jpg'
|
||||
// assert result[2] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test image paths with directories
|
||||
// fn test_extract_image_links_with_paths() {
|
||||
// content := '  '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'logo.png'
|
||||
// assert result[1] == 'banner.jpg'
|
||||
// assert result[2] == 'icon.svg'
|
||||
// }
|
||||
|
||||
// // Test various image formats
|
||||
// fn test_extract_image_links_formats() {
|
||||
// content := '      '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 7
|
||||
// assert 'img.png' in result
|
||||
// assert 'img.jpg' in result
|
||||
// assert 'img.jpeg' in result
|
||||
// assert 'img.gif' in result
|
||||
// assert 'img.svg' in result
|
||||
// assert 'img.webp' in result
|
||||
// assert 'img.bmp' in result
|
||||
// }
|
||||
|
||||
// // Test malformed markdown - missing closing bracket
|
||||
// fn test_extract_image_links_malformed_no_closing_bracket() {
|
||||
// content := '![alt text(image.png)'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test malformed markdown - missing opening parenthesis
|
||||
// fn test_extract_image_links_malformed_no_paren() {
|
||||
// content := '![alt text]image.png)'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test malformed markdown - missing closing parenthesis
|
||||
// fn test_extract_image_links_malformed_no_closing_paren() {
|
||||
// content := ' or { panic(err) }
|
||||
|
||||
// assert result.len == 0
|
||||
// }
|
||||
|
||||
// // Test empty alt text
|
||||
// fn test_extract_image_links_empty_alt() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'image.png'
|
||||
// }
|
||||
|
||||
// // Test alt text with special characters
|
||||
// fn test_extract_image_links_special_alt() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test image names with special characters
|
||||
// fn test_extract_image_links_special_names() {
|
||||
// content := '  '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'logo-2024.png'
|
||||
// assert result[1] == 'banner_v2.jpg'
|
||||
// assert result[2] == 'icon.final.svg'
|
||||
// }
|
||||
|
||||
// // Test mixed content with text, links, and images
|
||||
// fn test_extract_image_links_mixed_content() {
|
||||
// content := '
|
||||
// # Header
|
||||
|
||||
// Some text with [a link](page.md) and an image .
|
||||
|
||||
// ## Section
|
||||
|
||||
// More text and  another image.
|
||||
|
||||
// [Another link](doc.html)
|
||||
|
||||
// 
|
||||
// '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'logo.png'
|
||||
// assert result[1] == 'banner.jpg'
|
||||
// assert result[2] == 'icon.svg'
|
||||
// }
|
||||
|
||||
// // Test consecutive images
|
||||
// fn test_extract_image_links_consecutive() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'a.png'
|
||||
// assert result[1] == 'b.jpg'
|
||||
// assert result[2] == 'c.svg'
|
||||
// }
|
||||
|
||||
// // Test images with query parameters
|
||||
// fn test_extract_image_links_query_params() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// // Should extract the full filename including query params
|
||||
// assert result[0].contains('image.png')
|
||||
// }
|
||||
|
||||
// // Test images with anchors
|
||||
// fn test_extract_image_links_anchors() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0].contains('image.png')
|
||||
// }
|
||||
|
||||
// // Test duplicate images
|
||||
// fn test_extract_image_links_duplicates() {
|
||||
// content := ' some text  more text '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'logo.png'
|
||||
// assert result[1] == 'logo.png'
|
||||
// assert result[2] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test very long content
|
||||
// fn test_extract_image_links_long_content() {
|
||||
// mut content := ''
|
||||
// for i in 0 .. 100 {
|
||||
// content += 'Some text here. '
|
||||
// if i % 10 == 0 {
|
||||
// content += ' '
|
||||
// }
|
||||
// }
|
||||
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
// assert result.len == 10
|
||||
// }
|
||||
|
||||
// // Test image with absolute path
|
||||
// fn test_extract_image_links_absolute_path() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'image.png'
|
||||
// }
|
||||
|
||||
// // Test image with Windows-style path
|
||||
// fn test_extract_image_links_windows_path() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test nested brackets in alt text
|
||||
// fn test_extract_image_links_nested_brackets() {
|
||||
// content := '![alt [with] brackets](image.png)'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// // This might not work correctly due to nested brackets
|
||||
// // The function should handle it gracefully
|
||||
// assert result.len >= 0
|
||||
// }
|
||||
|
||||
// // Test image link at start of string
|
||||
// fn test_extract_image_links_at_start() {
|
||||
// content := ' followed by text'
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test image link at end of string
|
||||
// fn test_extract_image_links_at_end() {
|
||||
// content := 'text followed by '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test only image link
|
||||
// fn test_extract_image_links_only() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// assert result[0] == 'logo.png'
|
||||
// }
|
||||
|
||||
// // Test whitespace in URL
|
||||
// fn test_extract_image_links_whitespace() {
|
||||
// content := ''
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 1
|
||||
// // Should preserve whitespace as-is
|
||||
// assert result[0].contains('image.png')
|
||||
// }
|
||||
|
||||
// // Test case sensitivity
|
||||
// fn test_extract_image_links_case_sensitivity() {
|
||||
// content := '  '
|
||||
// result := extract_image_links(content, false) or { panic(err) }
|
||||
|
||||
// assert result.len == 3
|
||||
// assert result[0] == 'Image.PNG'
|
||||
// assert result[1] == 'LOGO.jpg'
|
||||
// assert result[2] == 'banner.SVG'
|
||||
// }
|
||||
Reference in New Issue
Block a user