public void testStableRenameLocalsClashingWithGlobals() { test("function a(v1, v2) {return v1;} a();", "function a(b, c) {return b;} a();"); previouslyUsedMap = renameVars.getVariableMap(); test( "function bar(){return;}function a(v1, v2) {return v1;} a();", "function d(){return;}function a(b, c) {return b;} a();"); }
public void testStableRenameWithPrefix2() { prefix = "a"; test( "function Foo() {return 1;}" + "function Bar() {" + " var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," + " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ab;" + " Foo();" + "} Bar();", "function a() {return 1;}" + "function aa() {" + " var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A," + " B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,ba,ca;" + " a();" + "} aa();"); previouslyUsedMap = renameVars.getVariableMap(); prefix = "a"; test( "function Foo() {return 1;}" + "function Baz() {return 1;}" + "function Bar() {" + " var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," + " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ab;" + " Foo();" + "} Bar();", "function a() {return 1;}" + "function ab() {return 1;}" + "function aa() {" + " var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A," + " B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,ba,ca;" + " a();" + "} aa();"); }
public void testStableRenameWithPrefix1AndUnstableLocalNames() { prefix = "PRE_"; test("function Foo(v1, v2) {return v1} Foo();", "function PRE_(a, b) {return a} PRE_();"); previouslyUsedMap = renameVars.getVariableMap(); prefix = "PRE_"; test( "function Foo(v0, v1, v2) {return v1} Foo();", "function PRE_(a, b, c) {return b} PRE_();"); }
public void testContrivedExampleWhereConsistentRenamingIsWorse() { previouslyUsedMap = makeVariableMap("Foo", "LongString", "L 0", "b", "L 1", "c"); test( "function Foo(v1, v2) {return v1;} Foo();", "function LongString(b, c) {return b;} LongString();"); previouslyUsedMap = renameVars.getVariableMap(); VariableMap expectedVariableMap = makeVariableMap("Foo", "LongString", "L 0", "b", "L 1", "c"); assertVariableMapsEqual(expectedVariableMap, previouslyUsedMap); }
public void testStableRenameSimpleGlobalNameExterned() { test("function Foo(v1, v2) {return v1;} Foo();", "function a(b, c) {return b;} a();"); previouslyUsedMap = renameVars.getVariableMap(); String externs = "var Foo;"; test( externs, "function Foo(v1, v2, v0) {return v1;} Foo();", "function Foo(b, c, a) {return b;} Foo();", null, null); }
public void testPreferStableNames() { preferStableNames = true; // Locals in scopes with too many local variables (>1000) should // not receive temporary names (eg, 'L 123'). These locals will // appear in the name maps with the same name as in the code (eg, // 'a0' in this case). test(createManyVarFunction(1000), null); assertEquals(null, renameVars.getVariableMap().lookupNewName("a0")); assertEquals("b", renameVars.getVariableMap().lookupNewName("L 0")); test(createManyVarFunction(1001), null); assertEquals("b", renameVars.getVariableMap().lookupNewName("a0")); assertEquals(null, renameVars.getVariableMap().lookupNewName("L 0")); // With {@code preferStableNames} off locals should // unconditionally receive temporary names. preferStableNames = false; test(createManyVarFunction(1000), null); assertEquals(null, renameVars.getVariableMap().lookupNewName("a0")); assertEquals("b", renameVars.getVariableMap().lookupNewName("L 0")); test(createManyVarFunction(1001), null); assertEquals(null, renameVars.getVariableMap().lookupNewName("a0")); assertEquals("b", renameVars.getVariableMap().lookupNewName("L 0")); }
private void testRenameMap( String externs, String input, String expected, VariableMap expectedRenameMap) { test(externs, input, expected, null, null); VariableMap renameMap = renameVars.getVariableMap(); assertVariableMapsEqual(expectedRenameMap, renameMap); }
private void testRenameMapUsingOldMap( String externs, String input, String expected, VariableMap expectedMap) { previouslyUsedMap = renameVars.getVariableMap(); testRenameMap(externs, input, expected, expectedMap); }
public void testStableRenameWithNameOverlap() { test("var a = 1; var b = 2; b + b;", "var a = 1; var b = 2; b + b;"); previouslyUsedMap = renameVars.getVariableMap(); test("var a = 1; var c, b = 2; b + b;", "var a = 1; var c, b = 2; b + b;"); }
public void testStableRenameWithExterns2() { String externs = "var a;"; test(externs, "var b = 5", "var b = 5", null, null); previouslyUsedMap = renameVars.getVariableMap(); test(externs, "var b = 5, catty = 9;", "var b = 5, c=9;", null, null); }
public void testStableRenameWithExterns1() { String externs = "var foo;"; test(externs, "var bar; foo(bar);", "var a; foo(a);", null, null); previouslyUsedMap = renameVars.getVariableMap(); test(externs, "var bar, baz; foo(bar, baz);", "var a, b; foo(a, b);", null, null); }