import lib
fn contains(haystack: String, needle: String): Bool =
match String.indexOf(haystack, needle) {
Some(_) => true,
None => false,
}
// Build a complete blog RSS feed with multiple posts
fn test_full_blog_feed(): Unit with {Test} = {
let items = [
lib.item("Getting Started with Lux", "https://blog.example.com/getting-started", "Learn the basics of the Lux programming language", "2025-01-15"),
lib.item("Advanced Effects in Lux", "https://blog.example.com/advanced-effects", "Deep dive into algebraic effects", "2025-02-01"),
lib.item("Building a Static Site", "https://blog.example.com/static-site", "Create a blog with Lux", "2025-02-15")
]
let f = lib.feed("Lux Programming Blog", "https://blog.example.com", "Tips and tutorials about Lux", items)
let xml = lib.render(f)
Test.assert(contains(xml, "Lux Programming Blog"), "feed title")
Test.assert(contains(xml, "https://blog.example.com"), "feed link")
Test.assert(contains(xml, "
Getting Started with Lux"), "first item title")
Test.assert(contains(xml, "Advanced Effects in Lux"), "second item title")
Test.assert(contains(xml, "Building a Static Site"), "third item title")
Test.assert(contains(xml, "15 Jan 2025 00:00:00 GMT"), "first item date in RFC 822")
Test.assert(contains(xml, "01 Feb 2025 00:00:00 GMT"), "second item date in RFC 822")
Test.assert(contains(xml, "Lux RSS Package"), "has generator tag")
}
// Feed with items containing custom GUIDs
fn test_feed_with_custom_guids(): Unit with {Test} = {
let items = [
lib.itemWithGuid("Post 1", "https://example.com/1", "Desc 1", "2025-01-01", "urn:uuid:1234"),
lib.itemWithGuid("Post 2", "https://example.com/2", "Desc 2", "2025-02-01", "urn:uuid:5678")
]
let f = lib.feed("Blog", "https://example.com", "A blog", items)
let xml = lib.render(f)
Test.assert(contains(xml, "urn:uuid:1234"), "first custom guid")
Test.assert(contains(xml, "urn:uuid:5678"), "second custom guid")
}
// Feed with special characters in all fields
fn test_feed_with_special_chars(): Unit with {Test} = {
let i = lib.item(
"Tom & Jerry's ",
"https://example.com/tom&jerry",
"A \"great\" show with ",
"2025-01-01"
)
let f = lib.feed(
"Kids' TV & More",
"https://example.com",
"Shows for ",
[i]
)
let xml = lib.render(f)
Test.assert(contains(xml, "&"), "ampersand escaped somewhere")
Test.assert(contains(xml, "<"), "angle bracket escaped somewhere")
}
// Multilingual feed
fn test_multilingual_feed(): Unit with {Test} = {
let f = lib.feedWithLang(
"Mon Blog",
"https://exemple.fr",
"Un blog en francais",
"fr",
[lib.item("Premier Article", "https://exemple.fr/premier", "Le debut", "2025-01-01")]
)
let xml = lib.render(f)
Test.assert(contains(xml, "fr"), "french language tag")
Test.assert(contains(xml, "Premier Article"), "french item title")
}
// Empty feed is still valid XML
fn test_empty_feed_structure(): Unit with {Test} = {
let f = lib.feed("Empty Blog", "https://example.com", "Nothing here yet", [])
let xml = lib.render(f)
Test.assert(contains(xml, ""), "has channel open")
Test.assert(contains(xml, ""), "has channel close")
Test.assert(contains(xml, ""), "has rss close")
Test.assert(contains(xml, "Empty Blog"), "has title")
}
// Feed with many items (stress test)
fn test_feed_many_items(): Unit with {Test} = {
let items = [
lib.item("Post 1", "https://example.com/1", "D1", "2025-01-01"),
lib.item("Post 2", "https://example.com/2", "D2", "2025-01-02"),
lib.item("Post 3", "https://example.com/3", "D3", "2025-01-03"),
lib.item("Post 4", "https://example.com/4", "D4", "2025-01-04"),
lib.item("Post 5", "https://example.com/5", "D5", "2025-01-05"),
lib.item("Post 6", "https://example.com/6", "D6", "2025-01-06"),
lib.item("Post 7", "https://example.com/7", "D7", "2025-01-07"),
lib.item("Post 8", "https://example.com/8", "D8", "2025-01-08"),
lib.item("Post 9", "https://example.com/9", "D9", "2025-01-09"),
lib.item("Post 10", "https://example.com/10", "D10", "2025-01-10")
]
let f = lib.feed("Big Blog", "https://example.com", "Many posts", items)
let xml = lib.render(f)
Test.assert(contains(xml, "Post 1"), "first item")
Test.assert(contains(xml, "Post 10"), "last item")
Test.assert(contains(xml, "10 Jan 2025"), "last item date")
}