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.
This commit is contained in:
103
packages/rss/test_snapshot.lux
Normal file
103
packages/rss/test_snapshot.lux
Normal file
@@ -0,0 +1,103 @@
|
||||
import lib
|
||||
|
||||
fn contains(haystack: String, needle: String): Bool =
|
||||
match String.indexOf(haystack, needle) {
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
}
|
||||
|
||||
// Snapshot: complete single-item feed
|
||||
fn test_snapshot_single_item_feed(): Unit with {Test} = {
|
||||
let f = lib.feed(
|
||||
"My Blog",
|
||||
"https://example.com",
|
||||
"A personal blog",
|
||||
[lib.item("Hello World", "https://example.com/hello", "My first post", "2025-01-29")]
|
||||
)
|
||||
let xml = lib.render(f)
|
||||
// Verify exact structure of the feed
|
||||
Test.assert(String.startsWith(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"), "snap: XML declaration")
|
||||
Test.assert(contains(xml, "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"), "snap: RSS opening tag")
|
||||
Test.assert(contains(xml, "<channel>"), "snap: channel open")
|
||||
Test.assert(contains(xml, "<title>My Blog</title>"), "snap: feed title")
|
||||
Test.assert(contains(xml, "<link>https://example.com</link>"), "snap: feed link")
|
||||
Test.assert(contains(xml, "<description>A personal blog</description>"), "snap: feed desc")
|
||||
Test.assert(contains(xml, "<language>en</language>"), "snap: language")
|
||||
Test.assert(contains(xml, "<generator>Lux RSS Package</generator>"), "snap: generator")
|
||||
Test.assert(contains(xml, "<item>"), "snap: item open")
|
||||
Test.assert(contains(xml, "<title>Hello World</title>"), "snap: item title")
|
||||
Test.assert(contains(xml, "<link>https://example.com/hello</link>"), "snap: item link")
|
||||
Test.assert(contains(xml, "<description>My first post</description>"), "snap: item desc")
|
||||
Test.assert(contains(xml, "<pubDate>29 Jan 2025 00:00:00 GMT</pubDate>"), "snap: item pubDate")
|
||||
Test.assert(contains(xml, "<guid isPermaLink=\"true\">https://example.com/hello</guid>"), "snap: item guid")
|
||||
Test.assert(contains(xml, "</item>"), "snap: item close")
|
||||
Test.assert(contains(xml, "</channel></rss>"), "snap: channel and rss close")
|
||||
}
|
||||
|
||||
// Snapshot: empty feed
|
||||
fn test_snapshot_empty_feed(): Unit with {Test} = {
|
||||
let f = lib.feed("Empty", "https://example.com", "Nothing", [])
|
||||
let xml = lib.render(f)
|
||||
Test.assert(String.startsWith(xml, "<?xml version=\"1.0\""), "snap: starts with declaration")
|
||||
// Empty feed should have no <item> tags
|
||||
Test.assertEqualMsg(false, contains(xml, "<item>"), "snap: no item tags")
|
||||
Test.assert(contains(xml, "<title>Empty</title>"), "snap: title present")
|
||||
Test.assert(String.endsWith(xml, "</channel></rss>"), "snap: ends properly")
|
||||
}
|
||||
|
||||
// Snapshot: feed with custom language
|
||||
fn test_snapshot_french_feed(): Unit with {Test} = {
|
||||
let f = lib.feedWithLang("Blog Francais", "https://exemple.fr", "Un blog", "fr", [
|
||||
lib.item("Bonjour", "https://exemple.fr/bonjour", "Premier article", "2025-06-15")
|
||||
])
|
||||
let xml = lib.render(f)
|
||||
Test.assert(contains(xml, "<language>fr</language>"), "snap: french language")
|
||||
Test.assert(contains(xml, "<title>Bonjour</title>"), "snap: french item title")
|
||||
Test.assert(contains(xml, "15 Jun 2025 00:00:00 GMT"), "snap: french item date")
|
||||
}
|
||||
|
||||
// Snapshot: feed with escaped content
|
||||
fn test_snapshot_escaped_feed(): Unit with {Test} = {
|
||||
let f = lib.feed(
|
||||
"Tom & Jerry",
|
||||
"https://example.com",
|
||||
"A <fun> show",
|
||||
[lib.item("Episode: \"The Chase\"", "https://example.com/1", "Tom & Jerry's adventure", "2025-01-01")]
|
||||
)
|
||||
let xml = lib.render(f)
|
||||
Test.assert(contains(xml, "<title>Tom & Jerry</title>"), "snap: escaped feed title")
|
||||
Test.assert(contains(xml, "<description>A <fun> show</description>"), "snap: escaped feed desc")
|
||||
}
|
||||
|
||||
// Snapshot: multi-item feed order
|
||||
fn test_snapshot_multi_item_order(): Unit with {Test} = {
|
||||
let f = lib.feed("Blog", "https://example.com", "A blog", [
|
||||
lib.item("First", "https://example.com/1", "D1", "2025-01-01"),
|
||||
lib.item("Second", "https://example.com/2", "D2", "2025-02-01"),
|
||||
lib.item("Third", "https://example.com/3", "D3", "2025-03-01")
|
||||
])
|
||||
let xml = lib.render(f)
|
||||
// Items should appear in order
|
||||
let firstIdx = match String.indexOf(xml, "<title>First</title>") { Some(i) => i, None => -1 }
|
||||
let secondIdx = match String.indexOf(xml, "<title>Second</title>") { Some(i) => i, None => -1 }
|
||||
let thirdIdx = match String.indexOf(xml, "<title>Third</title>") { Some(i) => i, None => -1 }
|
||||
Test.assert(firstIdx > 0, "snap: first item found")
|
||||
Test.assert(secondIdx > firstIdx, "snap: second after first")
|
||||
Test.assert(thirdIdx > secondIdx, "snap: third after second")
|
||||
}
|
||||
|
||||
// Snapshot: date conversion across all months
|
||||
fn test_snapshot_all_month_dates(): Unit with {Test} = {
|
||||
Test.assertEqualMsg("01 Jan 2025 00:00:00 GMT", lib.isoToRfc822("2025-01-01"), "snap: Jan")
|
||||
Test.assertEqualMsg("01 Feb 2025 00:00:00 GMT", lib.isoToRfc822("2025-02-01"), "snap: Feb")
|
||||
Test.assertEqualMsg("01 Mar 2025 00:00:00 GMT", lib.isoToRfc822("2025-03-01"), "snap: Mar")
|
||||
Test.assertEqualMsg("01 Apr 2025 00:00:00 GMT", lib.isoToRfc822("2025-04-01"), "snap: Apr")
|
||||
Test.assertEqualMsg("01 May 2025 00:00:00 GMT", lib.isoToRfc822("2025-05-01"), "snap: May")
|
||||
Test.assertEqualMsg("01 Jun 2025 00:00:00 GMT", lib.isoToRfc822("2025-06-01"), "snap: Jun")
|
||||
Test.assertEqualMsg("01 Jul 2025 00:00:00 GMT", lib.isoToRfc822("2025-07-01"), "snap: Jul")
|
||||
Test.assertEqualMsg("01 Aug 2025 00:00:00 GMT", lib.isoToRfc822("2025-08-01"), "snap: Aug")
|
||||
Test.assertEqualMsg("01 Sep 2025 00:00:00 GMT", lib.isoToRfc822("2025-09-01"), "snap: Sep")
|
||||
Test.assertEqualMsg("01 Oct 2025 00:00:00 GMT", lib.isoToRfc822("2025-10-01"), "snap: Oct")
|
||||
Test.assertEqualMsg("01 Nov 2025 00:00:00 GMT", lib.isoToRfc822("2025-11-01"), "snap: Nov")
|
||||
Test.assertEqualMsg("01 Dec 2025 00:00:00 GMT", lib.isoToRfc822("2025-12-01"), "snap: Dec")
|
||||
}
|
||||
Reference in New Issue
Block a user