source: Dev/branches/rest-dojo-ui/client/dojo/tests/string.js @ 263

Last change on this file since 263 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.4 KB
Line 
1define(["../main", "doh", "../string"], function(dojo, doh){
2
3doh.register("tests.string",
4        [
5                function test_string_pad(t){
6                        t.is("00001", dojo.string.pad("1", 5));
7                        t.is("000001", dojo.string.pad("000001", 5));
8                        t.is("10000", dojo.string.pad("1", 5, null, true));
9                },
10
11                function test_string_substitute(t){
12                        t.is("File 'foo.html' is not found in directory '/temp'.",
13                                dojo.string.substitute(
14                                        "File '${0}' is not found in directory '${1}'.",
15                                        ["foo.html","/temp"]
16                                )
17                        );
18                        t.is("File 'foo.html' is not found in directory '/temp'.",
19                                dojo.string.substitute(
20                                        "File '${name}' is not found in directory '${info.dir}'.",
21                                        {
22                                                name: "foo.html",
23                                                info: { dir: "/temp" }
24                                        }
25                                )
26                        );
27                        // Verify that an error is thrown!
28                        t.assertError(Error, dojo.string, "substitute", ["${x}", {y:1}]);
29                },
30
31                function test_string_substitute_transform(t){
32                        var getPrefix = function(str){
33                                // try to figure out the type
34                                var prefix = (str.charAt(0) == "/") ? "directory": "file";
35                                if(this.____prefix){
36                                        prefix = this.____prefix + prefix;
37                                }
38                                return prefix + " '" + str + "'";
39                        };
40
41                        var obj = {
42                                ____prefix: "...",
43                                getPrefix: getPrefix
44                        };
45
46                        t.is("file 'foo.html' is not found in directory '/temp'.",
47                                dojo.string.substitute(
48                                        "${0} is not found in ${1}.",
49                                        ["foo.html","/temp"],
50                                        getPrefix
51                                )
52                        );
53
54                        t.is("...file 'foo.html' is not found in ...directory '/temp'.",
55                                dojo.string.substitute(
56                                        "${0} is not found in ${1}.",
57                                        ["foo.html","/temp"],
58                                        obj.getPrefix, obj
59                                )
60                        );
61                },
62
63                function test_string_substitute_formatter(t){
64                        t.is("thinger -- howdy",
65                                dojo.string.substitute(
66                                        "${0:postfix}", ["thinger"], null, {
67                                                postfix: function(value, key){
68                                                        return value + " -- howdy";
69                                                }
70                                        }
71                                )
72                        );
73                },
74
75                function test_string_trim(t){
76                        t.is("astoria", dojo.string.trim("   \f\n\r\t      astoria           "));
77                        t.is("astoria", dojo.string.trim("astoria                            "));
78                        t.is("astoria", dojo.string.trim("                            astoria"));
79                        t.is("astoria", dojo.string.trim("astoria"));
80                        t.is("a", dojo.string.trim("   a   "));
81                },
82
83                function test_string_rep(t){
84                        t.is("aaaaa", dojo.string.rep("a", 5));
85                        t.is("abababab", dojo.string.rep("ab", 4));
86                        t.is("", dojo.string.rep("ab", 0));
87                        t.is("", dojo.string.rep("", 3));
88                }
89        ]
90);
91
92});
Note: See TracBrowser for help on using the repository browser.