Index: test/mjsunit/debug-liveedit-literals.js |
diff --git a/test/mjsunit/debug-liveedit-3.js b/test/mjsunit/debug-liveedit-literals.js |
similarity index 58% |
copy from test/mjsunit/debug-liveedit-3.js |
copy to test/mjsunit/debug-liveedit-literals.js |
index b2106579d839bcf9964759e78430dd94393d0723..fba3d35c3761a3aa3d7a6c6bd9d4f188bdf9281e 100644 |
--- a/test/mjsunit/debug-liveedit-3.js |
+++ b/test/mjsunit/debug-liveedit-literals.js |
@@ -28,43 +28,48 @@ |
// Flags: --expose-debug-as debug |
// Get the Debug object exposed from the debug context global object. |
-// In this test case we edit a script so that techincally function text |
-// hasen't been changed. However actually function became one level more nested |
-// and must be recompiled because it uses variable from outer scope. |
+Debug = debug.Debug |
+function Test(old_expression, new_expression) { |
+ eval("var t1 =1;\n" + |
+ "function ChooseAnimal() {\n" + |
+ " return " + old_expression + ";\n" + |
+ "}\n" + |
+ "var t2 =1;\n"); |
-Debug = debug.Debug |
+ assertEquals("Cat", ChooseAnimal()); |
-var function_z_text = |
-" function Z() {\n" |
-+ " return 2 + p;\n" |
-+ " }\n"; |
+ var script = Debug.findScript(ChooseAnimal); |
-eval( |
-"function Factory(p) {\n" |
-+ "return (\n" |
-+ function_z_text |
-+ ");\n" |
-+ "}\n" |
-); |
+ var patch_pos = script.source.indexOf(old_expression); |
+ var new_animal_patch = new_expression; |
-var z6 = Factory(6); |
-assertEquals(8, z6()); |
+ var change_log = new Array(); |
+ Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, old_expression.length, new_expression, change_log); |
Yang
2012/10/23 16:10:31
Please keep the 80-char limit.
Peter Rybin
2012/11/11 03:28:47
Done.
|
+ assertEquals("Capybara", ChooseAnimal()); |
+} |
-var script = Debug.findScript(Factory); |
+// Check that old literal boilerplate was reset. |
+Test("['Cat'][0]", "['Capybara'][0]"); |
+Test("['Cat'][0]", "{a:'Capybara'}.a"); |
-var new_source = script.source.replace(function_z_text, "function Intermediate() {\nreturn (\n" + function_z_text + ")\n;\n}\n"); |
-print("new source: " + new_source); |
+// No literals -> 1 literal. |
+Test("'Cat'", "['Capybara'][0]"); |
-var change_log = new Array(); |
-var result = Debug.LiveEdit.SetScriptSource(script, new_source, false, change_log); |
-print("Result: " + JSON.stringify(result) + "\n"); |
-print("Change log: " + JSON.stringify(change_log) + "\n"); |
+// No literals -> 2 literals. |
+Test("'Cat'", "['Capy'][0] + {a:'bara'}.a"); |
-assertEquals(8, z6()); |
+// 1 literal -> no literals. |
+Test("['Cat'][0]", "'Capybara'"); |
-var z100 = Factory(100)(); |
+// 2 literals -> no literals. |
+Test("['Ca'][0] + {a:'t'}.a", "'Capybara'"); |
-assertEquals(102, z100()); |
+// No literals -> regexp. |
+Test("'Cat'", "(/.A.Y.A.A/i).exec('Capybara')[0]"); |
+// Array literal -> regexp. |
+Test("['Cat'][0]", "(/.A.Y.A.A/i).exec('Capybara')[0]"); |
+// No literals -> regexp. |
+Test("(/.A./i).exec('Cat')[0]", "{c:'Capybara'}.c"); |
Yang
2012/10/23 16:10:31
the test for regexp -> no literals seems to be mis
Peter Rybin
2012/11/11 03:28:47
This description was totally misleading anyway. I
|