Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation warnings and test a wider range of Elixir versions #130

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: ${{ matrix.script_file }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
Expand Down
49 changes: 26 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,38 @@ on:

jobs:
build:
name: Test (${{matrix.elixir}}/${{matrix.otp}})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- pair:
elixir: '1.6'
otp: '20'
- pair:
elixir: '1.14'
otp: '24'
check_format: true

runs-on: ubuntu-20.04

name: mix test ${{ matrix.pair.elixir }}-erlang-${{ matrix.pair.otp }}

otp: [24.x, 25.x, 26.x]
elixir: [1.11.x, 1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x]
exclude:
- otp: 26.x
elixir: 1.13.x
- otp: 26.x
elixir: 1.12.x
- otp: 26.x
elixir: 1.11.x
- otp: 25.x
elixir: 1.12.x
- otp: 25.x
elixir: 1.11.x
steps:
- uses: actions/checkout@v1

- name: Setup Elixir
uses: erlef/[email protected]
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore dependencies cache
uses: actions/cache@v4
with:
otp-version: ${{matrix.pair.otp}}
elixir-version: ${{matrix.pair.elixir}}
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-

- name: Install Dependencies
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
run: mix deps.get

- name: Check format
if: matrix.check_format
Expand Down
26 changes: 13 additions & 13 deletions lib/saxy/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Saxy.Encoder do
end

defp prolog(%Saxy.Prolog{} = prolog) do
['<?xml', version(prolog.version), encoding(prolog.encoding), standalone(prolog.standalone), '?>']
[~c"<?xml", version(prolog.version), encoding(prolog.encoding), standalone(prolog.standalone), ~c"?>"]
end

defp prolog(prolog) when is_list(prolog) do
Expand All @@ -21,23 +21,23 @@ defmodule Saxy.Encoder do
defp prolog(nil), do: []

defp version(version) when is_binary(version) do
[?\s, 'version', ?=, ?", version, ?"]
[?\s, ~c"version", ?=, ?", version, ?"]
end

defp encoding(nil), do: []

defp encoding(:utf8) do
[?\s, 'encoding', ?=, ?", 'utf-8', ?"]
[?\s, ~c"encoding", ?=, ?", ~c"utf-8", ?"]
end

defp encoding(encoding) when encoding in ["UTF-8", "utf-8"] do
[?\s, 'encoding', ?=, ?", ~c(#{encoding}), ?"]
[?\s, ~c"encoding", ?=, ?", ~c(#{encoding}), ?"]
end

defp standalone(nil), do: []

defp standalone(true) do
[?\s, 'standalone', ?=, ?", "yes", ?"]
[?\s, ~c"standalone", ?=, ?", "yes", ?"]
end

defp element({tag_name, attributes, []}) do
Expand Down Expand Up @@ -102,11 +102,11 @@ defmodule Saxy.Encoder do
end

@escapes [
{?<, '&lt;'},
{?>, '&gt;'},
{?&, '&amp;'},
{?", '&quot;'},
{?', '&apos;'}
{?<, ~c"&lt;"},
{?>, ~c"&gt;"},
{?&, ~c"&amp;"},
{?", ~c"&quot;"},
{?', ~c"&apos;"}
]

for {match, insert} <- @escapes do
Expand All @@ -124,7 +124,7 @@ defmodule Saxy.Encoder do
end

defp cdata(characters) do
['<![CDATA[', characters | ']]>']
[~c"<![CDATA[", characters | ~c"]]>"]
end

defp reference({:entity, reference}) do
Expand All @@ -140,7 +140,7 @@ defmodule Saxy.Encoder do
end

defp comment(comment) do
['<!--', escape_comment(comment, comment) | '-->']
[~c"<!--", escape_comment(comment, comment) | ~c"-->"]
end

defp escape_comment(<<?->>, original) do
Expand All @@ -156,6 +156,6 @@ defmodule Saxy.Encoder do
end

defp processing_instruction(name, content) do
['<?', name, ?\s, content | '?>']
[~c"<?", name, ?\s, content | ~c"?>"]
end
end
2 changes: 1 addition & 1 deletion lib/saxy/parser/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule Saxy.Parser.Builder do

encoding_decl(rest, more?, original, pos + len + 1, state, prolog)

char <> rest when char in '0123456789' ->
char <> rest when char in ~c"0123456789" ->
xml_ver_num(rest, more?, original, pos, state, open_quote, len + 1)

_ in [""] when more? ->
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ defmodule Saxy.MixProject do
use Mix.Project

@source_url "https://github.com/qcam/saxy"
@version "1.5.0"
@version "1.5.1"

def project() do
[
app: :saxy,
version: @version,
elixir: "~> 1.6",
elixir: "~> 1.11",
name: "Saxy",
consolidate_protocols: Mix.env() != :test,
deps: deps(),
Expand Down
14 changes: 7 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%{
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm", "c57508ddad47dfb8038ca6de1e616e66e9b87313220ac5d9817bc4a4dc2257b9"},
"earmark_parser": {:hex, :earmark_parser, "1.4.31", "a93921cdc6b9b869f519213d5bc79d9e218ba768d7270d46fdcf1c01bacff9e2", [:mix], [], "hexpm", "317d367ee0335ef037a87e46c91a2269fef6306413f731e8ec11fc45a7efd059"},
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.0", "9e18a119d9efc3370a3ef2a937bf0b24c088d9c4bf0ba9d7c3751d49d347d035", [:mix], [], "hexpm", "7977f183127a7cbe9346981e2f480dc04c55ffddaef746bd58debd566070eef8"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"stream_data": {:hex, :stream_data, "0.6.0", "e87a9a79d7ec23d10ff83eb025141ef4915eeb09d4491f79e52f2562b73e5f47", [:mix], [], "hexpm", "b92b5031b650ca480ced047578f1d57ea6dd563f5b57464ad274718c9c29501c"},
}
6 changes: 3 additions & 3 deletions test/saxy/xml_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ defmodule Saxy.XMLTest do
describe "characters/1" do
test "generates characters in simple form" do
assert characters("foo & bar") == {:characters, "foo & bar"}
assert characters('foo & bar') == {:characters, "foo & bar"}
assert characters(~c"foo & bar") == {:characters, "foo & bar"}
assert characters(:foo) == {:characters, "foo"}
end
end

describe "comment/1" do
test "generates comment in simple form" do
assert comment("foo & bar") == {:comment, "foo & bar"}
assert comment('foo & bar') == {:comment, "foo & bar"}
assert comment(~c"foo & bar") == {:comment, "foo & bar"}
assert comment(:foo) == {:comment, "foo"}
end
end

describe "cdata/1" do
test "generates comment in simple form" do
assert cdata("foo & bar") == {:cdata, "foo & bar"}
assert cdata('foo & bar') == {:cdata, "foo & bar"}
assert cdata(~c"foo & bar") == {:cdata, "foo & bar"}
assert cdata(:foo) == {:cdata, "foo"}
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/saxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ defmodule SaxyTest do
for fixture <- @fixtures do
stream = stream_fixture(fixture)
element_stream = Saxy.stream_events(stream)
assert [_ | _] = Enum.to_list element_stream
assert [_ | _] = Enum.to_list(element_stream)
end

assert_raise Saxy.ParseError, fn ->
Enum.to_list Saxy.stream_events stream_fixture "incorrect.xml"
Enum.to_list(Saxy.stream_events(stream_fixture("incorrect.xml")))
end
end

Expand Down
Loading