Skip to content

Commit

Permalink
fix: Fix credo warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Mar 20, 2022
1 parent 797c992 commit 4fa2b48
Showing 1 changed file with 121 additions and 121 deletions.
242 changes: 121 additions & 121 deletions test/bson_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,141 +7,141 @@ defmodule BSONTest do

import BSON, only: [decode: 1]

@map1 %{"hello" => "world"}
@bin1 <<22, 0, 0, 0, 2, 104, 101, 108, 108, 111, 0, 6, 0, 0, 0, 119, 111, 114, 108, 100, 0, 0>>
@map_1 %{"hello" => "world"}
@bin_1 <<22, 0, 0, 0, 2, 104, 101, 108, 108, 111, 0, 6, 0, 0, 0, 119, 111, 114, 108, 100, 0, 0>>

@map2 %{"BSON" => ["awesome", 5.05, 1986]}
@bin2 <<49, 0, 0, 0, 4, 66, 83, 79, 78, 0, 38, 0, 0, 0, 2, 48, 0, 8, 0, 0, 0, 97, 119, 101, 115, 111, 109, 101, 0, 1, 49, 0, 51, 51, 51, 51, 51, 51, 20, 64, 16, 50, 0, 194, 7, 0, 0, 0, 0>>
@map_2 %{"BSON" => ["awesome", 5.05, 1986]}
@bin_2 <<49, 0, 0, 0, 4, 66, 83, 79, 78, 0, 38, 0, 0, 0, 2, 48, 0, 8, 0, 0, 0, 97, 119, 101, 115, 111, 109, 101, 0, 1, 49, 0, 51, 51, 51, 51, 51, 51, 20, 64, 16, 50, 0, 194, 7, 0, 0, 0, 0>>

@map3 %{"a" => %{"b" => %{}, "c" => %{"d" => nil}}}
@bin3 <<32, 0, 0, 0, 3, 97, 0, 24, 0, 0, 0, 3, 98, 0, 5, 0, 0, 0, 0, 3, 99, 0, 8, 0, 0, 0, 10, 100, 0, 0, 0, 0>>
@map_3 %{"a" => %{"b" => %{}, "c" => %{"d" => nil}}}
@bin_3 <<32, 0, 0, 0, 3, 97, 0, 24, 0, 0, 0, 3, 98, 0, 5, 0, 0, 0, 0, 3, 99, 0, 8, 0, 0, 0, 10, 100, 0, 0, 0, 0>>

@map4 %{"a" => [], "b" => [1, 2, 3], "c" => [1.1, "2", true]}
@bin4 <<74, 0, 0, 0, 4, 97, 0, 5, 0, 0, 0, 0, 4, 98, 0, 26, 0, 0, 0, 16, 48, 0, 1, 0, 0, 0, 16, 49, 0, 2, 0, 0, 0, 16, 50, 0, 3, 0, 0, 0, 0, 4, 99, 0, 29, 0, 0, 0, 1, 48, 0, 154, 153, 153, 153, 153, 153, 241, 63, 2, 49, 0, 2, 0, 0, 0, 50, 0, 8, 50,
@map_4 %{"a" => [], "b" => [1, 2, 3], "c" => [1.1, "2", true]}
@bin_4 <<74, 0, 0, 0, 4, 97, 0, 5, 0, 0, 0, 0, 4, 98, 0, 26, 0, 0, 0, 16, 48, 0, 1, 0, 0, 0, 16, 49, 0, 2, 0, 0, 0, 16, 50, 0, 3, 0, 0, 0, 0, 4, 99, 0, 29, 0, 0, 0, 1, 48, 0, 154, 153, 153, 153, 153, 153, 241, 63, 2, 49, 0, 2, 0, 0, 0, 50, 0, 8, 50,
0, 1, 0, 0>>

@map5 %{"a" => 123.0}
@bin5 <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 192, 94, 64, 0>>
@map_5 %{"a" => 123.0}
@bin_5 <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 192, 94, 64, 0>>

