Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / v8 / test / mjsunit / uri.js
1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Tests of URI encoding and decoding.
29
30 assertEquals("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.!~*'();/?:@&=+$,#",
31              encodeURI("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.!~*'();/?:@&=+$,#"));
32
33 var cc1 = 0x007D;
34 var s1 = String.fromCharCode(cc1);
35 var cc2 = 0x0000;
36 var s2 = String.fromCharCode(cc2);
37 var cc3 = 0x0080;
38 var s3 = String.fromCharCode(cc3);
39 var cc4 = 0x0555;
40 var s4 = String.fromCharCode(cc4);
41 var cc5 = 0x07FF;
42 var s5 = String.fromCharCode(cc5);
43 var cc6 = 0x0800;
44 var s6 = String.fromCharCode(cc6);
45 var cc7 = 0xAEEE;
46 var s7 = String.fromCharCode(cc7);
47 var cc8_1 = 0xD800;
48 var cc8_2 = 0xDC00;
49 var s8 = String.fromCharCode(cc8_1)+String.fromCharCode(cc8_2);
50 var cc9_1 = 0xDBFF;
51 var cc9_2 = 0xDFFF;
52 var s9 = String.fromCharCode(cc9_1)+String.fromCharCode(cc9_2);
53 var cc10 = 0xE000;
54 var s10 = String.fromCharCode(cc10);
55
56 assertEquals('%7D', encodeURI(s1));
57 assertEquals('%00', encodeURI(s2));
58 assertEquals('%C2%80', encodeURI(s3));
59 assertEquals('%D5%95', encodeURI(s4));
60 assertEquals('%DF%BF', encodeURI(s5));
61 assertEquals('%E0%A0%80', encodeURI(s6));
62 assertEquals('%EA%BB%AE', encodeURI(s7));
63 assertEquals('%F0%90%80%80', encodeURI(s8));
64 assertEquals('%F4%8F%BF%BF', encodeURI(s9));
65 assertEquals('%EE%80%80', encodeURI(s10));
66
67 assertEquals(cc1, decodeURI(encodeURI(s1)).charCodeAt(0));
68 assertEquals(cc2, decodeURI(encodeURI(s2)).charCodeAt(0));
69 assertEquals(cc3, decodeURI(encodeURI(s3)).charCodeAt(0));
70 assertEquals(cc4, decodeURI(encodeURI(s4)).charCodeAt(0));
71 assertEquals(cc5, decodeURI(encodeURI(s5)).charCodeAt(0));
72 assertEquals(cc6, decodeURI(encodeURI(s6)).charCodeAt(0));
73 assertEquals(cc7, decodeURI(encodeURI(s7)).charCodeAt(0));
74 assertEquals(cc8_1, decodeURI(encodeURI(s8)).charCodeAt(0));
75 assertEquals(cc8_2, decodeURI(encodeURI(s8)).charCodeAt(1));
76 assertEquals(cc9_1, decodeURI(encodeURI(s9)).charCodeAt(0));
77 assertEquals(cc9_2, decodeURI(encodeURI(s9)).charCodeAt(1));
78 assertEquals(cc10, decodeURI(encodeURI(s10)).charCodeAt(0));
79
80 assertEquals("", decodeURI(""));
81 assertEquals("", encodeURI(""));
82
83 function test(string) {
84   assertEquals(string, decodeURI(encodeURI(string)));
85 }
86
87 test("\u1234\u0123\uabcd");
88 test("abcd");
89 test("ab<\u1234\u0123");
90 test("ab\u1234<\u0123");