-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
defmodule Money.Mixfile do | ||
use Mix.Project | ||
|
||
@version "3.1.1" | ||
@version "3.2.0" | ||
|
||
def project do | ||
[ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule MoneyTest.Parse do | ||
use ExUnit.Case | ||
|
||
describe "Money.parse/2 " do | ||
test "parses with currency code in front" do | ||
assert Money.parse("USD 100") == Money.new(:USD, 100) | ||
assert Money.parse("USD100") == Money.new(:USD, 100) | ||
assert Money.parse("USD 100 ") == Money.new(:USD, 100) | ||
assert Money.parse("USD100 ") == Money.new(:USD, 100) | ||
assert Money.parse("USD 100.00") == Money.new(:USD, "100.00") | ||
end | ||
|
||
test "parses with currency code out back" do | ||
assert Money.parse("100 USD") == Money.new(:USD, 100) | ||
assert Money.parse("100USD") == Money.new(:USD, 100) | ||
assert Money.parse("100 USD ") == Money.new(:USD, 100) | ||
assert Money.parse("100USD ") == Money.new(:USD, 100) | ||
assert Money.parse("100.00USD") == Money.new(:USD, "100.00") | ||
end | ||
|
||
test "parses with locale specific separators" do | ||
assert Money.parse("100,00USD", locale: "de") == Money.new(:USD, "100.00") | ||
end | ||
|
||
test "parsing fails" do | ||
assert Money.parse("100") == {:error, | ||
{Money.Invalid, | ||
"A currency code must be specified but was not found in \"100\""}} | ||
|
||
assert Money.parse("EUR") == {:error, | ||
{Money.Invalid, "An amount must be specified but was not found in \"EUR\""}} | ||
|
||
assert Money.parse("EUR 100 USD") == | ||
{:error, {Money.Invalid, "A currency code can only be specified once. Found both \"EUR\" and \"USD\"."}} | ||
|
||
string = "EUR 100 And some bogus extra stuff" | ||
assert {:error, {Money.Invalid, "Could not parse \"" <> string <> "\"."}} == Money.parse(string) | ||
|
||
string = "100 EUR And some bogus extra stuff" | ||
assert {:error, {Money.Invalid, "Could not parse \"" <> string <> "\"."}} == Money.parse(string) | ||
end | ||
end | ||
end |