Skip to content
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
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
locals_without_parens: [field: 2, field: 3, oneof: 2, extend: 4, extensions: 1],
export: [
locals_without_parens: [field: 2, field: 3, oneof: 2, extend: 4, extensions: 1]
]
],
import_deps: [:stream_data]
]
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ More options will be added in the future, see elixirpb.proto comments for detail

## Tests

Before you can run the test suite, you must install `eqc_gen`:

```
$ mix eqc.install --mini
```bash
mix test
```

## Sponsors
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Protobuf.Mixfile do
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.23", only: :dev, runtime: false},
{:eqc_ex, github: "tony612/eqc_ex", branch: "fix-elixir-1-10", only: [:dev, :test]}
{:stream_data, "~> 0.5.0", only: [:dev, :test]}
]
end

Expand Down
3 changes: 1 addition & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"credo": {:hex, :credo, "1.5.1", "4fe303cc828412b9d21eed4eab60914c401e71f117f40243266aafb66f30d036", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "0b219ca4dcc89e4e7bc6ae7e6539c313e738e192e10b85275fa1e82b5203ecd7"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"eqc_ex": {:git, "https://github.com/tony612/eqc_ex.git", "43759ba1fa56dec40b0346f2e23268d18f3ccda1", [branch: "fix-elixir-1-10"]},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
"file_system": {:hex, :file_system, "0.2.9", "545b9c9d502e8bfa71a5315fac2a923bd060fd9acb797fe6595f54b0f975fd32", [:mix], [], "hexpm", "3cf87a377fe1d93043adeec4889feacf594957226b4f19d5897096d6f61345d8"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
}
58 changes: 26 additions & 32 deletions test/pbt/encode_decode_type_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do
defmacro make_property(gen_func, field_type, wire_type) do
quote do
property unquote(Atom.to_string(field_type)) <> " roundtrip" do
forall n <- unquote(gen_func) do
check all n <- unquote(gen_func) do
iodata = Encoder.encode_type(unquote(field_type), n)
bin = IO.iodata_to_binary(iodata)

ensure(
n ==
decode_type(
unquote(wire_type),
unquote(field_type),
bin
)
)
assert n == decode_type(unquote(wire_type), unquote(field_type), bin)
end
end
end
Expand All @@ -35,7 +27,7 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do
defmacro make_canonical_property(gen_func, field_type, wire_type) do
quote do
property unquote(Atom.to_string(field_type)) <> " canonical roundtrip" do
forall n <- unquote(gen_func) do
check all n <- unquote(gen_func) do
encoded_val =
unquote(field_type)
|> Encoder.encode_type(n)
Expand All @@ -53,45 +45,47 @@ defmodule Protobuf.EncodeDecodeTypeTest.PropertyGenerator do
|> Encoder.encode_type(canonical_val)
|> IO.iodata_to_binary()

ensure(
canonical_val ==
decode_type(
unquote(wire_type),
unquote(field_type),
bin
)
)
assert canonical_val == decode_type(unquote(wire_type), unquote(field_type), bin)
end
end
end
end
end

defmodule Protobuf.EncodeDecodeTypeTest do
use ExUnit.Case
use EQC.ExUnit
use ExUnit.Case, async: true
use ExUnitProperties

import Protobuf.EncodeDecodeTypeTest.PropertyGenerator

defp uint32_gen do
let(<<x::unsigned-integer-size(32)>> <- binary(4), do: return(x))
map(binary(length: 4), fn <<x::unsigned-integer-size(32)>> -> x end)
end

defp uint64_gen do
let(<<x::unsigned-integer-size(64)>> <- binary(8), do: return(x))
map(binary(length: 8), fn <<x::unsigned-integer-size(64)>> -> x end)
end

defp large_integer do
scale(integer(), &(&1 * 10_000))
end

make_property(int(), :int32, 0)
make_property(largeint(), :int64, 0)
defp natural_number do
map(integer(), &abs/1)
end

make_property(integer(), :int32, 0)
make_property(large_integer(), :int64, 0)
make_property(uint32_gen(), :uint32, 0)
make_property(uint64_gen(), :uint64, 0)
make_property(int(), :sint32, 0)
make_property(largeint(), :sint64, 0)
make_property(bool(), :bool, 0)
make_property(integer(), :sint32, 0)
make_property(large_integer(), :sint64, 0)

make_property(boolean(), :bool, 0)

make_property(nat(), :fixed64, 1)
make_property(largeint(), :sfixed64, 1)
make_canonical_property(resize(64, real()), :double, 1)
make_property(natural_number(), :fixed64, 1)
make_property(large_integer(), :sfixed64, 1)

make_canonical_property(resize(32, real()), :float, 5)
make_canonical_property(float(), :double, 1)
make_canonical_property(float(), :float, 5)
end
22 changes: 12 additions & 10 deletions test/pbt/encode_decode_varint_test.exs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
defmodule Protobuf.EncodeDecodeVarintTest do
use ExUnit.Case
use EQC.ExUnit
use ExUnit.Case, async: true
use ExUnitProperties

alias Protobuf.{Encoder, Decoder}

property "varint roundtrip" do
forall n <- largeint() do
check all n <- large_integer_gen() do
iodata = Encoder.encode_varint(n)
bin = IO.iodata_to_binary(iodata)
[n] = Decoder.decode_varint(bin, :value)
ensure(<<n::signed-64>> == <<n::64>>)
assert <<n::signed-64>> == <<n::64>>
end
end

defp neg_gen do
let(x <- largeint(), do: return(-abs(x)))
end

property "encode_varint for negative integers should always be 10 bytes" do
forall n <- neg_gen() do
ensure(IO.iodata_length(Encoder.encode_varint(n)) == 10)
negative_large_integer_gen = map(large_integer_gen(), &(-abs(&1)))

check all n <- negative_large_integer_gen do
assert IO.iodata_length(Encoder.encode_varint(n)) == 10
end
end

defp large_integer_gen do
scale(integer(), &(&1 * 10_000))
end
end