Files
pkgs.lux/packages/rss/test_rss.lux
Brandon Lucas cbb66fbb73 Add frontmatter, markdown, path, xml, rss, and web packages
Sync local packages into the registry repo and update index.json
and README.md to include all 9 packages.
2026-02-24 21:04:20 -05:00

68 lines
3.3 KiB
Plaintext

import lib
fn contains(haystack: String, needle: String): Bool =
match String.indexOf(haystack, needle) {
Some(_) => true,
None => false,
}
fn test_create_item(): Unit with {Test} = {
let i = lib.item("My Post", "https://example.com/post", "A description", "2025-01-29")
Test.assertEqualMsg("My Post", lib.itemTitle(i), "item title")
Test.assertEqualMsg("https://example.com/post", lib.itemLink(i), "item link")
Test.assertEqualMsg("A description", lib.itemDescription(i), "item description")
Test.assertEqualMsg("2025-01-29", lib.itemPubDate(i), "item pubDate")
Test.assertEqualMsg("https://example.com/post", lib.itemGuid(i), "item guid defaults to link")
}
fn test_item_with_guid(): Unit with {Test} = {
let i = lib.itemWithGuid("Post", "https://example.com", "Desc", "2025-01-29", "custom-guid-123")
Test.assertEqualMsg("custom-guid-123", lib.itemGuid(i), "item custom guid")
}
fn test_date_conversion(): Unit with {Test} = {
Test.assertEqualMsg("29 Jan 2025 00:00:00 GMT", lib.isoToRfc822("2025-01-29"), "date jan")
Test.assertEqualMsg("31 Dec 2025 00:00:00 GMT", lib.isoToRfc822("2025-12-31"), "date dec")
Test.assertEqualMsg("15 Jun 2025 00:00:00 GMT", lib.isoToRfc822("2025-06-15"), "date jun")
Test.assertEqualMsg("bad", lib.isoToRfc822("bad"), "date short string passthrough")
}
fn test_empty_feed(): Unit with {Test} = {
let emptyFeed = lib.feed("My Blog", "https://example.com", "Blog about things", [])
let xml = lib.render(emptyFeed)
Test.assert(contains(xml, "<?xml version=\"1.0\""), "xml declaration")
Test.assert(contains(xml, "<rss version=\"2.0\""), "rss tag")
Test.assert(contains(xml, "<title>My Blog</title>"), "feed title")
Test.assert(contains(xml, "<link>https://example.com</link>"), "feed link")
Test.assert(contains(xml, "<description>Blog about things</description>"), "feed description")
Test.assert(contains(xml, "<language>en</language>"), "feed language")
}
fn test_feed_with_items(): Unit with {Test} = {
let items = [
lib.item("First Post", "https://example.com/first", "First!", "2025-01-29"),
lib.item("Second Post", "https://example.com/second", "Second!", "2025-02-01")
]
let fullFeed = lib.feed("Blog", "https://example.com", "A blog", items)
let xml = lib.render(fullFeed)
Test.assert(contains(xml, "<item>"), "has item tag")
Test.assert(contains(xml, "<title>First Post</title>"), "first item title")
Test.assert(contains(xml, "<title>Second Post</title>"), "second item title")
Test.assert(contains(xml, "29 Jan 2025 00:00:00 GMT"), "rfc822 date in feed")
Test.assert(contains(xml, "<guid isPermaLink=\"true\">"), "guid with permalink")
}
fn test_feed_with_language(): Unit with {Test} = {
let frFeed = lib.feedWithLang("Mon Blog", "https://example.fr", "Un blog", "fr", [])
let xml = lib.render(frFeed)
Test.assert(contains(xml, "<language>fr</language>"), "custom language")
}
fn test_special_characters(): Unit with {Test} = {
let specialItem = lib.item("A & B <C>", "https://example.com", "\"quoted\" & <tagged>", "2025-01-01")
let specialFeed = lib.feed("Test", "https://example.com", "Test", [specialItem])
let xml = lib.render(specialFeed)
Test.assert(contains(xml, "&amp;"), "ampersand escaped")
Test.assert(contains(xml, "&lt;"), "angle bracket escaped")
}