feat: Support atlas_client module:
- Add client for atlas module - Add unit tests to test the workflow - Remove println statements from file_or_image_exists - Remove println statements from link processing loop
This commit is contained in:
298
lib/web/atlas_client/extract_links_test.v
Normal file
298
lib/web/atlas_client/extract_links_test.v
Normal file
@@ -0,0 +1,298 @@
|
||||
module atlas_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