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

Side by Side Diff: test/mjsunit/string-external-cached.js

Issue 559913002: Rename ascii to one-byte where applicable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 // Test regexp and short substring. 62 // Test regexp and short substring.
63 var re = /(A|B)/; 63 var re = /(A|B)/;
64 var rere = /(T.{1,2}B)/; 64 var rere = /(T.{1,2}B)/;
65 var ascii = "ABCDEFGHIJKLMNOPQRST"; 65 var ascii = "ABCDEFGHIJKLMNOPQRST";
66 var twobyte = "_ABCDEFGHIJKLMNOPQRST"; 66 var twobyte = "_ABCDEFGHIJKLMNOPQRST";
67 try { 67 try {
68 externalizeString(ascii, false); 68 externalizeString(ascii, false);
69 externalizeString(twobyte, true); 69 externalizeString(twobyte, true);
70 } catch (ex) { } 70 } catch (ex) { }
71 assertTrue(isAsciiString(ascii)); 71 assertTrue(isOneByteString(ascii));
72 assertFalse(isAsciiString(twobyte)); 72 assertFalse(isOneByteString(twobyte));
73 var ascii_slice = ascii.slice(1,-1); 73 var ascii_slice = ascii.slice(1,-1);
74 var twobyte_slice = twobyte.slice(2,-1); 74 var twobyte_slice = twobyte.slice(2,-1);
75 var ascii_cons = ascii + ascii; 75 var ascii_cons = ascii + ascii;
76 var twobyte_cons = twobyte + twobyte; 76 var twobyte_cons = twobyte + twobyte;
77 for (var i = 0; i < 2; i++) { 77 for (var i = 0; i < 2; i++) {
78 assertEquals(["A", "A"], re.exec(ascii)); 78 assertEquals(["A", "A"], re.exec(ascii));
79 assertEquals(["B", "B"], re.exec(ascii_slice)); 79 assertEquals(["B", "B"], re.exec(ascii_slice));
80 assertEquals(["TAB", "TAB"], rere.exec(ascii_cons)); 80 assertEquals(["TAB", "TAB"], rere.exec(ascii_cons));
81 assertEquals(["A", "A"], re.exec(twobyte)); 81 assertEquals(["A", "A"], re.exec(twobyte));
82 assertEquals(["B", "B"], re.exec(twobyte_slice)); 82 assertEquals(["B", "B"], re.exec(twobyte_slice));
83 assertEquals(["T_AB", "T_AB"], rere.exec(twobyte_cons)); 83 assertEquals(["T_AB", "T_AB"], rere.exec(twobyte_cons));
84 assertEquals("DEFG", ascii_slice.substr(2, 4)); 84 assertEquals("DEFG", ascii_slice.substr(2, 4));
85 assertEquals("DEFG", twobyte_slice.substr(2, 4)); 85 assertEquals("DEFG", twobyte_slice.substr(2, 4));
86 assertEquals("DEFG", ascii_cons.substr(3, 4)); 86 assertEquals("DEFG", ascii_cons.substr(3, 4));
87 assertEquals("DEFG", twobyte_cons.substr(4, 4)); 87 assertEquals("DEFG", twobyte_cons.substr(4, 4));
88 } 88 }
89 89
90 // Test adding external strings 90 // Test adding external strings
91 var short_ascii = "E="; 91 var short_ascii = "E=";
92 var long_ascii = "MCsquared"; 92 var long_ascii = "MCsquared";
93 var short_twobyte = "E\u1234"; 93 var short_twobyte = "E\u1234";
94 var long_twobyte = "MCsquare\u1234"; 94 var long_twobyte = "MCsquare\u1234";
95 try { // String can only be externalized once 95 try { // String can only be externalized once
96 externalizeString(short_ascii, false); 96 externalizeString(short_ascii, false);
97 externalizeString(long_ascii, false); 97 externalizeString(long_ascii, false);
98 externalizeString(short_twobyte, true); 98 externalizeString(short_twobyte, true);
99 externalizeString(long_twobyte, true); 99 externalizeString(long_twobyte, true);
100 assertTrue(isAsciiString(short_asii) && isAsciiString(long_ascii)); 100 assertTrue(isOneByteString(short_asii) && isOneByteString(long_ascii));
101 assertFalse(isAsciiString(short_twobyte) || isAsciiString(long_twobyte)); 101 assertFalse(isOneByteString(short_twobyte) || isOneByteString(long_twobyte)) ;
102 } catch (ex) { } 102 } catch (ex) { }
103 assertEquals("E=MCsquared", short_ascii + long_ascii); 103 assertEquals("E=MCsquared", short_ascii + long_ascii);
104 assertTrue(isAsciiString(short_ascii + long_ascii)); 104 assertTrue(isOneByteString(short_ascii + long_ascii));
105 assertEquals("MCsquaredE=", long_ascii + short_ascii); 105 assertEquals("MCsquaredE=", long_ascii + short_ascii);
106 assertEquals("E\u1234MCsquare\u1234", short_twobyte + long_twobyte); 106 assertEquals("E\u1234MCsquare\u1234", short_twobyte + long_twobyte);
107 assertFalse(isAsciiString(short_twobyte + long_twobyte)); 107 assertFalse(isOneByteString(short_twobyte + long_twobyte));
108 assertEquals("E=MCsquared", "E=" + long_ascii); 108 assertEquals("E=MCsquared", "E=" + long_ascii);
109 assertEquals("E\u1234MCsquared", short_twobyte + "MCsquared"); 109 assertEquals("E\u1234MCsquared", short_twobyte + "MCsquared");
110 assertEquals("E\u1234MCsquared", short_twobyte + long_ascii); 110 assertEquals("E\u1234MCsquared", short_twobyte + long_ascii);
111 assertFalse(isAsciiString(short_twobyte + long_ascii)); 111 assertFalse(isOneByteString(short_twobyte + long_ascii));
112 } 112 }
113 113
114 // Run the test many times to ensure IC-s don't break things. 114 // Run the test many times to ensure IC-s don't break things.
115 for (var i = 0; i < 10; i++) { 115 for (var i = 0; i < 10; i++) {
116 test(); 116 test();
117 } 117 }
118 118
119 // Clean up string to make Valgrind happy. 119 // Clean up string to make Valgrind happy.
120 gc(); 120 gc();
121 gc(); 121 gc();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698