Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.FlakeIdTest do
  5. use Pleroma.DataCase
  6. import Kernel, except: [to_string: 1]
  7. import Pleroma.FlakeId
  8. describe "fake flakes (compatibility with older serial integers)" do
  9. test "from_string/1" do
  10. fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
  11. assert from_string("42") == fake_flake
  12. assert from_string(42) == fake_flake
  13. end
  14. test "zero or -1 is a null flake" do
  15. fake_flake = <<0::integer-size(128)>>
  16. assert from_string("0") == fake_flake
  17. assert from_string("-1") == fake_flake
  18. end
  19. test "to_string/1" do
  20. fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
  21. assert to_string(fake_flake) == "42"
  22. end
  23. end
  24. test "ecto type behaviour" do
  25. flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>>
  26. flake_s = "9eoozpwTul5mjSEDRI"
  27. assert cast(flake) == {:ok, flake_s}
  28. assert cast(flake_s) == {:ok, flake_s}
  29. assert load(flake) == {:ok, flake_s}
  30. assert load(flake_s) == {:ok, flake_s}
  31. assert dump(flake_s) == {:ok, flake}
  32. assert dump(flake) == {:ok, flake}
  33. end
  34. end