Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
25 KB
Referenced Files
None
Subscribers
None
diff --git a/Makefile b/Makefile
index ac1d0f7..e7d221f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,102 +1,102 @@
MIX = mix
-MYHTMLEX_CFLAGS = -g -O2 -std=c99 -pedantic -Wcomment -Wextra -Wno-old-style-declaration -Wall
+MYHTML_WORKER_CFLAGS = -g -O2 -std=c99 -pedantic -Wcomment -Wextra -Wno-old-style-declaration -Wall
# we need to compile position independent code
-MYHTMLEX_CFLAGS += -fpic -DPIC
+MYHTML_WORKER_CFLAGS += -fpic -DPIC
# For some reason __erl_errno is undefined unless _REENTRANT is defined
-MYHTMLEX_CFLAGS += -D_REENTRANT
+MYHTML_WORKER_CFLAGS += -D_REENTRANT
# myhtmlex is using stpcpy, as defined in gnu string.h
-# MYHTMLEX_CFLAGS += -D_GNU_SOURCE
+# MYHTML_WORKER_CFLAGS += -D_GNU_SOURCE
# base on the same posix c source as myhtml
-# MYHTMLEX_CFLAGS += -D_POSIX_C_SOURCE=199309
+# MYHTML_WORKER_CFLAGS += -D_POSIX_C_SOURCE=199309
# turn warnings into errors
-# MYHTMLEX_CFLAGS += -Werror
+# MYHTML_WORKER_CFLAGS += -Werror
# ignore unused variables
-# MYHTMLEX_CFLAGS += -Wno-unused-variable
+# MYHTML_WORKER_CFLAGS += -Wno-unused-variable
# ignore unused parameter warnings
-MYHTMLEX_CFLAGS += -Wno-unused-parameter
+MYHTML_WORKER_CFLAGS += -Wno-unused-parameter
# set erlang include path
ERLANG_PATH = $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)])])' -s init stop -noshell)
-MYHTMLEX_CFLAGS += -I$(ERLANG_PATH)/include
+MYHTML_WORKER_CFLAGS += -I$(ERLANG_PATH)/include
# expecting myhtml as a submodule in c_src/
# that way we can pin a version and package the whole thing in hex
# hex does not allow for non-app related dependencies.
MYHTML_PATH = c_src/myhtml
MYHTML_STATIC = $(MYHTML_PATH)/lib/libmyhtml_static.a
-MYHTMLEX_CFLAGS += -I$(MYHTML_PATH)/include
+MYHTML_WORKER_CFLAGS += -I$(MYHTML_PATH)/include
# avoid undefined reference errors to phtread_mutex_trylock
-MYHTMLEX_CFLAGS += -lpthread
+MYHTML_WORKER_CFLAGS += -lpthread
# that would be used for a dynamically linked build
-# MYHTMLEX_CFLAGS += -L$(MYHTML_PATH)/lib
+# MYHTML_WORKER_CFLAGS += -L$(MYHTML_PATH)/lib
-MYHTMLEX_LDFLAGS = -shared
+MYHTML_WORKER_LDFLAGS = -shared
# C-Node
ERL_INTERFACE = $(wildcard $(ERLANG_PATH)/../lib/erl_interface-*)
-CNODE_CFLAGS = $(MYHTMLEX_CFLAGS)
+CNODE_CFLAGS = $(MYHTML_WORKER_CFLAGS)
CNODE_CFLAGS += -L$(ERL_INTERFACE)/lib
CNODE_CFLAGS += -I$(ERL_INTERFACE)/include
CNODE_LDFLAGS =
ifeq ($(OTP22_DEF),YES)
CNODE_CFLAGS += -DOTP_22_OR_NEWER
else
CNODE_LDFLAGS += -lerl_interface
endif
CNODE_LDFLAGS += -lei -pthread
# enumerate docker build tests
BUILD_TESTS := $(patsubst %.dockerfile, %.dockerfile.PHONY, $(wildcard ./build-test/*.dockerfile))
# platform specific environment
UNAME = $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
- MYHTMLEX_LDFLAGS += -dynamiclib -undefined dynamic_lookup
+ MYHTML_WORKER_LDFLAGS += -dynamiclib -undefined dynamic_lookup
else
# myhtmlex is using stpcpy, as defined in gnu string.h
- MYHTMLEX_CFLAGS += -D_GNU_SOURCE
+ MYHTML_WORKER_CFLAGS += -D_GNU_SOURCE
# base on the same posix c source as myhtml
- # MYHTMLEX_CFLAGS += -D_POSIX_C_SOURCE=199309
+ # MYHTML_WORKER_CFLAGS += -D_POSIX_C_SOURCE=199309
endif
.PHONY: all
all: myhtmlex
myhtmlex: priv/myhtml_worker
$(MIX) compile
$(MYHTML_STATIC): $(MYHTML_PATH)
$(MAKE) -C $(MYHTML_PATH) library MyCORE_BUILD_WITHOUT_THREADS=YES
priv/myhtml_worker: c_src/myhtml_worker.c $(MYHTML_STATIC)
$(CC) -o $@ $< $(MYHTML_STATIC) $(CNODE_CFLAGS) $(CNODE_LDFLAGS)
clean: clean-myhtml
$(RM) -r priv/myhtmlex*
$(RM) priv/myhtml_worker
$(RM) myhtmlex-*.tar
$(RM) -r package-test
clean-myhtml:
$(MAKE) -C $(MYHTML_PATH) clean
# publishing the package and docs separately is required
# otherwise the build artifacts are included in the package
# and the tarball gets too big to be published
publish: clean
$(MIX) hex.publish package
$(MIX) hex.publish docs
test:
$(MIX) test
build-tests: test $(BUILD_TESTS)
%.dockerfile.PHONY: %.dockerfile
docker build -f $< .
diff --git a/README.md b/README.md
index 65a3cdc..16a70f6 100644
--- a/README.md
+++ b/README.md
@@ -1,47 +1,35 @@
-# Myhtmlex
+# FastHTML
-Bindings for lexborisov's [myhtml](https://github.com/lexborisov/myhtml).
+A C Node wrapping lexborisov's [myhtml](https://github.com/lexborisov/myhtml).
+Primarily used with [FastSanitize](https://git.pleroma.social/pleroma/fast_sanitize).
-* Available as a hex package: `{:myhtmlex, "~> 0.2.0"}`
-* [Documentation](https://hexdocs.pm/myhtmlex/Myhtmlex.html)
+* Available as a hex package: `{:fast_html, "~> 0.1.0"}`
+* [Documentation](https://hexdocs.pm/fast_html/FastHTML.html)
## Example
- iex> Myhtmlex.decode("<h1>Hello world</h1>")
+ iex> :fast_html.decode("<h1>Hello world</h1>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Hello world"]}]}]}
Benchmark results (removed Nif calling mode) on various file sizes on a 2,5Ghz Core i7:
Settings:
duration: 1.0 s
## FileSizesBench
[15:28:42] 1/3: github_trending_js.html 341k
[15:28:46] 2/3: w3c_html5.html 131k
[15:28:48] 3/3: wikipedia_hyperlink.html 97k
Finished in 7.52 seconds
## FileSizesBench
benchmark name iterations average time
wikipedia_hyperlink.html 97k 1000 1385.86 µs/op
w3c_html5.html 131k 1000 2179.30 µs/op
github_trending_js.html 341k 500 5686.21 µs/op
## Contribution / Bug Reports
* Please make sure you do `git submodule update` after a checkout/pull
-* If you have problems building the project, please consider adding a Dockerfile to `build-tests/` to replicate the build error
* The project aims to be fully tested
-
-## Roadmap
-
-The exposed functions on `Myhtmlex` are not subject to change.
-This project is under active development.
-
-* [ ] Expose node-retrieval functions
-* [x] Parse a HTML-document into a tree
-* [x] Investigate safety and calling options
- * [x] Call as dirty-nif
- * [x] Call as C-Node (check branch `c-node`)
-
diff --git a/bench/basic_html_bench.exs b/bench/basic_html_bench.exs
index 7cb794f..64434e7 100644
--- a/bench/basic_html_bench.exs
+++ b/bench/basic_html_bench.exs
@@ -1,41 +1,23 @@
defmodule BasicHtmlBench do
use Benchfella
- setup_all do
- html = File.read!("bench/w3c_html5.html")
- context = {html, Myhtmlex.open(html)}
- {:ok, context}
- end
-
bench "decode" do
{html, _} = bench_context
- Myhtmlex.decode(html)
+ :fast_html.decode(html)
end
bench "decode w/ html_atoms" do
{html, _} = bench_context
- Myhtmlex.decode(html, format: [:html_atoms])
+ :fast_html.decode(html, format: [:html_atoms])
end
bench "decode w/ nil_self_closing" do
{html, _} = bench_context
- Myhtmlex.decode(html, format: [:nil_self_closing])
+ :fast_html.decode(html, format: [:nil_self_closing])
end
bench "decode w/ html_atoms, nil_self_closing" do
{html, _} = bench_context
- Myhtmlex.decode(html, format: [:html_atoms, :nil_self_closing])
- end
-
- bench "decode_tree" do
- {_, ref} = bench_context
- Myhtmlex.decode_tree(ref)
+ :fast_html.decode(html, format: [:html_atoms, :nil_self_closing])
end
-
- bench "decode_tree w/ html_atoms" do
- {_, ref} = bench_context
- Myhtmlex.decode_tree(ref, format: [:html_atoms])
- end
-
end
-
diff --git a/bench/cnode/file_sizes_bench.exs b/bench/cnode/file_sizes_bench.exs
index 6c4722f..44c9bbf 100644
--- a/bench/cnode/file_sizes_bench.exs
+++ b/bench/cnode/file_sizes_bench.exs
@@ -1,31 +1,31 @@
defmodule CnodeFileSizesBench do
use Benchfella
setup_all do
Nodex.Distributed.up
{:ok, _pid} = Nodex.Cnode.start_link(%{exec_path: "priv/myhtml_worker"}, name: Myhtmlex.Safe.Cnode)
contents = {
File.read!("bench/github_trending_js.html"),
File.read!("bench/w3c_html5.html"),
File.read!("bench/wikipedia_hyperlink.html")
}
{:ok, contents}
end
bench "github_trending_js.html 341k" do
{ref, _, _} = bench_context
- Myhtmlex.Safe.decode(ref)
+ :fast_html.decode(ref)
end
bench "w3c_html5.html 131k" do
{_, ref, _} = bench_context
- Myhtmlex.Safe.decode(ref)
+ :fast_html.decode(ref)
end
bench "wikipedia_hyperlink.html 97k" do
{_, _, ref} = bench_context
- Myhtmlex.Safe.decode(ref)
+ :fast_html.decode(ref)
end
end
diff --git a/bench/file_sizes_bench.exs b/bench/file_sizes_bench.exs
deleted file mode 100644
index 9c18dae..0000000
--- a/bench/file_sizes_bench.exs
+++ /dev/null
@@ -1,29 +0,0 @@
-defmodule FileSizesBench do
- use Benchfella
-
- setup_all do
- refs = {
- File.read!("bench/github_trending_js.html") |> Myhtmlex.open,
- File.read!("bench/w3c_html5.html") |> Myhtmlex.open,
- File.read!("bench/wikipedia_hyperlink.html") |> Myhtmlex.open
- }
- {:ok, refs}
- end
-
- bench "github_trending_js.html 341k" do
- {ref, _, _} = bench_context
- Myhtmlex.decode_tree(ref)
- end
-
- bench "w3c_html5.html 131k" do
- {_, ref, _} = bench_context
- Myhtmlex.decode_tree(ref)
- end
-
- bench "wikipedia_hyperlink.html 97k" do
- {_, _, ref} = bench_context
- Myhtmlex.decode_tree(ref)
- end
-
-end
-
diff --git a/build-test/package.sh b/build-test/package.sh
deleted file mode 100755
index 62f8301..0000000
--- a/build-test/package.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh
-
-start_dir=`pwd`
-
-abort()
-{
- cd $start_dir
- exit 1
-}
-
-trap 'abort' 0
-set -e
-
-make clean
-test -d package-test || mkdir package-test
-rm -rf package-test/*
-
-mkdir package-test/myhtmlex-local
-mix hex.build --unpack -o package-test/myhtmlex-local
-cd package-test
-mix new myhtmlex_pkg_test
-cd myhtmlex_pkg_test
-
-# Default operation
-sed -i -e 's/^.*dep_from_hexpm.*$/ {:myhtmlex, path: "..\/myhtmlex-local"}/' mix.exs
-mix deps.get
-mix compile
-mix run -e 'IO.inspect {"html", [], [{"head", [], []}, {"body", [], ["foo"]}]} = Myhtmlex.decode("foo")'
-
-# Nif operation
-sed -i -e 's/^.*myhtmlex-local.*$/ {:myhtmlex, path: "..\/myhtmlex-local", runtime: false}/' mix.exs
-echo "config :myhtmlex, mode: Myhtmlex.Nif" >> config/config.exs
-mix run -e 'IO.inspect {"html", [], [{"head", [], []}, {"body", [], ["foo"]}]} = Myhtmlex.decode("foo")'
-
-trap : 0
-
-cd $start_dir
-echo "ok"
-
diff --git a/build-test/ubuntu-14.04.dockerfile b/build-test/ubuntu-14.04.dockerfile
deleted file mode 100644
index eb62836..0000000
--- a/build-test/ubuntu-14.04.dockerfile
+++ /dev/null
@@ -1,33 +0,0 @@
-FROM ubuntu:trusty
-
-RUN mkdir myhtmlex
-WORKDIR myhtmlex
-
-ENV DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update \
- && apt-get install -y curl \
- && curl -LO https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb \
- && dpkg -i erlang-solutions_1.0_all.deb \
- && apt-get update \
- && apt-get install -y \
- git \
- esl-erlang \
- elixir \
- build-essential \
- && mix local.hex --force \
- && echo 'LANG=en_US.UTF-8' > /etc/default/locale \
- && echo 'LANGUAGE=en_US' >> /etc/default/locale
-
-COPY . ./
-
-# Test build
-RUN mix deps.get \
- && make \
- && mix test \
- && mix bench \
- && make clean
-
-# Test that it works as a dependency
-RUN build-test/package.sh
-
diff --git a/build-test/ubuntu-16.04.dockerfile b/build-test/ubuntu-16.04.dockerfile
deleted file mode 100644
index 431f5db..0000000
--- a/build-test/ubuntu-16.04.dockerfile
+++ /dev/null
@@ -1,33 +0,0 @@
-FROM ubuntu:xenial
-
-RUN mkdir myhtmlex
-WORKDIR myhtmlex
-
-ENV DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update \
- && apt-get install -y curl \
- && curl -LO https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb \
- && dpkg -i erlang-solutions_1.0_all.deb \
- && apt-get update \
- && apt-get install -y \
- git \
- esl-erlang \
- elixir \
- build-essential \
- && mix local.hex --force \
- && echo 'LANG=en_US.UTF-8' > /etc/default/locale \
- && echo 'LANGUAGE=en_US' >> /etc/default/locale
-
-COPY . ./
-
-# Test build
-RUN mix deps.get \
- && make \
- && mix test \
- && mix bench \
- && make clean
-
-# Test that it works as a dependency
-RUN build-test/package.sh
-
diff --git a/lib/myhtmlex.ex b/lib/fast_html.ex
similarity index 83%
rename from lib/myhtmlex.ex
rename to lib/fast_html.ex
index 1114010..8cb824a 100644
--- a/lib/myhtmlex.ex
+++ b/lib/fast_html.ex
@@ -1,101 +1,101 @@
-defmodule Myhtmlex do
+defmodule :fast_html do
@moduledoc """
A module to decode html into a tree structure.
Based on [Alexander Borisov's myhtml](https://github.com/lexborisov/myhtml),
this binding gains the properties of being html-spec compliant and very fast.
## Example
- iex> Myhtmlex.decode("<h1>Hello world</h1>")
+ iex> :fast_html.decode("<h1>Hello world</h1>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Hello world"]}]}]}
Benchmark results (removed Nif calling mode) on various file sizes on a 2,5Ghz Core i7:
Settings:
duration: 1.0 s
## FileSizesBench
[15:28:42] 1/3: github_trending_js.html 341k
[15:28:46] 2/3: w3c_html5.html 131k
[15:28:48] 3/3: wikipedia_hyperlink.html 97k
Finished in 7.52 seconds
## FileSizesBench
benchmark name iterations average time
wikipedia_hyperlink.html 97k 1000 1385.86 µs/op
w3c_html5.html 131k 1000 2179.30 µs/op
github_trending_js.html 341k 500 5686.21 µs/op
"""
@type tag() :: String.t() | atom()
@type attr() :: {String.t(), String.t()}
@type attr_list() :: [] | [attr()]
@type comment_node() :: {:comment, String.t()}
@type comment_node3() :: {:comment, [], String.t()}
@type tree() ::
{tag(), attr_list(), tree()}
| {tag(), attr_list(), nil}
| comment_node()
| comment_node3()
@type format_flag() :: :html_atoms | :nil_self_closing | :comment_tuple3
@doc """
Returns a tree representation from the given html string.
## Examples
- iex> Myhtmlex.decode("<h1>Hello world</h1>")
+ iex> :fast_html.decode("<h1>Hello world</h1>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Hello world"]}]}]}
- iex> Myhtmlex.decode("<span class='hello'>Hi there</span>")
+ iex> :fast_html.decode("<span class='hello'>Hi there</span>")
{"html", [],
[{"head", [], []},
{"body", [], [{"span", [{"class", "hello"}], ["Hi there"]}]}]}
- iex> Myhtmlex.decode("<body><!-- a comment --!></body>")
+ iex> :fast_html.decode("<body><!-- a comment --!></body>")
{"html", [], [{"head", [], []}, {"body", [], [comment: " a comment "]}]}
- iex> Myhtmlex.decode("<br>")
+ iex> :fast_html.decode("<br>")
{"html", [], [{"head", [], []}, {"body", [], [{"br", [], []}]}]}
"""
@spec decode(String.t()) :: tree()
def decode(bin) do
decode(bin, format: [])
end
@doc """
Returns a tree representation from the given html string.
This variant allows you to pass in one or more of the following format flags:
* `:html_atoms` uses atoms for known html tags (faster), binaries for everything else.
* `:nil_self_closing` uses `nil` to designate self-closing tags and void elements.
For example `<br>` is then being represented like `{"br", [], nil}`.
See http://w3c.github.io/html-reference/syntax.html#void-elements for a full list of void elements.
* `:comment_tuple3` uses 3-tuple elements for comments, instead of the default 2-tuple element.
## Examples
- iex> Myhtmlex.decode("<h1>Hello world</h1>", format: [:html_atoms])
+ iex> :fast_html.decode("<h1>Hello world</h1>", format: [:html_atoms])
{:html, [], [{:head, [], []}, {:body, [], [{:h1, [], ["Hello world"]}]}]}
- iex> Myhtmlex.decode("<br>", format: [:nil_self_closing])
+ iex> :fast_html.decode("<br>", format: [:nil_self_closing])
{"html", [], [{"head", [], []}, {"body", [], [{"br", [], nil}]}]}
- iex> Myhtmlex.decode("<body><!-- a comment --!></body>", format: [:comment_tuple3])
+ iex> :fast_html.decode("<body><!-- a comment --!></body>", format: [:comment_tuple3])
{"html", [], [{"head", [], []}, {"body", [], [{:comment, [], " a comment "}]}]}
iex> html = "<body><!-- a comment --!><unknown /></body>"
- iex> Myhtmlex.decode(html, format: [:html_atoms, :nil_self_closing, :comment_tuple3])
+ iex> :fast_html.decode(html, format: [:html_atoms, :nil_self_closing, :comment_tuple3])
{:html, [],
[{:head, [], []},
{:body, [], [{:comment, [], " a comment "}, {"unknown", [], nil}]}]}
"""
@spec decode(String.t(), format: [format_flag()]) :: tree()
def decode(bin, format: flags) do
Myhtmlex.Safe.decode(bin, flags)
end
end
diff --git a/mix.exs b/mix.exs
index c9dfa7c..f54e364 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,136 +1,138 @@
-defmodule Myhtmlex.Mixfile do
+defmodule FastHTML.Mixfile do
use Mix.Project
def project do
[
- app: :myhtmlex,
+ app: :fast_html,
version: "0.2.1",
elixir: "~> 1.5",
deps: deps(),
package: package(),
- compilers: [:myhtmlex_make] ++ Mix.compilers(),
+ compilers: [:my_html_worker_make] ++ Mix.compilers(),
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
- name: "Myhtmlex",
+ name: "FastHTML",
description: """
A module to decode HTML into a tree,
porting all properties of the underlying
library myhtml, being fast and correct
in regards to the html spec.
+
+ Originally based on Myhtmlex.
""",
docs: docs()
]
end
def package do
[
- maintainers: ["Lukas Rieder"],
+ maintainers: ["Ariadne Conill"],
licenses: ["GNU LGPL"],
links: %{
- "Github" => "https://git.pleroma.social/pleroma/myhtmlex",
- "Issues" => "https://git.pleroma.social/pleroma/myhtmlex/issues",
+ "GitLab" => "https://git.pleroma.social/pleroma/fast_html",
+ "Issues" => "https://git.pleroma.social/pleroma/fast_html/issues",
"MyHTML" => "https://github.com/lexborisov/myhtml"
},
files: [
"lib",
"c_src",
"priv/.gitignore",
"test",
"Makefile",
"mix.exs",
"README.md",
"LICENSE"
]
]
end
def application do
[
extra_applications: [:logger],
mod: {Myhtmlex.Safe, []},
# used to detect conflicts with other applications named processes
registered: [Myhtmlex.Safe.Cnode, Myhtmlex.Safe.Supervisor],
env: [
mode: Myhtmlex.Safe
]
]
end
defp deps do
[
# documentation helpers
{:ex_doc, ">= 0.0.0", only: :dev},
# benchmarking helpers
{:benchfella, "~> 0.3.0", only: :dev},
# cnode helpers
{:nodex,
git: "https://git.pleroma.social/pleroma/nodex",
ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"}
]
end
defp docs do
[
- main: "Myhtmlex"
+ main: "FastHTML"
]
end
end
-defmodule Mix.Tasks.Compile.MyhtmlexMake do
+defmodule Mix.Tasks.Compile.MyHtmlWorkerMake do
@artifacts [
"priv/myhtml_worker"
]
def find_make do
_make_cmd =
System.get_env("MAKE") ||
case :os.type() do
{:unix, :freebsd} -> "gmake"
{:unix, :openbsd} -> "gmake"
{:unix, :netbsd} -> "gmake"
{:unix, :dragonfly} -> "gmake"
_ -> "make"
end
end
defp otp_version do
:erlang.system_info(:otp_release)
|> to_string()
|> String.to_integer()
end
defp otp_22_or_newer? do
otp_version() >= 22
end
def run(_) do
make_cmd = find_make()
if match?({:win32, _}, :os.type()) do
IO.warn("Windows is not yet a target.")
exit(1)
else
{result, _error_code} =
System.cmd(
make_cmd,
@artifacts,
stderr_to_stdout: true,
env: [
{"MIX_ENV", to_string(Mix.env())},
{"OTP22_DEF", (otp_22_or_newer?() && "YES") || "NO"}
]
)
IO.binwrite(result)
end
:ok
end
def clean() do
make_cmd = find_make()
{result, _error_code} = System.cmd(make_cmd, ["clean"], stderr_to_stdout: true)
Mix.shell().info(result)
:ok
end
end
diff --git a/test/myhtmlex.safe_test.exs b/test/fast_html_test.exs
similarity index 72%
rename from test/myhtmlex.safe_test.exs
rename to test/fast_html_test.exs
index 122cd9a..304edd0 100644
--- a/test/myhtmlex.safe_test.exs
+++ b/test/fast_html_test.exs
@@ -1,140 +1,140 @@
-defmodule Myhtmlex.SafeTest do
+defmodule :fast_html_test do
use ExUnit.Case
- doctest Myhtmlex
+ doctest :fast_html
test "doesn't segfault when <!----> is encountered" do
- assert {"html", _attrs, _children} = Myhtmlex.decode("<div> <!----> </div>")
+ assert {"html", _attrs, _children} = :fast_html.decode("<div> <!----> </div>")
end
test "builds a tree, formatted like mochiweb by default" do
assert {"html", [],
[
{"head", [], []},
{"body", [],
[
{"br", [], []}
]}
- ]} = Myhtmlex.decode("<br>")
+ ]} = :fast_html.decode("<br>")
end
test "builds a tree, html tags as atoms" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{:br, [], []}
]}
- ]} = Myhtmlex.decode("<br>", format: [:html_atoms])
+ ]} = :fast_html.decode("<br>", format: [:html_atoms])
end
test "builds a tree, nil self closing" do
assert {"html", [],
[
{"head", [], []},
{"body", [],
[
{"br", [], nil},
{"esi:include", [], nil}
]}
- ]} = Myhtmlex.decode("<br><esi:include />", format: [:nil_self_closing])
+ ]} = :fast_html.decode("<br><esi:include />", format: [:nil_self_closing])
end
test "builds a tree, multiple format options" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{:br, [], nil}
]}
- ]} = Myhtmlex.decode("<br>", format: [:html_atoms, :nil_self_closing])
+ ]} = :fast_html.decode("<br>", format: [:html_atoms, :nil_self_closing])
end
test "attributes" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{:span, [{"id", "test"}, {"class", "foo garble"}], []}
]}
]} =
- Myhtmlex.decode(~s'<span id="test" class="foo garble"></span>',
+ :fast_html.decode(~s'<span id="test" class="foo garble"></span>',
format: [:html_atoms]
)
end
test "single attributes" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{:button, [{"disabled", "disabled"}, {"class", "foo garble"}], []}
]}
]} =
- Myhtmlex.decode(~s'<button disabled class="foo garble"></span>',
+ :fast_html.decode(~s'<button disabled class="foo garble"></span>',
format: [:html_atoms]
)
end
test "text nodes" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
"text node"
]}
- ]} = Myhtmlex.decode(~s'<body>text node</body>', format: [:html_atoms])
+ ]} = :fast_html.decode(~s'<body>text node</body>', format: [:html_atoms])
end
test "broken input" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{:a, [{"<", "<"}], [" asdf"]}
]}
- ]} = Myhtmlex.decode(~s'<a <> asdf', format: [:html_atoms])
+ ]} = :fast_html.decode(~s'<a <> asdf', format: [:html_atoms])
end
test "namespaced tags" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{"svg:svg", [],
[
{"svg:path", [], []},
{"svg:a", [], []}
]}
]}
- ]} = Myhtmlex.decode(~s'<svg><path></path><a></a></svg>', format: [:html_atoms])
+ ]} = :fast_html.decode(~s'<svg><path></path><a></a></svg>', format: [:html_atoms])
end
test "custom namespaced tags" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
{"esi:include", [], nil}
]}
- ]} = Myhtmlex.decode(~s'<esi:include />', format: [:html_atoms, :nil_self_closing])
+ ]} = :fast_html.decode(~s'<esi:include />', format: [:html_atoms, :nil_self_closing])
end
test "html comments" do
assert {:html, [],
[
{:head, [], []},
{:body, [],
[
comment: " a comment "
]}
- ]} = Myhtmlex.decode(~s'<body><!-- a comment --></body>', format: [:html_atoms])
+ ]} = :fast_html.decode(~s'<body><!-- a comment --></body>', format: [:html_atoms])
end
end

File Metadata

Mime Type
text/x-diff
Expires
Thu, Oct 29, 4:59 AM (9 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1796446
Default Alt Text
(25 KB)

Event Timeline