Skip to content

Commit d753de3

Browse files
committed
Support 500 podcast episodes
1 parent 1a5d8a8 commit d753de3

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

lib/components_guide/wasm/examples/podcast_feed/podcast_feed.ex

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ defmodule ComponentsGuide.Wasm.PodcastFeed do
55
use ComponentsGuide.Wasm.PodcastFeed.XMLFormatter, as: XML
66
require SilverOrb.Arena
77

8+
Memory.pages(10)
9+
810
SilverOrb.BumpAllocator.export_alloc()
911

1012
global :export_mutable do
@@ -81,11 +83,31 @@ defmodule ComponentsGuide.Wasm.PodcastFeed do
8183

8284
importw(Datasource, :datasource)
8385

86+
# SilverOrb.defarena(WriteBuffer, pages: 1)
87+
8488
# SilverOrb.Arena.def(DatasourceArena, pages: 1)
8589
# Used by url attribute in <enclosure url="…">
86-
SilverOrb.Arena.def(WriteBuffer, pages: 1)
90+
# SilverOrb.Arena.def(WriteBuffer, pages: 1)
8791
# Attributes must have <&" escaped.
88-
SilverOrb.Arena.def(EscapeXMLBuffer, pages: byte_size("&amp;"))
92+
# SilverOrb.Arena.def EscapeXMLBuffer, pages: byte_size("&quot;") do
93+
# defw escape_xml(str: I32.String), char: I32 do
94+
# loop EachChar do
95+
# I32.match char do
96+
# ?& ->
97+
# EscapeXMLBuffer.append_string("&amp;")
98+
99+
# ?" ->
100+
# EscapeXMLBuffer.append_string("&quot;")
101+
102+
# ?< ->
103+
# EscapeXMLBuffer.append_string("&lt;")
104+
105+
# _ ->
106+
# EscapeXMLBuffer.append_u8(char)
107+
# end
108+
# end
109+
# end
110+
# end
89111

90112
# There are a few ways to implement this:
91113
# 1. Pass every episode in as some sort of data structure. e.g.

test/components_guide/wasm/examples/podcast_feed_test.exs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ defmodule ComponentsGuide.Wasm.PodcastFeed.Test do
44
alias OrbWasmtime.{Instance, Wasm}
55
alias ComponentsGuide.Wasm.PodcastFeed
66

7-
defp wasm_imports do
7+
defp wasm_imports(opts) do
88
[
9-
{:datasource, :get_episodes_count, fn -> 2 end},
9+
{:datasource, :get_episodes_count, fn -> Keyword.get(opts, :episodes_count, 2) end},
1010
{:datasource, :write_episode_id,
1111
fn caller, id, write_at ->
1212
s = "#{id + 1}"
@@ -58,7 +58,7 @@ defmodule ComponentsGuide.Wasm.PodcastFeed.Test do
5858
test "podcast xml feed rendering" do
5959
# IO.puts(PodcastFeed.to_wat())
6060

61-
inst = Instance.run(PodcastFeed, wasm_imports())
61+
inst = Instance.run(PodcastFeed, wasm_imports([]))
6262

6363
# {title_offset, title_max_bytes} = Instance.call(inst, :get_title_memory_range)
6464
# title = "SOME TITLE" |> &[&1, ?\0] |> List.to_string()
@@ -103,7 +103,17 @@ defmodule ComponentsGuide.Wasm.PodcastFeed.Test do
103103
assert "Description for 2" = xml_text_content(item2, "//description[1]")
104104

105105
# <enclosure url="${bunnyEpisodeURL(episodeID)}" length="${feedItem.mp3ByteCount}" type="audio/mpeg"/>
106-
assert "Description for 2" = xml_xpath(item1, "//enclosure[1]")
106+
# assert "Description for 2" = xml_xpath(item1, "//enclosure[1]")
107+
end
108+
109+
test "500 episodes" do
110+
inst = Instance.run(PodcastFeed, wasm_imports(episodes_count: 500))
111+
text_xml_func = Instance.capture(inst, String, :text_xml, 0)
112+
text_xml = text_xml_func.()
113+
114+
assert text_xml =~ ~S"""
115+
<?xml version="1.0" encoding="UTF-8"?>
116+
"""
107117
end
108118

109119
defp xml_parse(xml) do
Binary file not shown.

test/components_guide/wasm/examples/podcast_feed_xml.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@
544544
call 22
545545
call 19
546546
call 18)
547-
(memory (;0;) 2)
547+
(memory (;0;) 12)
548548
(global (;0;) (mut i32) (i32.const 65536))
549549
(global (;1;) (mut i32) (i32.const 0))
550550
(global (;2;) (mut i32) (i32.const 0))
Binary file not shown.

test/components_guide/wasm/examples/podcast_feed_xml_OPT.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
call 8
412412
call 7
413413
call 6)
414-
(memory (;0;) 2)
414+
(memory (;0;) 12)
415415
(global (;0;) (mut i32) (i32.const 65536))
416416
(global (;1;) (mut i32) (i32.const 0))
417417
(global (;2;) (mut i32) (i32.const 0))

0 commit comments

Comments
 (0)