summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework/I18N/testNumberFormat.php
diff options
context:
space:
mode:
authorwei <>2006-01-06 05:32:33 +0000
committerwei <>2006-01-06 05:32:33 +0000
commit16660934cc48f357b1322bce7869158db2f7cb58 (patch)
treecd142f641e14c0338eb8847f00b572cb4f4603be /tests/UnitTests/framework/I18N/testNumberFormat.php
parented3e43d30524a76969fb7d42cb5e613c2e1a1d9a (diff)
Adding I18N unit test cases.
Diffstat (limited to 'tests/UnitTests/framework/I18N/testNumberFormat.php')
-rw-r--r--tests/UnitTests/framework/I18N/testNumberFormat.php113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/UnitTests/framework/I18N/testNumberFormat.php b/tests/UnitTests/framework/I18N/testNumberFormat.php
new file mode 100644
index 00000000..48342d9c
--- /dev/null
+++ b/tests/UnitTests/framework/I18N/testNumberFormat.php
@@ -0,0 +1,113 @@
+<?php
+
+//NOTE: This page require UTF-8 aware editors
+
+Prado::using('System.I18N.core.NumberFormat');
+
+class testNumberFormat extends UnitTestCase
+{
+ function testNumberFormat()
+ {
+ $this->UnitTestCase();
+ }
+
+ function testDefaultFormats()
+ {
+ $formatter = new NumberFormat();
+ $number = '123456789.125156';
+ $wanted = '123,456,789.125156';
+ $this->assertEqual($wanted, $formatter->format($number));
+
+ //currency
+ $wanted = 'US$123,456,789.13';
+ $this->assertEqual($wanted, $formatter->format($number,'c'));
+ }
+
+ function testLocalizedCurrencyFormats()
+ {
+ $fr = new NumberFormat('fr');
+ $de = new NumberFormat('de');
+ $ja = new NumberFormat('ja_JP');
+
+ $number = '123456789.125156';
+
+ //french
+ $wanted = '123 456 789,13 F';
+ $this->assertEqual($wanted, $fr->format($number,'c','FRF'));
+
+ //german
+ $wanted = 'DES 123.456.789,13';
+ $this->assertEqual($wanted, $de->format($number,'c','DES'));
+
+ //japanese
+ $wanted = '¥123,456,789';
+ $this->assertEqual($wanted, $ja->format($number,'c','JPY'));
+
+ //custom/unkown currency
+ $wanted = 'DLL123,456,789';
+ $this->assertEqual($wanted, $ja->format($number,'c','DLL'));
+ }
+
+ function testCustomFormat()
+ {
+ $formatter = new NumberFormat();
+ $number = '123456789.125156';
+
+ //primay and secondary grouping test
+ $pattern = '#,###,##.###';
+ $wanted = '1,234,567,89.125156';
+ $this->assertEqual($wanted, $formatter->format($number, $pattern));
+
+ //4 digits grouping test
+ $pattern = '#,####.###';
+ $wanted = '1,2345,6789.125156';
+ $this->assertEqual($wanted, $formatter->format($number, $pattern));
+
+ //custom percentage
+ $pattern = '#,###.00%';
+ $wanted = '123,456,789.13%';
+ $this->assertEqual($wanted, $formatter->format($number, $pattern));
+ }
+
+ function testPercentageFormat()
+ {
+ $formatter = new NumberFormat();
+ $number = '0.125156';
+ $wanted = '12%';
+ $this->assertEqual($wanted, $formatter->format($number, 'p'));
+ }
+
+ function testQuotes()
+ {
+ $formatter = new NumberFormat();
+ $number = '123456789.125156';
+
+ $pattern = "# o'clock";
+ $wanted = "123456789 o'clock";
+ $this->assertEqual($wanted, $formatter->format($number, $pattern));
+
+ }
+
+ function testPadding()
+ {
+ $formatter = new NumberFormat();
+ $number = '5';
+
+ $pattern = '0000';
+ $wanted = '0005';
+
+ //this should fail!!!
+ $this->assertEqual($wanted, $formatter->format($number, $pattern));
+ }
+
+ function testNegativeValue()
+ {
+ $formatter = new NumberFormat();
+ $number = "-1.2";
+
+ $wanted = "-1.2";
+ $this->assertEqual($wanted, $formatter->format($number));
+ }
+}
+
+?> \ No newline at end of file