~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/substitute/tests/substitute.html

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!doctype html>
2
 
<html>
3
 
<head>
4
 
<title>YUI substitute Tests</title>
5
 
</head>
6
 
 
7
 
<body class="yui3-skin-sam">
8
 
<h1>substitute Tests</h1>
9
 
<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
10
 
 
11
 
<script type="text/javascript" src="../../../build/yui/yui.js"></script>
12
 
<script type="text/javascript">
13
 
 
14
 
(function() {
15
 
    YUI({
16
 
        filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
17
 
        allowRollup: false,
18
 
        useBrowserConsole: false
19
 
    }).use("dump", "test", "console", "event-custom", function(Y) {
20
 
 
21
 
        var button = Y.one('#btnRun'),
22
 
            Assert = Y.Assert,
23
 
            ObjectAssert = Y.ObjectAssert;
24
 
 
25
 
        // Set up the page
26
 
        button.set("disabled", false);
27
 
        Y.on("click", function() {
28
 
            Y.Test.Runner.run();
29
 
        }, button);
30
 
 
31
 
        var myConsole = new Y.Console().render();
32
 
 
33
 
        var testSubstitute= new Y.Test.Case({
34
 
            name: "Substitute tests",
35
 
 
36
 
 
37
 
        test_substitute: function() {
38
 
 
39
 
            ////////////////////////////////////////////////////////////////////////////////
40
 
 
41
 
            var param = {domain: 'valvion.com',
42
 
                         media: 'http://media.{domain}/', /* nested */
43
 
                         contextdomain: { context1: 'context{domain}', context2: 'yahoo.com' },  /* the value is an object, we will use a custom function to extract the correct data */
44
 
                         contextmedia: 'http://contextmedia.{contextdomain context1}/'};
45
 
            var url;
46
 
 
47
 
            // standard replace, nested
48
 
            url = Y.substitute("{media}logo.gif", param, null, true);
49
 
            Assert.areEqual(url, "http://media.valvion.com/logo.gif");
50
 
 
51
 
 
52
 
            // If the replacement value is an object, use the meta info as a key to extract the
53
 
            // correct data.  Otherwise just return the value.
54
 
            function multipleChoice(key, val, meta) {
55
 
                return (Y.Lang.isObject(val)) ? val[meta] : val;
56
 
            }
57
 
 
58
 
            // "random data" is not used since the value for the contextmedia key is a string.
59
 
            // contextdomain uses "context1" as a key to expand the string correctly
60
 
            url = Y.substitute("{contextmedia random data}logo.gif", param, multipleChoice, true);
61
 
            Assert.areEqual(url, "http://contextmedia.contextvalvion.com/logo.gif");
62
 
 
63
 
            ////////////////////////////////////////////////////////////////////////////////
64
 
 
65
 
            var obj = {
66
 
                level1_1: 1.1,
67
 
                level1_2: 1.2,
68
 
                level1_3: {
69
 
                    level2_1: 2.1,
70
 
                    level2_2: 2.2,
71
 
                    level2_3: {
72
 
                        level3_1: 3.1,
73
 
                        level3_2: 3.2,
74
 
                        level3_3: 3.3,
75
 
                        level3_4: 3.4
76
 
                    },
77
 
                    level2_4: 2.4
78
 
                },
79
 
                level1_4: 1.4
80
 
            };
81
 
 
82
 
 
83
 
            Assert.areEqual(
84
 
                Y.substitute("{testobj 0}", { testobj: obj }, null, true),
85
 
                "{level1_1 => 1.1, level1_2 => 1.2, level1_3 => {...}, level1_4 => 1.4}",
86
 
                "failed one level object dump"
87
 
            );
88
 
 
89
 
            Assert.areEqual(
90
 
                Y.substitute("{testobj 1}", { testobj: obj }, null, true),
91
 
                "{level1_1 => 1.1, level1_2 => 1.2, level1_3 => {level2_1 => 2.1, level2_2 => 2.2, level2_3 => {...}, level2_4 => 2.4}, level1_4 => 1.4}",
92
 
                "failed two level object dump"
93
 
            );
94
 
 
95
 
            Assert.areEqual(
96
 
                Y.substitute(
97
 
                    "{testobj 10}", { testobj: obj }, null, true),
98
 
                "{level1_1 => 1.1, level1_2 => 1.2, level1_3 => {level2_1 => 2.1, level2_2 => 2.2, level2_3 => {level3_1 => 3.1, level3_2 => 3.2, level3_3 => 3.3, level3_4 => 3.4}, level2_4 => 2.4}, level1_4 => 1.4}",
99
 
                "failed deep object dump"
100
 
            );
101
 
 
102
 
            var arr = [
103
 
                1.1,
104
 
                1.2,
105
 
                [
106
 
                    2.1,
107
 
                    2.2,
108
 
                    [
109
 
                        3.1,
110
 
                        3.2,
111
 
                        3.3,
112
 
                        3.4
113
 
                    ],
114
 
                    2.4
115
 
                ],
116
 
                1.4
117
 
            ];
118
 
 
119
 
            Assert.areEqual(
120
 
                Y.substitute("{testarr 1}", { testarr: arr }, null, true),
121
 
                "[1.1, 1.2, [2.1, 2.2, {...}, 2.4], 1.4]",
122
 
                "failed two level array dump"
123
 
            );
124
 
 
125
 
            var mix = [
126
 
                1.1,
127
 
                new Date(),
128
 
                {
129
 
                    level2_1: 2.1,
130
 
                    level2_2: 2.2,
131
 
                    level2_3: [
132
 
                        3.1,
133
 
                        3.2,
134
 
                        3.3,
135
 
                        3.4
136
 
                    ],
137
 
                    level2_4: 2.4
138
 
                },
139
 
                1.4,
140
 
                function(){}
141
 
            ];
142
 
 
143
 
            var result = Y.substitute("{testmix 1}", { testmix: mix }, null, true);
144
 
 
145
 
            Assert.isTrue(
146
 
                (result.indexOf("GMT" > -1)) ? true : false,
147
 
                "failed two level mixed object with a date (date should have produced an output with GMT in it)"
148
 
            );
149
 
 
150
 
 
151
 
            ////////////////////////////////////////////////////////////////////////////////
152
 
 
153
 
            var tostr = {
154
 
                custom1_1: 1.1,
155
 
                custom1_2: 1.2,
156
 
                custom1_3: {
157
 
                    custom2_1: 2.1,
158
 
                    custom2_2: 2.2,
159
 
                    custom2_3: {
160
 
                        custom3_1: 3.1,
161
 
                        custom3_2: 3.2,
162
 
                        custom3_3: 3.3,
163
 
                        custom3_4: 3.4
164
 
                    },
165
 
                    custom2_4: 2.4
166
 
                },
167
 
                custom1_4: 1.4,
168
 
                toString: function() {
169
 
                    return "custom toString executed";
170
 
                }
171
 
            };
172
 
 
173
 
            Assert.areEqual(
174
 
                Y.substitute("{customtostr 1}", { customtostr:  tostr }, null, true),
175
 
                "custom toString executed",
176
 
                "failed: custom toString should have been used"
177
 
            );
178
 
 
179
 
            // Assert.areEqual(
180
 
            //     Y.substitute("{customtostr dump 1}", { customtostr:  tostr }, null, true),
181
 
            //     "{custom1_1 => 1.1, custom1_2 => 1.2, custom1_3 => {custom2_1 => 2.1, custom2_2 => 2.2, custom2_3 => {...}, custom2_4 => 2.4}, custom1_4 => 1.4, toString => f(){...}}",
182
 
            //     "failed: custom toString should NOT have been used because the dump keyword should override it"
183
 
            // );
184
 
 
185
 
            ////////////////////////////////////////////////////////////////////////////////
186
 
 
187
 
            var template = 'My {prefix} name is {name}. {signature}';
188
 
            var obj = {
189
 
                prefix:'last',
190
 
                name: 'Zappa',
191
 
                signature: '{I am a replacement string }{}'
192
 
            };
193
 
 
194
 
            // testing {} in the replacement text
195
 
            Assert.areEqual("My last name is Zappa. {I am a replacement string }{}", Y.substitute(template, obj));
196
 
 
197
 
                        Assert.areEqual(
198
 
                                '-{test}-',
199
 
                                Y.substitute('-{LBRACE}test{RBRACE}-', {test:'test'}, null, true),
200
 
                                'replacement of literals {LBRACE} and/or {RBRACE} failed'
201
 
                        );
202
 
                        
203
 
                        Assert.areEqual(
204
 
                                'done',
205
 
                                Y.substitute('{{{three}}}', {
206
 
                                        three:'two',
207
 
                                        two: 'one',
208
 
                                        one: 'done'
209
 
                                },null,true),
210
 
                                'recurse failed'
211
 
                        );
212
 
        }
213
 
 
214
 
        });
215
 
 
216
 
 
217
 
        Y.Test.Runner.setName("Substitute");
218
 
        Y.Test.Runner.add(testSubstitute);
219
 
        Y.Test.Runner.run();
220
 
    });
221
 
})();
222
 
</script>
223
 
</body>
224
 
</html>