test coverage
This commit is contained in:
parent
28fc5a1a84
commit
cb0e0b84e1
2 changed files with 69 additions and 12 deletions
|
|
@ -3,4 +3,4 @@ description:
|
|||
globs:
|
||||
alwaysApply: true
|
||||
---
|
||||
This is an elixir & phoenix project that uses esbuild and as much liveview as possible. Do not directly try to interact with npm. Ensure liveview is used as much as possible to minimize javascript. When writing or changing code, ensure the tests still pass and you did not break other parts of the code by running "mix test". Ensure you are writing idiomatic elixir and using as much function and pattern matching as possible instead of if/case conditionals. Keep your responses breif and do not say "you're right" or echo back what I've said. Keep the output short and sweet only telling me issues that come up or what you've done. Fix any compile warnings you create or encounter as well. Do not be emotional, be straight to the point and do not use fluff words.
|
||||
This is an elixir & phoenix project that uses esbuild and as much liveview as possible. Do not directly try to interact with npm. Ensure liveview is used as much as possible to minimize javascript. When writing or changing code, ensure the tests still pass and you did not break other parts of the code by running "mix test". Ensure you are writing idiomatic elixir and using as much function and pattern matching as possible instead of if/case conditionals. Keep your responses breif and do not say "you're right" or echo back what I've said. Keep the output short and sweet only telling me issues that come up or what you've done. Fix any compile warnings you create or encounter as well. Do not be emotional, be straight to the point and do not use fluff words. Do not interact directly with git by committing or pushing or pulling.
|
||||
|
|
|
|||
|
|
@ -1,22 +1,79 @@
|
|||
defmodule Parser.ItemTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnitProperties
|
||||
|
||||
alias Parser.Item
|
||||
|
||||
describe "parse/1" do
|
||||
test "returns a map with :data_type => :item for valid input" do
|
||||
result = Item.parse(")ITEM!4903.50N/07201.75W>Test item")
|
||||
assert is_map(result)
|
||||
assert result[:data_type] == :item
|
||||
test "parses an item with uncompressed position" do
|
||||
result = Item.parse(")GATE!4903.50N/07201.75W>Test item")
|
||||
|
||||
assert result.data_type == :item
|
||||
assert result.item_name == "GATE"
|
||||
assert result.live_killed == "!"
|
||||
assert_in_delta Decimal.to_float(result.latitude), 49.0583, 0.0001
|
||||
assert_in_delta Decimal.to_float(result.longitude), -72.0292, 0.0001
|
||||
assert result.position_format == :uncompressed
|
||||
assert result.symbol_code == ">"
|
||||
assert result.symbol_table_id == "/"
|
||||
assert result.comment == "Test item"
|
||||
end
|
||||
|
||||
property "always returns a map with :data_type == :item for any string" do
|
||||
check all s <- StreamData.string(:ascii, min_length: 1, max_length: 30) do
|
||||
result = Item.parse(s)
|
||||
assert is_map(result)
|
||||
assert result[:data_type] == :item
|
||||
end
|
||||
test "parses an item with compressed position" do
|
||||
result = Item.parse(")An_Item_ _/5L`a=;s#_comment")
|
||||
|
||||
assert result.data_type == :item
|
||||
assert result.item_name == "An_Item_"
|
||||
assert result.live_killed == "_"
|
||||
assert result.position_format == :compressed
|
||||
assert result.symbol_table_id == "/"
|
||||
assert result.symbol_code == "_"
|
||||
assert result.compression_type == "m"
|
||||
assert result.comment == "ment"
|
||||
{:ok, lat} = result.latitude
|
||||
{:ok, lon} = result.longitude
|
||||
assert is_float(lat)
|
||||
assert is_float(lon)
|
||||
end
|
||||
|
||||
test "parses an item with no position data" do
|
||||
result = Item.parse(")Item!No Position Data")
|
||||
|
||||
assert result == %{
|
||||
comment: "No Position Data",
|
||||
data_type: :item,
|
||||
item_name: "Item",
|
||||
live_killed: "!",
|
||||
position_format: :unknown
|
||||
}
|
||||
end
|
||||
|
||||
test "handles item with no regex match on item_name_and_data" do
|
||||
result = Item.parse(")This does not match the regex")
|
||||
|
||||
assert result == %{
|
||||
data_type: :item,
|
||||
item_name: "This does not match the regex",
|
||||
raw_data: ")This does not match the regex"
|
||||
}
|
||||
end
|
||||
|
||||
test "parses raw data with position information" do
|
||||
result = Item.parse(" raw data 4903.50N/07201.75W with position")
|
||||
assert result.data_type == :item
|
||||
assert result.raw_data == " raw data 4903.50N/07201.75W with position"
|
||||
assert_in_delta Decimal.to_float(result.latitude), 49.0583, 0.0001
|
||||
assert_in_delta Decimal.to_float(result.longitude), -72.0292, 0.0001
|
||||
end
|
||||
|
||||
test "handles raw data without position information" do
|
||||
result = Item.parse("some other random data")
|
||||
assert result == %{raw_data: "some other random data", data_type: :item}
|
||||
end
|
||||
|
||||
test "parses an item starting with %" do
|
||||
result = Item.parse("%GATE!4903.50N/07201.75W>Test item")
|
||||
assert result.data_type == :item
|
||||
assert result.item_name == "GATE"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue