2024-07-07 11:41:21 +02:00
|
|
|
defmodule WriteTest do
|
2024-07-07 19:05:32 +02:00
|
|
|
use ExUnit.Case, async: true
|
2024-07-07 18:23:14 +02:00
|
|
|
|
|
|
|
@moduledoc """
|
|
|
|
This module contains tests for the Amethyst.Minecraft.Write module.
|
|
|
|
"""
|
|
|
|
|
2024-07-07 11:41:21 +02:00
|
|
|
doctest Amethyst.Minecraft.Write
|
|
|
|
|
|
|
|
test "writing a varint" do
|
|
|
|
assert Amethyst.Minecraft.Write.varint(0) == <<0x00>>
|
|
|
|
assert Amethyst.Minecraft.Write.varint(127) == <<0x7F>>
|
|
|
|
assert Amethyst.Minecraft.Write.varint(128) == <<0x80, 0x01>>
|
|
|
|
assert Amethyst.Minecraft.Write.varint(255) == <<0xFF, 0x01>>
|
2024-07-08 22:45:57 +02:00
|
|
|
assert Amethyst.Minecraft.Write.varint(25_565) == <<0xDD, 0xC7, 0x01>>
|
2024-07-07 11:41:21 +02:00
|
|
|
assert Amethyst.Minecraft.Write.varint(2_147_483_647) == <<0xFF, 0xFF, 0xFF, 0xFF, 0x07>>
|
|
|
|
assert Amethyst.Minecraft.Write.varint(-1) == <<0xFF, 0xFF, 0xFF, 0xFF, 0x0F>>
|
|
|
|
assert Amethyst.Minecraft.Write.varint(-2_147_483_648) == <<0x80, 0x80, 0x80, 0x80, 0x08>>
|
|
|
|
end
|
|
|
|
|
|
|
|
test "writing a varlong" do
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(0) == <<0x00>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(127) == <<0x7F>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(128) == <<0x80, 0x01>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(255) == <<0xFF, 0x01>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(2_147_483_647) == <<0xFF, 0xFF, 0xFF, 0xFF, 0x07>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(9_223_372_036_854_775_807) == <<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F>>
|
|
|
|
assert Amethyst.Minecraft.Write.varlong(-1) == <<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01>>
|
|
|
|
end
|
|
|
|
|
|
|
|
test "writing a string" do
|
|
|
|
assert Amethyst.Minecraft.Write.string("Hello, world!") == <<0x0D, "Hello, world!">>
|
|
|
|
assert Amethyst.Minecraft.Write.string("") == <<0x00>>
|
|
|
|
end
|
|
|
|
end
|
2024-07-07 18:23:14 +02:00
|
|
|
|
|
|
|
defmodule ReadTest do
|
2024-07-07 19:05:32 +02:00
|
|
|
use ExUnit.Case, async: true
|
2024-07-07 18:23:14 +02:00
|
|
|
|
|
|
|
@moduledoc """
|
|
|
|
This module contains tests for the Amethyst.Minecraft.Read module.
|
|
|
|
"""
|
|
|
|
|
|
|
|
doctest Amethyst.Minecraft.Read
|
2024-07-07 19:05:32 +02:00
|
|
|
alias Amethyst.Minecraft.Read
|
2024-07-07 18:23:14 +02:00
|
|
|
|
|
|
|
test "reading a varint" do
|
2024-07-07 19:05:32 +02:00
|
|
|
assert Read.start(<<0x00>>) |> Read.varint() |> Read.stop() == {[0], ""}
|
|
|
|
assert Read.start(<<0x7F>>) |> Read.varint() |> Read.stop() == {[127], ""}
|
|
|
|
assert Read.start(<<0x80, 0x01>>) |> Read.varint() |> Read.stop() == {[128], ""}
|
|
|
|
assert Read.start(<<0xFF, 0x01>>) |> Read.varint() |> Read.stop() == {[255], ""}
|
|
|
|
assert Read.start(<<0xFF, 0xFF, 0xFF, 0xFF, 0x07>>) |> Read.varint() |> Read.stop() == {[2_147_483_647], ""}
|
|
|
|
assert Read.start(<<0xFF, 0xFF, 0xFF, 0xFF, 0x0F>>) |> Read.varint() |> Read.stop() == {[-1], ""}
|
|
|
|
assert Read.start(<<0x80, 0x80, 0x80, 0x80, 0x08>>) |> Read.varint() |> Read.stop() == {[-2_147_483_648], ""}
|
2024-07-07 18:23:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "reading a varlong" do
|
2024-07-07 19:05:32 +02:00
|
|
|
assert Read.start(<<0x00>>) |> Read.varlong() |> Read.stop() == {[0], ""}
|
|
|
|
assert Read.start(<<0x7F>>) |> Read.varlong() |> Read.stop() == {[127], ""}
|
|
|
|
assert Read.start(<<0x80, 0x01>>) |> Read.varlong() |> Read.stop() == {[128], ""}
|
|
|
|
assert Read.start(<<0xFF, 0x01>>) |> Read.varlong() |> Read.stop() == {[255], ""}
|
|
|
|
assert Read.start(<<0xFF, 0xFF, 0xFF, 0xFF, 0x07>>) |> Read.varlong() |> Read.stop() == {[2_147_483_647], ""}
|
|
|
|
assert Read.start(<<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F>>) |> Read.varlong() |> Read.stop() == {[9_223_372_036_854_775_807], ""}
|
|
|
|
assert Read.start(<<0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01>>) |> Read.varlong() |> Read.stop() == {[-1], ""}
|
2024-07-07 18:23:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "reading a string" do
|
2024-07-07 19:05:32 +02:00
|
|
|
assert Read.start(<<0x0D, "Hello, world!">>) |> Read.string() |> Read.stop() == {["Hello, world!"], ""}
|
|
|
|
assert Read.start(<<0x00>>) |> Read.string() |> Read.stop() == {[""], ""}
|
2024-07-07 18:23:14 +02:00
|
|
|
end
|
|
|
|
end
|