diff --git a/test/taoensso/tower/tests/main.clj b/test/taoensso/tower/tests/main.clj index 4173008..4085d8d 100644 --- a/test/taoensso/tower/tests/main.clj +++ b/test/taoensso/tower/tests/main.clj @@ -10,20 +10,23 @@ ;;;; Localization -(given [s n] (expect s (tower/fmt :en-ZA n)) - "1,000.1" 1000.10 - "100,000,000.1" 100000000.10 - "1,000" 1000) - -(given [s n] (expect s (tower/fmt :en-US n)) - "1,000.1" 1000.10 - "100,000,000.1" 100000000.10 - "1,000" 1000) - -(given [s n] (expect s (tower/fmt :de-DE n)) - "1.000,1" 1000.10 - "100.000.000,1" 100000000.10 - "1.000" 1000) +(expect + (from-each [[s n] [["1,000.1" 1000.10] + ["100,000,000.1" 100000000.10] + ["1,000" 1000]]] + (= s (tower/fmt :en-za n)))) + +(expect + (from-each [[s n] [["1,000.1" 1000.10] + ["100,000,000.1" 100000000.10] + ["1,000" 1000]]] + (= s (tower/fmt :en-US n)))) + +(expect + (from-each [[s n] [["1.000,1" 1000.10] + ["100.000.000,1" 100000000.10] + ["1.000" 1000]]] + (= s (tower/fmt :de-DE n)))) (expect "1,000.1" (tower/fmt :en-US 1000.10)) (expect "1,000" (tower/fmt :en-US 1000.10 :integer)) @@ -33,79 +36,92 @@ (expect "1.000" (tower/fmt :de-DE 1000.10 :integer)) (expect "1.000,10 €" (tower/fmt :de-DE 1000.10 :currency)) -(given [s n] (expect s (tower/fmt :en-ZA n :percent)) - "314%" (float (/ 22 7)) - "200%" 2 - "50%" (float (/ 1 2)) - "75%" (float (/ 3 4))) - -(given [s n] (expect s (tower/fmt :en-ZA n :currency)) - "R 123.45" 123.45 - "R 12,345.00" 12345 - "R 123,456,789.00" 123456789 - "R 123,456,789.20" 123456789.20) - -(given [s n] (expect s (tower/fmt :en-US n :currency)) - "$123.45" 123.45 - "$12,345.00" 12345 - "$123,456,789.00" 123456789 - "$123,456,789.20" 123456789.20) - -(given [s n] (expect s (tower/fmt :de-DE n :currency)) - "123,45 €" 123.45 - "12.345,00 €" 12345 - "123.456.789,00 €" 123456789 - "123.456.789,20 €" 123456789.20) - -(given [n s] (expect n (tower/parse :en-ZA s)) - 1000.01 "1000.01" - 1000.01 "1,000.01" - 1000000.01 "1,000,000.01" - 1.23456 "1.23456") - -(given [n s] (expect n (tower/parse :en-US s)) - 1000.01 "1000.01" - 1000.01 "1,000.01" - 1000000.01 "1,000,000.01" - 1.23456 "1.23456") - -(given [n s] (expect n (tower/parse :de-DE s)) - 1000.01 "1000,01" - 1000.01 "1.000,01" - 1000000.01 "1.000.000,01" - 1.23456 "1,23456") - -(given [n s] (expect n (tower/parse :en-ZA s :currency)) - 123.45 "R 123.45" - 12345 "R 123,45" - 123456.01 "R 123,456.01" - 123456789.01 "R 123,456,789.01") - -(given [n s] (expect n (tower/parse :en-US s :currency)) - 123.45 "$123.45" - 12345 "$123,45" - 123456.01 "$123,456.01" - 123456789.01 "$123,456,789.01") - -(given [n s] (expect n (tower/parse :de-DE s :currency)) - 123.45 "123,45 €" - 12345 "123.45 €" - 123456.01 "123.456,01 €" - 123456789.01 "123.456.789,01 €") +(expect + (from-each [[s n] [["314%" (float (/ 22 7))] + ["200%" 2] + ["50%" (float (/ 1 2))] + ["75%" (float (/ 3 4))]]] + (= s (tower/fmt :en-ZA n :percent)))) + +(expect + (from-each [[s n] [["R 123.45" 123.45] + ["R 12,345.00" 12345] + ["R 123,456,789.00" 123456789] + ["R 123,456,789.20" 123456789.20]]] + (= s (tower/fmt :en-ZA n :currency)))) + +(expect + (from-each [[s n] [["$123.45" 123.45] + ["$12,345.00" 12345] + ["$123,456,789.00" 123456789] + ["$123,456,789.20" 123456789.20]]] + (= s (tower/fmt :en-US n :currency)))) + +(expect + (from-each [[s n] [["123,45 €" 123.45] + ["12.345,00 €" 12345] + ["123.456.789,00 €" 123456789] + ["123.456.789,20 €" 123456789.20]]] + (= s (tower/fmt :de-DE n :currency)))) + +(expect + (from-each [[n s] [[1000.01 "1000.01"] + [1000.01 "1,000.01"] + [1000000.01 "1,000,000.01"] + [1.23456 "1.23456"]]] + (= n (tower/parse :en-ZA s)))) + +(expect + (from-each [[n s] [[1000.01 "1000.01"] + [1000.01 "1,000.01"] + [1000000.01 "1,000,000.01"] + [1.23456 "1.23456"]]] + (= n (tower/parse :en-US s)))) + +(expect + (from-each [[n s] [[1000.01 "1000,01"] + [1000.01 "1.000,01"] + [1000000.01 "1.000.000,01"] + [1.23456 "1,23456"]]] + (= n (tower/parse :de-DE s)))) + +(expect + (from-each [[n s] [[123.45 "R 123.45"] + [12345 "R 123,45"] + [123456.01 "R 123,456.01"] + [123456789.01 "R 123,456,789.01"]]] + (= n (tower/parse :en-ZA s :currency)))) + +(expect + (from-each [[n s] [[123.45 "$123.45"] + [12345 "$123,45"] + [123456.01 "$123,456.01"] + [123456789.01 "$123,456,789.01"]]] + (= n (tower/parse :en-US s :currency)))) + +(expect + (from-each [[n s] [[123.45 "123,45 €"] + [12345 "123.45 €"] + [123456.01 "123.456,01 €"] + [123456789.01 "123.456.789,01 €"]]] + (= n (tower/parse :de-DE s :currency)))) (defn test-dt [y m d] (Date. (Date/UTC (- y 1900) (- m 1) d 0 0 0))) -(given [s y m d] (expect s (tower/fmt :en-ZA (test-dt y m d))) - "01 Feb 2012" 2012 2 1 - "25 Mar 2012" 2012 3 25) +(expect + (from-each [[s y m d] [["01 Feb 2012" 2012 2 1] + ["25 Mar 2012" 2012 3 25]]] + (= s (tower/fmt :en-ZA (test-dt y m d))))) -(given [s y m d] (expect s (tower/fmt :en-US (test-dt y m d))) - "Feb 1, 2012" 2012 2 1 - "Mar 25, 2012" 2012 3 25) +(expect + (from-each [[s y m d] [["Feb 1, 2012" 2012 2 1] + ["Mar 25, 2012" 2012 3 25]]] + (= s (tower/fmt :en-US (test-dt y m d))))) -(given [s y m d] (expect s (tower/fmt :de-DE (test-dt y m d))) - "01.02.2012" 2012 2 1 - "25.03.2012" 2012 3 25) +(expect + (from-each [[s y m d] [["01.02.2012" 2012 2 1] + ["25.03.2012" 2012 3 25]]] + (= s (tower/fmt :de-DE (test-dt y m d))))) (def pt (tower/make-t tower/example-tconfig))