Extracted from qwan-tracker

This commit is contained in:
2026-05-12 15:58:07 +01:00
commit e06832fb13
16 changed files with 117311 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
defmodule Sample do
@moduledoc """
A sample module for testing microprint generation.
"""
@my_attribute :value
@doc "Returns a greeting message"
def greet(name) do
"Hello, #{name}!"
end
# Private helper
defp format_name(name) do
String.capitalize(name)
end
@type status :: :ok | :error
def calculate(x, y) when is_number(x) and is_number(y) do
x + y
end
def list_items do
:standalone_atom
end
end
+38
View File
@@ -0,0 +1,38 @@
defmodule Microprints.TestPubSub do
@moduledoc """
Test helper for starting a Phoenix.PubSub server.
Provides `start_link/1` to start a PubSub server and returns the
server name for use with MicroprintCache.
"""
@doc """
Starts a test PubSub server and returns its name.
"""
def start_link(opts \\ []) do
name = opts[:name] || Microprints.TestPubSub
child_spec = Phoenix.PubSub.child_spec(name: name, adapter: Phoenix.PubSub.PG2)
# Start a temporary supervisor to host the PubSub server
case Supervisor.start_link([child_spec], strategy: :one_for_one) do
{:ok, sup_pid} ->
Process.put(:test_pubsub_supervisor, sup_pid)
{:error, {:already_started, sup_pid}} ->
Process.put(:test_pubsub_supervisor, sup_pid)
end
name
end
@doc """
Stops the test PubSub server.
"""
def stop do
if sup_pid = Process.get(:test_pubsub_supervisor) do
Supervisor.stop(sup_pid)
Process.delete(:test_pubsub_supervisor)
end
end
end