more tests

This commit is contained in:
Graham McIntire 2025-06-22 15:44:35 -05:00
parent 65ca631115
commit 77276eb2a1
No known key found for this signature in database
5 changed files with 10 additions and 26 deletions

View file

@ -1,6 +1 @@
[
{{"lib/parser.ex", 1}, :pattern_match, "The pattern can never match the type."},
{{"lib/parser.ex", 893}, :pattern_match, "The pattern can never match the type."},
{{"lib/parser.ex", 324}, :pattern_match_cov,
"The pattern :variable_ can never match, because previous clauses completely cover the type {:error, <<_::224>>}."}
]
[]

View file

@ -1154,7 +1154,7 @@ defmodule AprsWeb.MapLive.Index do
{lat1, lng1, _} = MapHelpers.get_coordinates(packet1)
{lat2, lng2, _} = MapHelpers.get_coordinates(packet2)
abs(lat1 - lat2) > 0.00001 || abs(lng1 - lng2) > 0.00001
abs(lat1 - lat2) > 0.0001 || abs(lng1 - lng2) > 0.0001
end
# Fetch historical packets from the database

View file

@ -59,7 +59,7 @@
%{} = data_ext -> Map.get(data_ext, :latitude) || Map.get(data_ext, "latitude")
_ -> nil
end %>
{if lat,
{if not is_nil(lat),
do:
(is_float(lat) and :io_lib.format("~.6f", [lat]) |> List.to_string()) or
(is_binary(lat) and Regex.replace(~r/(\d+\.\d{1,6})\d*/, lat, "\\1")) or lat,
@ -80,7 +80,7 @@
%{} = data_ext -> Map.get(data_ext, :longitude) || Map.get(data_ext, "longitude")
_ -> nil
end %>
{if lon,
{if not is_nil(lon),
do:
(is_float(lon) and :io_lib.format("~.6f", [lon]) |> List.to_string()) or
(is_binary(lon) and Regex.replace(~r/(\d+\.\d{1,6})\d*/, lon, "\\1")) or lon,

View file

@ -58,6 +58,7 @@ defmodule Parser do
def parse(_), do: {:error, :invalid_packet}
@spec do_parse(String.t()) :: parse_result()
defp do_parse(message) do
with {:ok, [sender, path, data]} <- split_packet(message),
{:ok, callsign_parts} <- parse_callsign(sender),
@ -101,12 +102,6 @@ defmodule Parser do
data_extended: data_extended,
received_at: DateTime.truncate(DateTime.utc_now(), :microsecond)
}}
else
{:error, reason} when is_binary(reason) ->
case reason do
"Invalid packet format" -> {:error, "Invalid packet format"}
_ -> {:error, reason}
end
end
rescue
_ ->
@ -288,7 +283,7 @@ defmodule Parser do
def parse_data(:raw_gps_ultimeter, _destination, data) do
case Parser.Helpers.parse_nmea_sentence(data) do
{:error, error} when is_binary(error) ->
{:error, error} ->
%{
data_type: :raw_gps_ultimeter,
error: error,
@ -297,16 +292,6 @@ defmodule Parser do
latitude: nil,
longitude: nil
}
_ ->
%{
data_type: :raw_gps_ultimeter,
error: "Invalid NMEA sentence",
nmea_type: nil,
raw_data: data,
latitude: nil,
longitude: nil
}
end
end

View file

@ -9,6 +9,10 @@ defmodule Parser.AX25Test do
assert {:ok, {"CALL", "1"}} = AX25.parse_callsign("CALL-1")
end
test "parses callsign with multiple dashes" do
assert {:ok, {"CALL-1-EXTRA", "0"}} = AX25.parse_callsign("CALL-1-EXTRA")
end
test "parses callsign without dash" do
assert {:ok, {"CALL", "0"}} = AX25.parse_callsign("CALL")
end