dumper_test.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // $Id: dumper_test.php 1505 2007-04-30 23:39:59Z lastcraft $
  3. require_once(dirname(__FILE__) . '/../autorun.php');
  4. class DumperDummy {
  5. }
  6. class TestOfTextFormatting extends UnitTestCase {
  7. function testClipping() {
  8. $dumper = new SimpleDumper();
  9. $this->assertEqual(
  10. $dumper->clipString("Hello", 6),
  11. "Hello",
  12. "Hello, 6->%s");
  13. $this->assertEqual(
  14. $dumper->clipString("Hello", 5),
  15. "Hello",
  16. "Hello, 5->%s");
  17. $this->assertEqual(
  18. $dumper->clipString("Hello world", 3),
  19. "Hel...",
  20. "Hello world, 3->%s");
  21. $this->assertEqual(
  22. $dumper->clipString("Hello world", 6, 3),
  23. "Hello ...",
  24. "Hello world, 6, 3->%s");
  25. $this->assertEqual(
  26. $dumper->clipString("Hello world", 3, 6),
  27. "...o w...",
  28. "Hello world, 3, 6->%s");
  29. $this->assertEqual(
  30. $dumper->clipString("Hello world", 4, 11),
  31. "...orld",
  32. "Hello world, 4, 11->%s");
  33. $this->assertEqual(
  34. $dumper->clipString("Hello world", 4, 12),
  35. "...orld",
  36. "Hello world, 4, 12->%s");
  37. }
  38. function testDescribeNull() {
  39. $dumper = new SimpleDumper();
  40. $this->assertPattern('/null/i', $dumper->describeValue(null));
  41. }
  42. function testDescribeBoolean() {
  43. $dumper = new SimpleDumper();
  44. $this->assertPattern('/boolean/i', $dumper->describeValue(true));
  45. $this->assertPattern('/true/i', $dumper->describeValue(true));
  46. $this->assertPattern('/false/i', $dumper->describeValue(false));
  47. }
  48. function testDescribeString() {
  49. $dumper = new SimpleDumper();
  50. $this->assertPattern('/string/i', $dumper->describeValue('Hello'));
  51. $this->assertPattern('/Hello/', $dumper->describeValue('Hello'));
  52. }
  53. function testDescribeInteger() {
  54. $dumper = new SimpleDumper();
  55. $this->assertPattern('/integer/i', $dumper->describeValue(35));
  56. $this->assertPattern('/35/', $dumper->describeValue(35));
  57. }
  58. function testDescribeFloat() {
  59. $dumper = new SimpleDumper();
  60. $this->assertPattern('/float/i', $dumper->describeValue(0.99));
  61. $this->assertPattern('/0\.99/', $dumper->describeValue(0.99));
  62. }
  63. function testDescribeArray() {
  64. $dumper = new SimpleDumper();
  65. $this->assertPattern('/array/i', $dumper->describeValue(array(1, 4)));
  66. $this->assertPattern('/2/i', $dumper->describeValue(array(1, 4)));
  67. }
  68. function testDescribeObject() {
  69. $dumper = new SimpleDumper();
  70. $this->assertPattern(
  71. '/object/i',
  72. $dumper->describeValue(new DumperDummy()));
  73. $this->assertPattern(
  74. '/DumperDummy/i',
  75. $dumper->describeValue(new DumperDummy()));
  76. }
  77. }
  78. ?>