JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added unit tests for format_options
authorJason Woofenden <jason@jasonwoof.com>
Fri, 9 Apr 2010 17:47:33 +0000 (13:47 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Fri, 9 Apr 2010 17:53:01 +0000 (13:53 -0400)
unit_tests/db.php
unit_tests/format.php

index 4906f1b..f6b5325 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-#  Copyright (C) 2009 Jason Woofenden
+#  Copyright (C) 2010 Jason Woofenden
 #
 #  This program is free software: you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
index 21a1f74..dac002d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-#  Copyright (C) 2009 Jason Woofenden
+#  Copyright (C) 2010 Jason Woofenden
 #
 #  This program is free software: you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -45,6 +45,9 @@ function test_format_money() {
        $errors += _test_format_money('0', '$0', '$0.00');
        $errors += _test_format_money('0.0', '$0', '$0.00');
        $errors += _test_format_money('0.00', '$0', '$0.00');
+       $errors += _test_format_money('00.00', '$0', '$0.00');
+       $errors += _test_format_money('0.000', '$0', '$0.00');
+       $errors += _test_format_money('0000.00000', '$0', '$0.00');
        $errors += _test_format_money('0.01', '$0', '$0.01');
        $errors += _test_format_money('0.51', '$1', '$0.51');
        $errors += _test_format_money('2.05', '$2', '$2.05');
@@ -179,7 +182,6 @@ function test_format_misc() {
 
 
        /* FIXME test these
-       format_options($str, $name)
        format_filename($str, $allow_uppercase = false)
        format_path($str, $allow_uppercase = false)
        client_path_to_filename($path)
@@ -207,9 +209,42 @@ function test_format_misc() {
 }
 
 # returns number of errors
+function _test_format_options($field, $value, $correct) {
+       $ret = format_options($value, $field);
+       if($ret !== $correct) {
+               message("format_options($value, $field) returned \"$ret\" instead of \"$correct\"");
+               return 1;
+       }
+       return 0;
+}
+
+
+function test_format_options() {
+       $errors = 0;
+       pulldown('array', array('one', 'two', "symbols&amp;'\""), PULLDOWN_ARRAY);
+       $errors +=_test_format_options('array', 'one', 'one');
+       $errors +=_test_format_options('array', 'One', '');
+       $errors +=_test_format_options('array', 'two', 'two');
+       $errors +=_test_format_options('array', 'symbols&amp;\'"', 'symbols&amp;\'"');
+       pulldown('hash', array('one' => 'Eno', 'two' => 'Owt', 'symbols&amp;\'"' => 'Slobmys'), PULLDOWN_HASH);
+       $errors +=_test_format_options('hash', 'one', 'one');
+       $errors +=_test_format_options('hash', 'One', '');
+       $errors +=_test_format_options('hash', 'two', 'two');
+       $errors +=_test_format_options('hash', 'symbols&\'"', '');
+       pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&amp;\'"', 'Slobmys')), PULLDOWN_2D);
+       $errors +=_test_format_options('array_2d', 'one', 'one');
+       $errors +=_test_format_options('array_2d', 'One', '');
+       $errors +=_test_format_options('array_2d', 'two', 'two');
+       $errors +=_test_format_options('array_2d', 'symbols&amp;amp;\'"', '');
+
+       return $errors;
+}
+
+# returns number of errors
 function format_unit_tests_main() {
        $errors = 0;
        $errors += test_format_money();
        $errors += test_format_misc();
+       $errors += test_format_options();
        return $errors;
 }