~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/3.4.1/tests/querystring/tests/querystring.html

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html>
3
 
<head>
4
 
    <title>Test Page</title>
5
 
    <link rel="stylesheet" href="../../../build/test/assets/test-console.css">
6
 
    <style>
7
 
    body {
8
 
        font-size:16px;
9
 
    }
10
 
    script.mine {
11
 
        clear:left;
12
 
        white-space:pre;
13
 
        display:block;
14
 
        font-family:monospace;
15
 
        background:#eef;
16
 
    }
17
 
    script::before, script::after {
18
 
        content:"<script>";
19
 
    }
20
 
    script::after {
21
 
        content:"</script>";
22
 
    }
23
 
    script[src]::before {
24
 
        content:"<script src=\"" attr(src) "\">";
25
 
        white-space:nowrap;
26
 
    }
27
 
    script[src] {
28
 
        background:#fff;
29
 
    }
30
 
    .yui3-console, .yui3-console-bd {
31
 
        height:auto!important;
32
 
        overflow:auto!important;
33
 
        overflow-y:auto!important;
34
 
    }
35
 
 
36
 
    </style>
37
 
</head>
38
 
<body class="yui3-skin-sam">
39
 
<h1>Query String Tests</h1>
40
 
<div id="testbed"></div>
41
 
 
42
 
<script src="../../../build/yui/yui.js"></script>
43
 
<script src="../../../build/console/console-debug.js"></script>
44
 
<script src="../../../build/querystring/querystring-debug.js"></script>
45
 
<script src="../../../build/collection/collection-debug.js"></script>
46
 
<script src="../../../build/test/test-debug.js"></script>
47
 
<script>
48
 
YUI({
49
 
    filter : 'debug',
50
 
    useBrowserConsole : false,
51
 
    logInclude : {
52
 
        TestRunner : true,
53
 
        querystring : true,
54
 
        QueryString: true
55
 
    }
56
 
}).use( 'test', 'console', 'querystring', function (Y) {
57
 
    var J = Y.JSON.stringify;
58
 
 
59
 
    if (!Array.prototype.forEach) Array.prototype.forEach = function (fn) {
60
 
        for (var i = 0, l = this.length; i < l; i ++) fn(this[i]);
61
 
    };
62
 
 
63
 
    // [ wonkyQS, canonicalQS, obj ]
64
 
    var qsTestCases = [ //{
65
 
        ["foo=bar",  "foo=bar", {"foo" : "bar"}],
66
 
        ["foo=bar&foo=quux", "foo%5B%5D=bar&foo%5B%5D=quux", {"foo" : ["bar", "quux"]}],
67
 
        ["foo=1&bar=2", "foo=1&bar=2", {"foo" : 1, "bar" : 2}],
68
 
        ["my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F", "my%20weird%20field=q1!2%22'w%245%267%2Fz8)%3F", {"my weird field" : "q1!2\"'w$5&7/z8)?" }],
69
 
        ["foo%3Dbaz=bar", "foo%3Dbaz=bar", {"foo=baz" : "bar"}],
70
 
        ["foo=baz=bar", "foo=baz%3Dbar", {"foo" : "baz=bar"}],
71
 
        ["str=foo&arr[]=1&arr[]=2&arr[]=3&obj[a]=bar&obj[b][]=4&obj[b][]=5&obj[b][]=6&obj[b][]=&obj[c][]=4&obj[c][]=5&obj[c][][somestr]=baz&obj[objobj][objobjstr]=blerg&somenull=&undef=", "str=foo&arr%5B%5D=1&arr%5B%5D=2&arr%5B%5D=3&obj%5Ba%5D=bar&obj%5Bb%5D%5B%5D=4&obj%5Bb%5D%5B%5D=5&obj%5Bb%5D%5B%5D=6&obj%5Bb%5D%5B%5D=&obj%5Bc%5D%5B%5D=4&obj%5Bc%5D%5B%5D=5&obj%5Bc%5D%5B%5D%5Bsomestr%5D=baz&obj%5Bobjobj%5D%5Bobjobjstr%5D=blerg&somenull=&undef=", {
72
 
            "str":"foo",
73
 
            "arr":[1,2,3],
74
 
            "obj":{
75
 
                "a":"bar",
76
 
                "b":[4,5,6,""],
77
 
                "c":[4,5,{"somestr":"baz"}],
78
 
                "objobj":{"objobjstr":"blerg"}
79
 
            },
80
 
            "somenull":"",
81
 
            "undef":""
82
 
        }],
83
 
        ["foo[bar][bla]=baz&foo[bar][bla]=blo", "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo", {"foo":{"bar":{"bla":["baz","blo"]}}}],
84
 
        ["foo[bar][][bla]=baz&foo[bar][][bla]=blo", "foo%5Bbar%5D%5B%5D%5Bbla%5D=baz&foo%5Bbar%5D%5B%5D%5Bbla%5D=blo", {"foo":{"bar":[{"bla":"baz"},{"bla":"blo"}]}}],
85
 
        ["foo[bar][bla][]=baz&foo[bar][bla][]=blo", "foo%5Bbar%5D%5Bbla%5D%5B%5D=baz&foo%5Bbar%5D%5Bbla%5D%5B%5D=blo", {"foo":{"bar":{"bla":["baz","blo"]}}}],
86
 
        [" foo = bar ", "foo=bar", {"foo":"bar"}]
87
 
    ]; //}
88
 
    // [ wonkyQS, canonicalQS, obj ]
89
 
    var qsColonTestCases = [ //{
90
 
        ["foo:bar", "foo:bar", {"foo":"bar"}],
91
 
        ["foo:bar;foo:quux", "foo%5B%5D:bar;foo%5B%5D:quux", {"foo" : ["bar", "quux"]}],
92
 
        ["foo:1&bar:2;baz:quux", "foo:1%26bar%3A2;baz:quux", {"foo":"1&bar:2", "baz":"quux"}],
93
 
        ["foo%3Abaz:bar", "foo%3Abaz:bar", {"foo:baz":"bar"}],
94
 
        ["foo:baz:bar", "foo:baz%3Abar", {"foo":"baz:bar"}]
95
 
    ]; //}
96
 
 
97
 
    // [ wonkyObj, qs, canonicalObj ]
98
 
    var extendedFunction = function () {};
99
 
    extendedFunction.prototype = {a:"b"};
100
 
    var qsWeirdObjects = [ //{
101
 
        [ {regexp:/./g}, "regexp=", {"regexp":""} ],
102
 
        [ {regexp: new RegExp(".", "g")}, "regexp=", {"regexp":""} ],
103
 
        [ {fn:function () {}}, "fn=", {"fn":""}],
104
 
        [ {fn:new Function("")}, "fn=", {"fn":""} ],
105
 
        [ {math:Math}, "math=", {"math":""} ],
106
 
        [ {e:extendedFunction}, "e=", {"e":""} ],
107
 
        [ {d:new Date()}, "d=", {"d":""} ],
108
 
        [ {d:Date}, "d=", {"d":""} ],
109
 
        [ {f:new Boolean(false), t:new Boolean(true)}, "f=0&t=1", {"f":0, "t":1} ],
110
 
        [ {f:false, t:true}, "f=0&t=1", {"f":0, "t":1} ]
111
 
    ]; //}
112
 
 
113
 
    // Tests Below...
114
 
    var suite = new Y.Test.Suite("Query String Tests");
115
 
    suite.add(new Y.Test.Case({
116
 
        name : "Parse Query Strings",
117
 
 
118
 
        testParseBasic : function() {
119
 
            qsTestCases.forEach(function (testCase) {
120
 
                Y.Assert.areSame(J(testCase[2]), J(Y.QueryString.parse(testCase[0])));
121
 
            });
122
 
        },
123
 
        testParseColon : function () {
124
 
            qsColonTestCases.forEach(function (testCase) {
125
 
                Y.Assert.areSame(J(testCase[2]), J(Y.QueryString.parse(testCase[0], ";", ":")));
126
 
            });
127
 
        },
128
 
        testParseWeird : function () {
129
 
            qsWeirdObjects.forEach(function (testCase) {
130
 
                Y.Assert.areSame(J(testCase[2]), J(Y.QueryString.parse(testCase[1])));
131
 
            });
132
 
        },
133
 
        testNested : function () {
134
 
            var f = Y.QueryString.parse("a=b&q=x%3Dy%26y%3Dz");
135
 
            f.q = Y.QueryString.parse(f.q);
136
 
            Y.Assert.areSame(J(f), J({ a : "b", q : { x : "y", y : "z" } }));
137
 
        },
138
 
        testNestedColon : function () {
139
 
            var f = Y.QueryString.parse("a:b;q:x%3Ay%3By%3Az", ";", ":");
140
 
            f.q = Y.QueryString.parse(f.q, ";", ":");
141
 
            Y.Assert.areSame(J(f), J({ a : "b", q : { x : "y", y : "z" } }));
142
 
        }
143
 
    }));
144
 
    suite.add(new Y.Test.Case({
145
 
        name : "Query Stringify Objects",
146
 
 
147
 
        _should:{error:{
148
 
            testStringifyCyclical : "QueryString.stringify. Cyclical reference"
149
 
        }},
150
 
 
151
 
        testStringifyBasic : function () {
152
 
            qsTestCases.forEach(function (testCase) {
153
 
                Y.Assert.areSame(testCase[1], Y.QueryString.stringify(testCase[2], { arrayKey: true }));
154
 
            });
155
 
        },
156
 
        testStringifyColon : function () {
157
 
            qsColonTestCases.forEach(function (testCase) {
158
 
                Y.Assert.areSame(testCase[1], Y.QueryString.stringify(testCase[2], { arrayKey: true, sep: ";", eq: ":" }));
159
 
            });
160
 
        },
161
 
        testStringifyWeird : function () {
162
 
            qsWeirdObjects.forEach(function (testCase) {
163
 
                Y.Assert.areSame(testCase[1], Y.QueryString.stringify(testCase[0]), { arrayKey: true });
164
 
            });
165
 
        },
166
 
        testStringifyCyclical : function () {
167
 
            var f = {};
168
 
            f.f = f;
169
 
            Y.QueryString.stringify(f);
170
 
        },
171
 
        testNested : function () {
172
 
            var f = Y.QueryString.stringify({
173
 
                a : "b",
174
 
                q : Y.QueryString.stringify({
175
 
                    x : "y",
176
 
                    y : "z"
177
 
                }, { arrayKey: true })
178
 
            });
179
 
            Y.Assert.areSame(f, "a=b&q=x%3Dy%26y%3Dz");
180
 
        },
181
 
        testNestedColon : function () {
182
 
            var f = Y.QueryString.stringify({
183
 
                a : "b",
184
 
                q : Y.QueryString.stringify({
185
 
                    x : "y",
186
 
                    y : "z"
187
 
                }, { arrayKey: true, sep: ";", eq: ":" })
188
 
            }, { arrayKey: true, sep: ";", eq: ":" });
189
 
            Y.Assert.areSame(f, "a:b;q:x%3Ay%3By%3Az");
190
 
        },
191
 
        testArrayKey : function () {
192
 
            var f = Y.QueryString.stringify({ foo: ["bar","baz"] });
193
 
            Y.Assert.areSame(f, "foo=bar&foo=baz");
194
 
        }
195
 
    }));
196
 
 
197
 
 
198
 
    var yconsole = new Y.Console({
199
 
        contentBox : "#testbed",
200
 
        newestOnTop : false,
201
 
        style : 'inline',
202
 
        height : 'auto',
203
 
        width : 'auto'
204
 
    }).render();
205
 
 
206
 
    Y.Test.Runner.add(suite);
207
 
 
208
 
    Y.Test.Runner.run();
209
 
 
210
 
});
211
 
</script>
212
 
</body>
213
 
</html>