diff --git a/.formatter.exs b/.formatter.exs index 216876e2..7dd7323c 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,3 +1,7 @@ [ - inputs: ["mix.exs", "{config,lib,test,conformance,benchmark}/**/*.{ex,exs}"] + inputs: ["mix.exs", "{config,lib,test,conformance,benchmark}/**/*.{ex,exs}"], + plugins: [Quokka], + quokka: [ + only: [:line_length] + ] ] diff --git a/lib/protox/define_decoder.ex b/lib/protox/define_decoder.ex index 415605b3..a7ca664a 100644 --- a/lib/protox/define_decoder.ex +++ b/lib/protox/define_decoder.ex @@ -245,8 +245,7 @@ defmodule Protox.DefineDecoder do _ -> quote do - <> + <> end end end @@ -264,8 +263,7 @@ defmodule Protox.DefineDecoder do quote do {entry_key, entry_value} = unquote(value) - {unquote(field.name), - Map.put(unquote(vars.msg).unquote(field.name), entry_key, entry_value)} + {unquote(field.name), Map.put(unquote(vars.msg).unquote(field.name), entry_key, entry_value)} end end diff --git a/lib/protox/errors.ex b/lib/protox/errors.ex index 8717756d..7f84348c 100644 --- a/lib/protox/errors.ex +++ b/lib/protox/errors.ex @@ -55,8 +55,7 @@ defmodule Protox.InvalidFieldAttribute do @doc false def new(attribute, expected, got) do %__MODULE__{ - message: - "Field attribute #{attribute} should be in #{inspect(expected)}, got #{inspect(got)}" + message: "Field attribute #{attribute} should be in #{inspect(expected)}, got #{inspect(got)}" } end end diff --git a/lib/protox/varint.ex b/lib/protox/varint.ex index cd3fce0a..37b74699 100644 --- a/lib/protox/varint.ex +++ b/lib/protox/varint.ex @@ -21,19 +21,17 @@ defmodule Protox.Varint do do: {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, v >>> 28>>, 5} def encode(v) when v < 1 <<< 42, - do: - {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, - v >>> 35>>, 6} + do: {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, v >>> 35>>, 6} def encode(v) when v < 1 <<< 49, do: - {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, - 1::1, v >>> 35::7, v >>> 42>>, 7} + {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, 1::1, v >>> 35::7, + v >>> 42>>, 7} def encode(v) when v < 1 <<< 56, do: - {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, - 1::1, v >>> 35::7, 1::1, v >>> 42::7, v >>> 49>>, 8} + {<<1::1, v::7, 1::1, v >>> 7::7, 1::1, v >>> 14::7, 1::1, v >>> 21::7, 1::1, v >>> 28::7, 1::1, v >>> 35::7, 1::1, + v >>> 42::7, v >>> 49>>, 8} def encode(v) do {next_bytes, size} = encode(v >>> 7) @@ -53,23 +51,19 @@ defmodule Protox.Varint do def decode(<<1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, byte0::7, rest::binary>>), do: {byte3 <<< 0 ||| byte2 <<< 7 ||| byte1 <<< 14 ||| byte0 <<< 21, rest} - def decode( - <<1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, byte0::7, - rest::binary>> - ), - do: {byte4 <<< 0 ||| byte3 <<< 7 ||| byte2 <<< 14 ||| byte1 <<< 21 ||| byte0 <<< 28, rest} + def decode(<<1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, byte0::7, rest::binary>>), + do: {byte4 <<< 0 ||| byte3 <<< 7 ||| byte2 <<< 14 ||| byte1 <<< 21 ||| byte0 <<< 28, rest} def decode( - <<1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, - byte0::7, rest::binary>> + <<1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, byte0::7, rest::binary>> ), do: {byte5 <<< 0 ||| byte4 <<< 7 ||| byte3 <<< 14 ||| byte2 <<< 21 ||| byte1 <<< 28 ||| byte0 <<< 35, rest} def decode( - <<1::1, byte6::7, 1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, - byte1::7, 0::1, byte0::7, rest::binary>> + <<1::1, byte6::7, 1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, byte1::7, 0::1, + byte0::7, rest::binary>> ), do: {byte6 <<< 0 ||| byte5 <<< 7 ||| byte4 <<< 14 ||| byte3 <<< 21 ||| byte2 <<< 28 ||| @@ -77,8 +71,8 @@ defmodule Protox.Varint do byte0 <<< 42, rest} def decode( - <<1::1, byte7::7, 1::1, byte6::7, 1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, - byte2::7, 1::1, byte1::7, 0::1, byte0::7, rest::binary>> + <<1::1, byte7::7, 1::1, byte6::7, 1::1, byte5::7, 1::1, byte4::7, 1::1, byte3::7, 1::1, byte2::7, 1::1, + byte1::7, 0::1, byte0::7, rest::binary>> ), do: {byte7 <<< 0 ||| byte6 <<< 7 ||| byte5 <<< 14 ||| byte4 <<< 21 ||| byte3 <<< 28 ||| diff --git a/mix.exs b/mix.exs index 9b708b75..7a871391 100644 --- a/mix.exs +++ b/mix.exs @@ -40,7 +40,8 @@ defmodule Protox.Mixfile do {:excoveralls, "~> 0.13", only: [:test], runtime: false}, {:ex_doc, "~> 0.22", only: [:dev], runtime: false}, {:propcheck, github: "alfert/propcheck", ref: "c564e89d", only: [:test, :dev]}, - {:stream_data, "~> 1.0", only: [:dev, :test], runtime: false} + {:stream_data, "~> 1.0", only: [:dev, :test], runtime: false}, + {:quokka, "~> 2.0", only: [:dev, :test], runtime: false} ] |> maybe_add_muzak_pro() |> maybe_download_protobuf() @@ -53,8 +54,7 @@ defmodule Protox.Mixfile do creds -> muzak_pro = - {:muzak, - git: "https://#{creds}@github.com/ahamez/muzak.git", tag: "1.1.0", only: [:test]} + {:muzak, git: "https://#{creds}@github.com/ahamez/muzak.git", tag: "1.1.0", only: [:test]} [muzak_pro | deps] end diff --git a/mix.lock b/mix.lock index f70d5802..29bfb8fb 100644 --- a/mix.lock +++ b/mix.lock @@ -20,6 +20,7 @@ "propcheck": {:git, "https://github.com/alfert/propcheck.git", "c564e89d3873caf9c6bf64a2af4bb3890e24ecf1", [ref: "c564e89d"]}, "proper": {:git, "https://github.com/proper-testing/proper.git", "a5ae5669f01143b0828fc21667d4f5e344aa760b", [ref: "a5ae5669f01143b0828fc21667d4f5e344aa760b"]}, "protobuf": {:git, "https://github.com/protocolbuffers/protobuf.git", "b407e8416e3893036aee5af9a12bd9b6a0e2b2e6", [tag: "v29.3", submodules: true]}, + "quokka": {:hex, :quokka, "2.0.0", "cbdd3024c93320818374a8ee53411e50f24456b32b7186e92347a7a3dc8daf33", [:mix], [{:credo, "~> 1.7", [hex: :credo, repo: "hexpm", optional: false]}], "hexpm", "a140bf724daaa6e3f879eef5900d72710bdd83c444892e07106ddf988ed9e43b"}, "statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"}, "stream_data": {:hex, :stream_data, "1.1.2", "05499eaec0443349ff877aaabc6e194e82bda6799b9ce6aaa1aadac15a9fdb4d", [:mix], [], "hexpm", "129558d2c77cbc1eb2f4747acbbea79e181a5da51108457000020a906813a1a9"}, } diff --git a/test/protox/decode_test.exs b/test/protox/decode_test.exs index 15d95d3c..8ff62d88 100644 --- a/test/protox/decode_test.exs +++ b/test/protox/decode_test.exs @@ -24,8 +24,7 @@ defmodule Protox.DecodeTest do { "Repeated fixed64, not contiguous, should be concatenated", # first part of repeated fixed64 | XXXX | second part of repeated fixed64 - <<178, 2, 8, 1, 0, 0, 0, 0, 0, 0, 0, 8, 150, 1, 178, 2, 8, 254, 255, 255, 255, 255, 255, - 255, 255>>, + <<178, 2, 8, 1, 0, 0, 0, 0, 0, 0, 0, 8, 150, 1, 178, 2, 8, 254, 255, 255, 255, 255, 255, 255, 255>>, %TestAllTypesProto3{optional_int32: 150, repeated_fixed64: [1, 18_446_744_073_709_551_614]} }, { @@ -61,8 +60,8 @@ defmodule Protox.DecodeTest do }, { "Repeated int64", - <<130, 2, 24, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 2, 253, 255, 255, 255, 255, - 255, 255, 255, 255, 1, 144, 78>>, + <<130, 2, 24, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 2, 253, 255, 255, 255, 255, 255, 255, 255, 255, + 1, 144, 78>>, %TestAllTypesProto3{repeated_int64: [0, -1, 2, -3, 10_000]} }, { @@ -92,8 +91,8 @@ defmodule Protox.DecodeTest do }, { "Repeated sfixed64", - <<194, 2, 40, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, - 255, 255, 3, 0, 0, 0, 0, 0, 0, 0, 240, 216, 255, 255, 255, 255, 255, 255>>, + <<194, 2, 40, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 3, 0, 0, 0, + 0, 0, 0, 0, 240, 216, 255, 255, 255, 255, 255, 255>>, %TestAllTypesProto3{repeated_sfixed64: [0, 1, -2, 3, -10_000]} }, { @@ -205,8 +204,7 @@ defmodule Protox.DecodeTest do }, { "Message without fields and with unknown fields", - <<8, 42, 61, 42, 0, 0, 0, 65, 42, 0, 0, 0, 0, 0, 0, 0, 114, 3, 102, 111, 111, 218, 4, 3, 1, - 2, 3>>, + <<8, 42, 61, 42, 0, 0, 0, 65, 42, 0, 0, 0, 0, 0, 0, 0, 114, 3, 102, 111, 111, 218, 4, 3, 1, 2, 3>>, %NullHypothesisProto3{ __uf__: [ {1, 0, "*"}, diff --git a/test/protox/encode_test.exs b/test/protox/encode_test.exs index 5602e9ec..1634ad33 100644 --- a/test/protox/encode_test.exs +++ b/test/protox/encode_test.exs @@ -69,17 +69,15 @@ defmodule Protox.EncodeTest do assert encode(%TestAllTypesProto3{ repeated_double: [33.2, -44.0, :infinity, :"-infinity", :nan] }) == - {<<210, 2, 40, 154, 153, 153, 153, 153, 153, 64, 64, 0, 0, 0, 0, 0, 0, 70, 192, 0, 0, - 0, 0, 0, 0, 240, 127, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 1, 241, 255>>, - 43} + {<<210, 2, 40, 154, 153, 153, 153, 153, 153, 64, 64, 0, 0, 0, 0, 0, 0, 70, 192, 0, 0, 0, 0, 0, 0, 240, 127, + 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 1, 241, 255>>, 43} end test "Repeated float" do assert encode(%TestAllTypesProto3{ repeated_float: [33.2, -44.0, :infinity, :"-infinity", :nan] }) == - {<<202, 2, 20, 205, 204, 4, 66, 0, 0, 48, 194, 0, 0, 128, 127, 0, 0, 128, 255, 0, 1, - 129, 255>>, 23} + {<<202, 2, 20, 205, 204, 4, 66, 0, 0, 48, 194, 0, 0, 128, 127, 0, 0, 128, 255, 0, 1, 129, 255>>, 23} end test "Repeated bool" do @@ -94,8 +92,7 @@ defmodule Protox.EncodeTest do test "Unpacked Repeated int32" do assert encode(%TestAllTypesProto3{unpacked_int32: [-1, 2, 3]}) == - {<<200, 5, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 200, 5, 2, 200, 5, 3>>, - 18} + {<<200, 5, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 200, 5, 2, 200, 5, 3>>, 18} end test "Bytes" do