Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: test/mjsunit/substr.js

Issue 655002: Merge revisions 3777-3813 from bleding_edge to partial snapshots ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/object-define-property.js ('k') | test/mjsunit/tools/logreader.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:executable
+ *
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 assertEquals(s, s.substr({ toString: function() { return '0'; } })); 37 assertEquals(s, s.substr({ toString: function() { return '0'; } }));
38 38
39 var s1 = s.substring(1); 39 var s1 = s.substring(1);
40 assertEquals(s1, s.substr(1)); 40 assertEquals(s1, s.substr(1));
41 assertEquals(s1, s.substr('1')); 41 assertEquals(s1, s.substr('1'));
42 assertEquals(s1, s.substr(true)); 42 assertEquals(s1, s.substr(true));
43 assertEquals(s1, s.substr(1.1)); 43 assertEquals(s1, s.substr(1.1));
44 assertEquals(s1, s.substr({ valueOf: function() { return 1; } })); 44 assertEquals(s1, s.substr({ valueOf: function() { return 1; } }));
45 assertEquals(s1, s.substr({ toString: function() { return '1'; } })); 45 assertEquals(s1, s.substr({ toString: function() { return '1'; } }));
46 46
47 for (var i = 0; i < s.length; i++)
48 for (var j = i; j < s.length + 5; j++)
49 assertEquals(s.substring(i, j), s.substr(i, j - i));
50 47
51 assertEquals(s.substring(s.length - 1), s.substr(-1)); 48 assertEquals(s.substring(s.length - 1), s.substr(-1));
52 assertEquals(s.substring(s.length - 1), s.substr(-1.2)); 49 assertEquals(s.substring(s.length - 1), s.substr(-1.2));
53 assertEquals(s.substring(s.length - 1), s.substr(-1.7)); 50 assertEquals(s.substring(s.length - 1), s.substr(-1.7));
54 assertEquals(s.substring(s.length - 2), s.substr(-2)); 51 assertEquals(s.substring(s.length - 2), s.substr(-2));
55 assertEquals(s.substring(s.length - 2), s.substr(-2.3)); 52 assertEquals(s.substring(s.length - 2), s.substr(-2.3));
56 assertEquals(s.substring(s.length - 2, s.length - 1), s.substr(-2, 1)); 53 assertEquals(s.substring(s.length - 2, s.length - 1), s.substr(-2, 1));
57 assertEquals(s, s.substr(-100)); 54 assertEquals(s, s.substr(-100));
58 assertEquals('abc', s.substr(-100, 3)); 55 assertEquals('abc', s.substr(-100, 3));
59 assertEquals(s1, s.substr(-s.length + 1)); 56 assertEquals(s1, s.substr(-s.length + 1));
60 57
61 // assertEquals('', s.substr(0, void 0)); // smjs and rhino 58 // assertEquals('', s.substr(0, void 0)); // smjs and rhino
62 assertEquals('abcdefghijklmn', s.substr(0, void 0)); // kjs and v8 59 assertEquals('abcdefghijklmn', s.substr(0, void 0)); // kjs and v8
63 assertEquals('', s.substr(0, null)); 60 assertEquals('', s.substr(0, null));
64 assertEquals(s, s.substr(0, String(s.length))); 61 assertEquals(s, s.substr(0, String(s.length)));
65 assertEquals('a', s.substr(0, true)); 62 assertEquals('a', s.substr(0, true));
63
64
65 // Test substrings of different lengths and alignments.
66 // First ASCII.
67 var x = "ASCII";
68 for (var i = 0; i < 25; i++) {
69 x += (i >> 4).toString(16) + (i & 0x0f).toString(16);
70 }
71 /x/.exec(x); // Try to force a flatten.
72 for (var i = 5; i < 25; i++) {
73 for (var j = 0; j < 25; j++) {
74 var z = x.substring(i, i+j);
75 var w = Math.random() * 42; // Allocate something new in new-space.
76 assertEquals(j, z.length);
77 for (var k = 0; k < j; k++) {
78 assertEquals(x.charAt(i+k), z.charAt(k));
79 }
80 }
81 }
82
83
84 // Then two-byte strings.
85 x = "UC16\u2028"; // Non-ascii char forces two-byte string.
86 for (var i = 0; i < 25; i++) {
87 x += (i >> 4).toString(16) + (i & 0x0f).toString(16);
88 }
89 /x/.exec(x); // Try to force a flatten.
90 for (var i = 5; i < 25; i++) {
91 for (var j = 0; j < 25; j++) {
92 var z = x.substring(i, i + j);
93 var w = Math.random() * 42; // Allocate something new in new-space.
94 assertEquals(j, z.length);
95 for (var k = 0; k < j; k++) {
96 assertEquals(x.charAt(i+k), z.charAt(k));
97 }
98 }
99 }
100
101
102 // Keep creating strings to to force allocation failure on substring creation.
103 var x = "0123456789ABCDEF";
104 x += x; // 2^5
105 x += x;
106 x += x;
107 x += x;
108 x += x;
109 x += x; // 2^10
110 x += x;
111 x += x;
112 var xl = x.length;
113 var cache = [];
114 for (var i = 0; i < 10000; i++) {
115 var z = x.substring(i % xl);
116 assertEquals(xl - (i % xl), z.length);
117 cache.push(z);
118 }
119
120
121 // Same with two-byte strings
122 var x = "\u2028123456789ABCDEF";
123 x += x; // 2^5
124 x += x;
125 x += x;
126 x += x;
127 x += x;
128 x += x; // 2^10
129 x += x;
130 x += x;
131 var xl = x.length;
132 var cache = [];
133 for (var i = 0; i < 10000; i++) {
134 var z = x.substring(i % xl);
135 assertEquals(xl - (i % xl), z.length);
136 cache.push(z);
137 }
OLDNEW
« no previous file with comments | « test/mjsunit/object-define-property.js ('k') | test/mjsunit/tools/logreader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698