@map6 %{"b" => "123"}
@bin6 <<16, 0, 0, 0, 2, 98, 0, 4, 0, 0, 0, 49, 50, 51, 0, 0>>
@map_6 %{"b" => "123"}
@bin_6 <<16, 0, 0, 0, 2, 98, 0, 4, 0, 0, 0, 49, 50, 51, 0, 0>>

@map7 %{"c" => %{}}
@bin7 <<13, 0, 0, 0, 3, 99, 0, 5, 0, 0, 0, 0, 0>>
@map_7 %{"c" => %{}}
@bin_7 <<13, 0, 0, 0, 3, 99, 0, 5, 0, 0, 0, 0, 0>>

@map8 %{"d" => []}
@bin8 <<13, 0, 0, 0, 4, 100, 0, 5, 0, 0, 0, 0, 0>>
@map_8 %{"d" => []}
@bin_8 <<13, 0, 0, 0, 4, 100, 0, 5, 0, 0, 0, 0, 0>>

@map9 %{"e" => %BSON.Binary{binary: <<1, 2, 3>>, subtype: :generic}}
@bin9 <<16, 0, 0, 0, 5, 101, 0, 3, 0, 0, 0, 0, 1, 2, 3, 0>>
@map_9 %{"e" => %BSON.Binary{binary: <<1, 2, 3>>, subtype: :generic}}
@bin_9 <<16, 0, 0, 0, 5, 101, 0, 3, 0, 0, 0, 0, 1, 2, 3, 0>>

@map10 %{"f" => %BSON.ObjectId{value: <<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11>>}}
@bin10 <<20, 0, 0, 0, 7, 102, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0>>
@map_10 %{"f" => %BSON.ObjectId{value: <<0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11>>}}
@bin_10 <<20, 0, 0, 0, 7, 102, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0>>

@map11 %{"g" => true}
@bin11 <<9, 0, 0, 0, 8, 103, 0, 1, 0>>
@map_11 %{"g" => true}
@bin_11 <<9, 0, 0, 0, 8, 103, 0, 1, 0>>

@map12 %{"h" => DateTime.from_unix!(12_345, :millisecond)}
@bin12 <<16, 0, 0, 0, 9, 104, 0, 57, 48, 0, 0, 0, 0, 0, 0, 0>>
@map_12 %{"h" => DateTime.from_unix!(12_345, :millisecond)}
@bin_12 <<16, 0, 0, 0, 9, 104, 0, 57, 48, 0, 0, 0, 0, 0, 0, 0>>

@map13 %{"i" => nil}
@bin13 <<8, 0, 0, 0, 10, 105, 0, 0>>
@map_13 %{"i" => nil}
@bin_13 <<8, 0, 0, 0, 10, 105, 0, 0>>

@map14 %{"j" => %BSON.JavaScript{code: "1 + 2"}}
@bin14 <<18, 0, 0, 0, 13, 106, 0, 6, 0, 0, 0, 49, 32, 43, 32, 50, 0, 0>>
@map_14 %{"j" => %BSON.JavaScript{code: "1 + 2"}}
@bin_14 <<18, 0, 0, 0, 13, 106, 0, 6, 0, 0, 0, 49, 32, 43, 32, 50, 0, 0>>

@map15 %{"k" => %BSON.JavaScript{code: "a + b", scope: %{"a" => 2, "b" => 2}}}
@bin15 <<41, 0, 0, 0, 15, 107, 0, 33, 0, 0, 0, 6, 0, 0, 0, 97, 32, 43, 32, 98, 0, 19, 0, 0, 0, 16, 97, 0, 2, 0, 0, 0, 16, 98, 0, 2, 0, 0, 0, 0, 0>>
@map_15 %{"k" => %BSON.JavaScript{code: "a + b", scope: %{"a" => 2, "b" => 2}}}
@bin_15 <<41, 0, 0, 0, 15, 107, 0, 33, 0, 0, 0, 6, 0, 0, 0, 97, 32, 43, 32, 98, 0, 19, 0, 0, 0, 16, 97, 0, 2, 0, 0, 0, 16, 98, 0, 2, 0, 0, 0, 0, 0>>

