Skip to content

String tests should be useful in optimized output - #9986

Merged
niloc132 merged 1 commit into
gwtproject:mainfrom
niloc132:fix-string-test
Jul 22, 2024
Merged

niloc132 merged 1 commit into
gwtproject:mainfrom
niloc132:fix-string-test

Conversation

@niloc132

Copy link
Copy Markdown
Member

Resolves TODOs in the old tests, so that the DeadCodeElimination pass doesn't rewrite the test to do nothing, but actually confirm that the String class does what is expected.

Related #9975

Resolves TODOs in the old tests, so that the DeadCodeElimination pass
doesn't rewrite the test to do nothing, but actually confirm that the
String class does what is expected.

Related gwtproject#9975
@niloc132

Copy link
Copy Markdown
Member Author

Old optimized output (with style PRETTY and emulated stack traces turned off):

_.testTrim = function testTrim(){
  assertEquals_13('abc', 'abc');
  assertEquals_13('abc', 'abc');
  assertSame('abc', 'abc');
  assertSame('#hi', '#hi');
  assertEquals_13('abc', 'abc');
  assertEquals_13('abc', 'abc');
  assertEquals_13('', '');
  assertEquals_13('', '');
  // rest of lines missing
}
;
_.testValueOf = function testValueOf_1(){
  assertTrue_0($startsWith('' + ($clinit_C() , FLOAT_VALUE), FLOAT_STRING));
  assertEquals_13('123456789', '123456789');
  assertEquals_13('1234567890123456', '1234567890123456');
  assertTrue_0($startsWith('' + DOUBLE_VALUE, DOUBLE_STRING));
  assertEquals_13(CHAR_STRING, String.fromCharCode(CHAR_VALUE));
  assertEquals_13(CHAR_ARRAY_STRING, valueOf_4(CHAR_ARRAY_VALUE));
  assertEquals_13(CHAR_ARRAY_STRING_SUB, valueOf_5(CHAR_ARRAY_VALUE, 1, 4));
  assertEquals_13(FALSE_STRING, 'false');
  assertEquals_13(TRUE_STRING, '' + TRUE_VALUE);
  // last line missing
}
;

After this patch:

_.testTrim = function testTrim_0(){
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , '   \t abc \n  ')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , 'abc')));
  assertSame('abc', $trim(($wnd.Math.random() < -1 && fail() , 'abc')));
  assertSame('#hi', $trim(($wnd.Math.random() < -1 && fail() , '#hi')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , ' abc')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , 'abc ')));
  assertEquals_13('', $trim(($wnd.Math.random() < -1 && fail() , '')));
  assertEquals_13('', $trim(($wnd.Math.random() < -1 && fail() , '   \t ')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , '\x00\x00\x00 abc')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , 'abc\x00\x00\x00')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , 'abc   \x00\x00\x00')));
  assertEquals_13('abc', $trim(($wnd.Math.random() < -1 && fail() , '   \x00 \x00 \x00abc')));
  assertEquals_13('abc \x00 a', $trim(($wnd.Math.random() < -1 && fail() , '    abc \x00 a')));
  assertEquals_13('abc \x00 a', $trim(($wnd.Math.random() < -1 && fail() , '    abc \x00 a   \x00')));
  assertEquals_13('abc \x00 a', $trim(($wnd.Math.random() < -1 && fail() , '    abc \x00 a   \x00   ')));
  assertEquals_13('! abc', $trim(($wnd.Math.random() < -1 && fail() , '\x19\x17! abc\x19\x17\x18 ')));
  assertEquals_13('! abc', $trim(($wnd.Math.random() < -1 && fail() , '\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F ! abc')));
  assertEquals_13('\u2029abc\xA0', $trim(($wnd.Math.random() < -1 && fail() , '\u2029abc\xA0')));
  assertEquals_13('\uFFEFx\u180E', $trim(($wnd.Math.random() < -1 && fail() , '\uFFEFx\u180E ')));
}
;
_.testValueOf = function testValueOf_3(){
  assertTrue_0($startsWith(valueOf_4($hideFromCompiler(new Float(($clinit_C() , FLOAT_VALUE)))), FLOAT_STRING));
  assertEquals_13('123456789', valueOf_4($hideFromCompiler(valueOf_1($intern_73))));
  assertEquals_13('1234567890123456', valueOf_4($hideFromCompiler(valueOf_2({l:703168, m:742642, h:70}))));
  assertTrue_0($startsWith('' + DOUBLE_VALUE, castToString($hideFromCompiler(DOUBLE_STRING))));
  assertEquals_13(CHAR_STRING, valueOf_4($hideFromCompiler(valueOf_0(CHAR_VALUE))));
  assertEquals_13(CHAR_ARRAY_STRING, valueOf_5(castTo($hideFromCompiler(CHAR_ARRAY_VALUE), 6)));
  assertEquals_13(CHAR_ARRAY_STRING_SUB, valueOf_6(castTo($hideFromCompiler(CHAR_ARRAY_VALUE), 6), 1, 4));
  assertEquals_13(FALSE_STRING, valueOf_4($hideFromCompiler(($clinit_Boolean() , false))));
  assertEquals_13(TRUE_STRING, valueOf_4($hideFromCompiler(TRUE_VALUE?true:false)));
  assertEquals_13(getLargeCharArrayString(), valueOf_5(getLargeCharArrayValue()));
}
;

@niloc132
niloc132 merged commit 5e87768 into gwtproject:main Jul 22, 2024
@niloc132 niloc132 added this to the 2.12 milestone Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants