Consolidate completely stateless tests into doctests
Removing dupes
This commit is contained in:
@@ -16,6 +16,44 @@ defmodule MusicBrainz.ReleaseSearchResult do
|
||||
}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the physical format of a release based on its media.
|
||||
|
||||
Returns `:multi` when a release contains different format types.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [%{format: "CD", disc_count: 1, track_count: 11}]
|
||||
...> })
|
||||
:cd
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [%{format: "12\\" Vinyl", disc_count: 0, track_count: 8}]
|
||||
...> })
|
||||
:vinyl
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [
|
||||
...> %{format: "CD", disc_count: 1, track_count: 10},
|
||||
...> %{format: "CD", disc_count: 1, track_count: 9}
|
||||
...> ]
|
||||
...> })
|
||||
:cd
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [
|
||||
...> %{format: "CD", disc_count: 0, track_count: 11},
|
||||
...> %{format: "DVD-Video", disc_count: 0, track_count: 22}
|
||||
...> ]
|
||||
...> })
|
||||
:multi
|
||||
|
||||
"""
|
||||
def format(release_search_result) do
|
||||
sorted_frequencies =
|
||||
release_search_result.media
|
||||
|
||||
@@ -276,12 +276,45 @@ defmodule MusicLibrary.Country do
|
||||
iex> MusicLibrary.Country.to_emoji("US")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("PL")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB")
|
||||
"🇬🇧"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("us")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("pl")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-SCT")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-WLS")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-ENG")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-CYM") == MusicLibrary.Country.to_emoji("GB-WLS")
|
||||
true
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("USA")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GBR")
|
||||
"🇬🇧"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("POL")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("en-US")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("pl-PL")
|
||||
"🇵🇱"
|
||||
|
||||
"""
|
||||
@spec to_emoji(String.t()) :: String.t()
|
||||
def to_emoji(code) when is_binary(code) do
|
||||
|
||||
@@ -1,4 +1,26 @@
|
||||
defmodule MusicLibraryWeb.Duration do
|
||||
@moduledoc """
|
||||
Formats durations from milliseconds to human-readable strings.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Formats a duration in milliseconds as a human-readable string.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(30_000)
|
||||
"0:30"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(90_000)
|
||||
"1:30"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(3_723_000)
|
||||
"1:02:03"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(0)
|
||||
"0:00"
|
||||
|
||||
"""
|
||||
def format_duration(milliseconds) do
|
||||
milliseconds
|
||||
|> System.convert_time_unit(:millisecond, :second)
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
defmodule LastFm.SessionTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias LastFm.Session
|
||||
|
||||
doctest LastFm.Session
|
||||
|
||||
@xml """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lfm status="ok">
|
||||
<session>
|
||||
<name>cloud8421</name>
|
||||
<key>super-secret</key>
|
||||
<subscriber>1</subscriber>
|
||||
</session>
|
||||
</lfm>
|
||||
"""
|
||||
|
||||
test "parse/1" do
|
||||
assert %Session{
|
||||
name: "cloud8421",
|
||||
key: "super-secret",
|
||||
pro: true
|
||||
} == Session.parse(@xml)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,79 +1,5 @@
|
||||
defmodule MusicBrainz.ReleaseSearchResultTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias MusicBrainz.ReleaseSearchResult
|
||||
|
||||
@single_cd %MusicBrainz.ReleaseSearchResult{
|
||||
id: "dc393148-be34-4056-be66-b2b95905c5c1",
|
||||
title: "Equally Cursed and Blessed",
|
||||
release_group: %{
|
||||
id: "c35fc446-65cc-3645-939b-1b3782e60639",
|
||||
type: :album,
|
||||
title: "Equally Cursed and Blessed"
|
||||
},
|
||||
artists: "Catatonia",
|
||||
date: "1999-04-12",
|
||||
barcode: "639842709422",
|
||||
media: [%{format: "CD", disc_count: 5, track_count: 11}]
|
||||
}
|
||||
|
||||
@double_cd %MusicBrainz.ReleaseSearchResult{
|
||||
id: "51ebc32b-d21f-4466-9297-94b6a3e0e6ba",
|
||||
title: "Rock in Rio",
|
||||
release_group: %{
|
||||
id: "ea6dac58-887a-35a8-86ff-08c56e6bf047",
|
||||
type: :album,
|
||||
title: "Rock in Rio"
|
||||
},
|
||||
artists: "Iron Maiden",
|
||||
date: "2002-03-21",
|
||||
barcode: "724353864309",
|
||||
media: [
|
||||
%{format: "CD", disc_count: 1, track_count: 10},
|
||||
%{format: "CD", disc_count: 1, track_count: 9}
|
||||
]
|
||||
}
|
||||
|
||||
@single_vinyl %MusicBrainz.ReleaseSearchResult{
|
||||
id: "3af1f610-9df1-4a48-8874-78cd64e25888",
|
||||
title: "Somewhere in Time",
|
||||
release_group: %{
|
||||
id: "a5fe4d2d-3aab-3e86-91ad-22a3fe16c4f2",
|
||||
type: :album,
|
||||
title: "Somewhere in Time"
|
||||
},
|
||||
artists: "Iron Maiden",
|
||||
date: "1986-09-29",
|
||||
barcode: "5099924059718",
|
||||
media: [%{format: "12\" Vinyl", disc_count: 0, track_count: 8}]
|
||||
}
|
||||
|
||||
@multi %MusicBrainz.ReleaseSearchResult{
|
||||
id: "804e4781-bc17-496e-8abd-d61c7173391c",
|
||||
title: "Live With the Plovdiv Psychotic Symphony",
|
||||
release_group: %{
|
||||
id: "887898c3-ef40-4162-88d3-1fbc58ee2d09",
|
||||
type: :album,
|
||||
title: "Live With the Plovdiv Psychotic Symphony"
|
||||
},
|
||||
artists: "Sons of Apollo, Пловдивска филхармония",
|
||||
date: "2019-08-30",
|
||||
barcode: "190759669228",
|
||||
media: [
|
||||
%{format: "CD", disc_count: 0, track_count: 11},
|
||||
%{format: "CD", disc_count: 1, track_count: 10},
|
||||
%{format: "CD", disc_count: 0, track_count: 3},
|
||||
%{format: "DVD-Video", disc_count: 0, track_count: 22},
|
||||
%{format: "Blu-ray", disc_count: 0, track_count: 42}
|
||||
]
|
||||
}
|
||||
|
||||
describe "format/1" do
|
||||
test "it returns the format of the release" do
|
||||
assert ReleaseSearchResult.format(@single_cd) == :cd
|
||||
assert ReleaseSearchResult.format(@single_vinyl) == :vinyl
|
||||
assert ReleaseSearchResult.format(@double_cd) == :cd
|
||||
assert ReleaseSearchResult.format(@multi) == :multi
|
||||
end
|
||||
end
|
||||
doctest MusicBrainz.ReleaseSearchResult
|
||||
end
|
||||
|
||||
@@ -1,39 +1,5 @@
|
||||
defmodule MusicLibrary.CountryTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias MusicLibrary.Country
|
||||
|
||||
describe "to_emoji/1" do
|
||||
test "converts alpha-2 codes" do
|
||||
assert Country.to_emoji("US") == "🇺🇸"
|
||||
assert Country.to_emoji("PL") == "🇵🇱"
|
||||
assert Country.to_emoji("GB") == "🇬🇧"
|
||||
end
|
||||
|
||||
test "is case insensitive" do
|
||||
assert Country.to_emoji("us") == "🇺🇸"
|
||||
assert Country.to_emoji("pl") == "🇵🇱"
|
||||
end
|
||||
|
||||
test "converts subdivision codes" do
|
||||
assert Country.to_emoji("GB-SCT") == "🏴"
|
||||
assert Country.to_emoji("GB-WLS") == "🏴"
|
||||
assert Country.to_emoji("GB-ENG") == "🏴"
|
||||
end
|
||||
|
||||
test "maps GB-CYM to GB-WLS" do
|
||||
assert Country.to_emoji("GB-CYM") == Country.to_emoji("GB-WLS")
|
||||
end
|
||||
|
||||
test "converts alpha-3 codes" do
|
||||
assert Country.to_emoji("USA") == "🇺🇸"
|
||||
assert Country.to_emoji("GBR") == "🇬🇧"
|
||||
assert Country.to_emoji("POL") == "🇵🇱"
|
||||
end
|
||||
|
||||
test "converts IETF language tags" do
|
||||
assert Country.to_emoji("en-US") == "🇺🇸"
|
||||
assert Country.to_emoji("pl-PL") == "🇵🇱"
|
||||
end
|
||||
end
|
||||
doctest MusicLibrary.Country
|
||||
end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
defmodule MusicLibraryWeb.DurationTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
doctest MusicLibraryWeb.Duration
|
||||
end
|
||||
Reference in New Issue
Block a user