@map16 %{"l" => 12_345}
@bin16 <<12, 0, 0, 0, 16, 108, 0, 57, 48, 0, 0, 0>>
@map_16 %{"l" => 12_345}
@bin_16 <<12, 0, 0, 0, 16, 108, 0, 57, 48, 0, 0, 0>>

@map17 %{"m" => %BSON.Timestamp{value: 1_423_458_185, ordinal: 9}}
@bin17 <<16, 0, 0, 0, 17, 109, 0, 9, 0, 0, 0, 137, 63, 216, 84, 0>>
@map_17 %{"m" => %BSON.Timestamp{value: 1_423_458_185, ordinal: 9}}
@bin_17 <<16, 0, 0, 0, 17, 109, 0, 9, 0, 0, 0, 137, 63, 216, 84, 0>>

@map18 %{"n" => 123_456_789_123_456}
@bin18 <<16, 0, 0, 0, 18, 110, 0, 128, 145, 15, 134, 72, 112, 0, 0, 0>>
@map_18 %{"n" => 123_456_789_123_456}
@bin_18 <<16, 0, 0, 0, 18, 110, 0, 128, 145, 15, 134, 72, 112, 0, 0, 0>>

@map19 %{"o" => :BSON_min}
@bin19 <<8, 0, 0, 0, 255, 111, 0, 0>>
@map_19 %{"o" => :BSON_min}
@bin_19 <<8, 0, 0, 0, 255, 111, 0, 0>>

@map20 %{"p" => :BSON_max}
@bin20 <<8, 0, 0, 0, 127, 112, 0, 0>>
@map_20 %{"p" => :BSON_max}
@bin_20 <<8, 0, 0, 0, 127, 112, 0, 0>>

@map21 %{"q" => %BSON.Binary{binary: <<1, 2, 3>>, subtype: :binary_old}}
@bin21 <<20, 0, 0, 0, 5, 113, 0, 7, 0, 0, 0, 2, 3, 0, 0, 0, 1, 2, 3, 0>>
@map_21 %{"q" => %BSON.Binary{binary: <<1, 2, 3>>, subtype: :binary_old}}
@bin_21 <<20, 0, 0, 0, 5, 113, 0, 7, 0, 0, 0, 2, 3, 0, 0, 0, 1, 2, 3, 0>>

@map22 %{"regex" => %BSON.Regex{pattern: "acme.*corp", options: "i"}}
@bin22 <<25, 0, 0, 0, 11, 114, 101, 103, 101, 120, 0, 97, 99, 109, 101, 46, 42, 99, 111, 114, 112, 0, 105, 0, 0>>
@map_22 %{"regex" => %BSON.Regex{pattern: "acme.*corp", options: "i"}}
@bin_22 <<25, 0, 0, 0, 11, 114, 101, 103, 101, 120, 0, 97, 99, 109, 101, 46, 42, 99, 111, 114, 112, 0, 105, 0, 0>>

@map23 %{"regex" => %BSON.Regex{pattern: "acme.*corp"}}
@bin23 <<24, 0, 0, 0, 11, 114, 101, 103, 101, 120, 0, 97, 99, 109, 101, 46, 42, 99, 111, 114, 112, 0, 0, 0>>
@map_23 %{"regex" => %BSON.Regex{pattern: "acme.*corp"}}
@bin_23 <<24, 0, 0, 0, 11, 114, 101, 103, 101, 120, 0, 97, 99, 109, 101, 46, 42, 99, 111, 114, 112, 0, 0, 0>>

@map24 %{"number" => %BSON.LongNumber{value: 123}}
@bin24 <<21, 0, 0, 0, 18, 110, 117, 109, 98, 101, 114, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0>>
@map_24 %{"number" => %BSON.LongNumber{value: 123}}
@bin_24 <<21, 0, 0, 0, 18, 110, 117, 109, 98, 101, 114, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0>>

@map25 %{"number" => Decimal.new("0.33")}
@bin25 <<29, 0, 0, 0, 19, 110, 117, 109, 98, 101, 114, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 48, 0>>
@map_25 %{"number" => Decimal.new("0.33")}
@bin_25 <<29, 0, 0, 0, 19, 110, 117, 109, 98, 101, 114, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 48, 0>>

@map26 %TestUser{}
@bin26 <<29, 0, 0, 0, 16, 97, 103, 101, 0, 27, 0, 0, 0, 2, 110, 97, 109, 101, 0, 5, 0, 0, 0, 74, 111, 104, 110, 0, 0>>
@map_26 %TestUser{}
@bin_26 <<29, 0, 0, 0, 16, 97, 103, 101, 0, 27, 0, 0, 0, 2, 110, 97, 109, 101, 0, 5, 0, 0, 0, 74, 111, 104, 110, 0, 0>>

test "encode" do
assert encode(@map1) == @bin1
assert encode(@map2) == @bin2
assert encode(@map3) == @bin3
assert encode(@map4) == @bin4
assert encode(@map5) == @bin5
assert encode(@map6) == @bin6
assert encode(@map7) == @bin7
assert encode(@map8) == @bin8
assert encode(@map9) == @bin9
assert encode(@map10) == @bin10
assert encode(@map11) == @bin11
assert encode(@map12) == @bin12
assert encode(@map13) == @bin13
assert encode(@map14) == @bin14
assert encode(@map15) == @bin15
assert encode(@map16) == @bin16
assert encode(@map17) == @bin17
assert encode(@map18) == @bin18
assert encode(@map19) == @bin19
assert encode(@map20) == @bin20
assert encode(@map21) == @bin21
assert encode(@map22) == @bin22
assert encode(@map23) == @bin23
assert encode(@map24) == @bin24
assert encode(@map25) == @bin25
assert encode(@map26) == @bin26
assert encode(@map_1) == @bin_1
assert encode(@map_2) == @bin_2
assert encode(@map_3) == @bin_3
assert encode(@map_4) == @bin_4
assert encode(@map_5) == @bin_5
assert encode(@map_6) == @bin_6
assert encode(@map_7) == @bin_7
assert encode(@map_8) == @bin_8
assert encode(@map_9) == @bin_9
assert encode(@map_10) == @bin_10
assert encode(@map_11) == @bin_11
assert encode(@map_12) == @bin_12
assert encode(@map_13) == @bin_13
assert encode(@map_14) == @bin_14
assert encode(@map_15) == @bin_15
assert encode(@map_16) == @bin_16
assert encode(@map_17) == @bin_17
assert encode(@map_18) == @bin_18
assert encode(@map_19) == @bin_19
assert encode(@map_20) == @bin_20
assert encode(@map_21) == @bin_21
assert encode(@map_22) == @bin_22
assert encode(@map_23) == @bin_23
assert encode(@map_24) == @bin_24
assert encode(@map_25) == @bin_25
assert encode(@map_26) == @bin_26
end

test "decode" do
assert decode(@bin1) == @map1
assert decode(@bin2) == @map2
assert decode(@bin3) == @map3
assert decode(@bin4) == @map4
assert decode(@bin5) == @map5
assert decode(@bin6) == @map6
assert decode(@bin7) == @map7
assert decode(@bin8) == @map8
assert decode(@bin9) == @map9
assert decode(@bin10) == @map10
assert decode(@bin11) == @map11
assert decode(@bin12) == @map12
assert decode(@bin13) == @map13
assert decode(@bin14) == @map14
assert decode(@bin15) == @map15
assert decode(@bin16) == @map16
assert decode(@bin17) == @map17
assert decode(@bin18) == @map18
assert decode(@bin19) == @map19
assert decode(@bin20) == @map20
assert decode(@bin21) == @map21
assert decode(@bin22) == @map22
assert decode(@bin23) == @map23
assert decode(@bin24) == %{"number" => 123}
assert decode(@bin25) == @map25
assert decode(@bin26) == %{"name" => "John", "age" => 27}
assert decode(@bin_1) == @map_1
assert decode(@bin_2) == @map_2
assert decode(@bin_3) == @map_3
assert decode(@bin_4) == @map_4
assert decode(@bin_5) == @map_5
assert decode(@bin_6) == @map_6
assert decode(@bin_7) == @map_7
assert decode(@bin_8) == @map_8
assert decode(@bin_9) == @map_9
assert decode(@bin_10) == @map_10
assert decode(@bin_11) == @map_11
assert decode(@bin_12) == @map_12
assert decode(@bin_13) == @map_13
assert decode(@bin_14) == @map_14
assert decode(@bin_15) == @map_15
assert decode(@bin_16) == @map_16
assert decode(@bin_17) == @map_17
assert decode(@bin_18) == @map_18
assert decode(@bin_19) == @map_19
assert decode(@bin_20) == @map_20
assert decode(@bin_21) == @map_21
assert decode(@bin_22) == @map_22
assert decode(@bin_23) == @map_23
assert decode(@bin_24) == %{"number" => 123}
assert decode(@bin_25) == @map_25
assert decode(@bin_26) == %{"name" => "John", "age" => 27}
end

