3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
9 # This file contains tests for functions in wfpl/encode.php
11 # See wfpl/test.php for details on how to run or create tests
14 require_once(__DIR__.'/../'.'encode.php');
16 function _test_encode_pulled($field, $value, $correct) {
17 unit_test_func('enc_pulled', $value, $field, $correct);
20 function test_encode_pulled() {
21 pulldown('array', array('one', 'two', "symbols&'\""));
22 _test_encode_pulled('array', 'one', 'one');
23 _test_encode_pulled('array', 'One', 'One'); # not found is unchanged
24 _test_encode_pulled('array', 'two', 'two');
25 _test_encode_pulled('array', 'symbols&\'"', 'symbols&\'"');
27 pulldown('mixed', array(array('one', 'Eno'), 'two', array('symbols&\'"', 'Slobmys')));
28 _test_encode_pulled('mixed', 'one', 'Eno');
29 _test_encode_pulled('mixed', 'One', 'One'); # not found is unchanged
30 _test_encode_pulled('mixed', 'two', 'two');
31 _test_encode_pulled('mixed', 'symbols&\'"', 'symbols&\'"'); # not found is unchanged
32 _test_encode_pulled('mixed', 'symbols&\'"', 'Slobmys');
34 pulldown('array_2d', array(array('one', 'Eno'), array('two', 'Owt'), array('symbols&\'"', 'Slobmys')));
35 _test_encode_pulled('array_2d', 'one', 'Eno');
36 _test_encode_pulled('array_2d', 'One', 'One'); # not found in unchanged
37 _test_encode_pulled('array_2d', 'two', 'Owt');
38 _test_encode_pulled('array_2d', 'symbols&\'"', 'symbols&\'"'); # not found in unchanged
41 function test_encode_misc() {
42 unit_test_func('enc_tab', '', '');
43 unit_test_func('enc_tab', "\n", "\t\n\t");
44 unit_test_func('enc_tab', "a", "\ta");
45 unit_test_func('enc_tab', "a\n", "\ta\n\t");
46 unit_test_func('enc_tab', "\t", "\t\t");
47 unit_test_func('enc_tab', "\n\na", "\t\n\t\n\ta");
48 unit_test_func('enc_tab', "\t\n\t\n\ta", "\t\t\n\t\t\n\t\ta");
51 function encode_unit_tests_main() {