defmodule BBCode.Generator.Test do use ExUnit.Case describe "simple tags" do test "[b] tags are translated to " do assert {:ok, "testing"} = BBCode.to_html("[b]testing[/b]") end test "[i] tags are translated to " do assert {:ok, "testing"} = BBCode.to_html("[i]testing[/i]") end test "[u] tags are translated to " do assert {:ok, "testing"} = BBCode.to_html("[u]testing[/u]") end test "[s] tags are translated to " do assert {:ok, "testing"} = BBCode.to_html("[s]testing[/s]") end test "[code] tags are translated to
" do
      assert {:ok, "
testing
"} = BBCode.to_html("[code]testing[/code]") end test "[quote] tags are translated to
" do assert {:ok, "
testing
"} = BBCode.to_html("[quote]testing[/quote]") end test "compounding simple tags works as expected" do assert {:ok, "testing"} = BBCode.to_html("[b][i]testing[/i][/b]") end end describe "lists" do test "[ul] lists are rendered properly" do data = """ [ul] [*]a [*]b [*]c [/ul] """ expected = "
  • a
  • b
  • c
" assert {:ok, ^expected} = BBCode.to_html(data) end test "[ol] lists are rendered properly" do data = """ [ol] [*]a [*]b [*]c [/ol] """ expected = "
  1. a
  2. b
  3. c
" assert {:ok, ^expected} = BBCode.to_html(data) end end describe "tables" do test "[table] tables are rendered properly" do data = """ [table] [tr] [th]header[/th] [/tr] [tr] [td]cell[/td] [/tr] [/table] """ expected = "
header
cell
" assert {:ok, ^expected} = BBCode.to_html(data) end end describe "links" do test "bare [url] links are rendered properly" do data = """ [url]http://example.com[/url] """ expected = "http://example.com
" assert {:ok, ^expected} = BBCode.to_html(data) end test "named [url] links are rendered properly" do data = """ [url=http://example.com]Example[/url] """ expected = "Example
" assert {:ok, ^expected} = BBCode.to_html(data) end end describe "images" do test "bare [img] links are rendered properly" do data = """ [img]http://example.com/image.jpg[/img] """ expected = "
" assert {:ok, ^expected} = BBCode.to_html(data) end test "sized [img] links are rendered properly" do data = """ [img=32x32]http://example.com/image.jpg[/img] """ expected = "
" assert {:ok, ^expected} = BBCode.to_html(data) end end describe "documents" do test "it correctly renders a complex document" do data = """ [quote] A multiline quote. This is the second line. [/quote] [ul] [*]a [*]b [*]c [/ul] [b]bold[/b] [i]italic[/i] [u]underline[/u] [s]strikethrough[/s] [url=http://example.com]a link[/url] @kaniini (a mention) """ {:ok, output} = BBCode.to_html(data) assert output == "
A multiline quote.
This is the second line.
  • a
  • b
  • c
bold
italic
underline
strikethrough

a link

@kaniini (a mention)
" end end end