test "keywords" do
Expand All @@ -155,51 +155,51 @@ defmodule BSONTest do
end

test "encode atom" do
assert encode(%{hello: "world"}) == @bin1
assert encode(%{hello: "world"}) == @bin_1
end

test "encode atom value" do
assert encode(%{"hello" => :world}) == @bin1
assert encode(%{"hello" => :world}) == @bin_1
end

test "decode BSON symbol into string" do
encoded = <<22, 0, 0, 0, 14, 104, 101, 108, 108, 111, 0, 6, 0, 0, 0, 119, 111, 114, 108, 100, 0, 0>>
assert decode(encoded) == @map1
assert decode(encoded) == @map_1
end

@mapPosInf %{"a" => :inf}
@binPosInf <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 240::little-integer-size(8), 127::little-integer-size(8), 0>>
@map_pos_inf %{"a" => :inf}
@bin_pos_inf <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 240::little-integer-size(8), 127::little-integer-size(8), 0>>

@mapNegInf %{"a" => :"-inf"}
@binNegInf <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 240::little-integer-size(8), 255::little-integer-size(8), 0>>
@map_neg_inf %{"a" => :"-inf"}
@bin_neg_inf <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 240::little-integer-size(8), 255::little-integer-size(8), 0>>

@mapNaN %{"a" => :NaN}
@binNaN <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 248::little-integer-size(8), 127::little-integer-size(8), 0>>
@binNaN2 <<16, 0, 0, 0, 1, 97, 0, 1, 0, 0, 0, 0, 0, 240::little-integer-size(8), 127::little-integer-size(8), 0>>
@map_nan %{"a" => :NaN}
@bin_nan <<16, 0, 0, 0, 1, 97, 0, 0, 0, 0, 0, 0, 0, 248::little-integer-size(8), 127::little-integer-size(8), 0>>
@bin_nan2 <<16, 0, 0, 0, 1, 97, 0, 1, 0, 0, 0, 0, 0, 240::little-integer-size(8), 127::little-integer-size(8), 0>>

test "decode float NaN" do
assert decode(@binNaN) == @mapNaN
assert decode(@binNaN2) == @mapNaN
assert decode(@bin_nan) == @map_nan
assert decode(@bin_nan2) == @map_nan
end

test "encode float NaN" do
assert encode(@mapNaN) == @binNaN
assert encode(@map_nan) == @bin_nan
end

test "decode float positive Infinity" do
assert decode(@binPosInf) == @mapPosInf
assert decode(@bin_pos_inf) == @map_pos_inf
end

test "encode float positive Infinity" do
assert encode(@mapPosInf) == @binPosInf
assert encode(@map_pos_inf) == @bin_pos_inf
end

test "decode float negative Infinity" do
assert decode(@binNegInf) == @mapNegInf
assert decode(@bin_neg_inf) == @map_neg_inf
end

test "encode float negative Infinity" do
assert encode(@mapNegInf) == @binNegInf
assert encode(@map_neg_inf) == @bin_neg_inf
end

test "mixing atoms with binaries" do
Expand Down

0 comments on commit 4fa2b48

Please sign in to comment.