public void TestAddingParameter9() { string cppCode = @" class Human { public string SomeHumanMethod() { } private int SomeMethod() { } } " ; string newCppCode = @" class Human { public string SomeHumanMethod(string parameter) { } private int SomeMethod() { } } " ; string result = Refactor.AddParameter(cppCode, "SomeHumanMethod", "string parameter"); Assert.AreEqual(newCppCode, result); }
public void Overlapping() { string cs = @" using System.Collections; using System.Text; using System.Threading; "; CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); refactor.Queue(new AddUsing(globals, "System.Com")); refactor.Queue(new Indent(1, 30, "\t")); try // TODO: can do this better with nunit 2.4 { refactor.Process(); Assert.Fail("expected an exception"); } catch (InvalidOperationException e) { if (!e.Message.Contains("AddUsing and Indent edits overlap")) Assert.Fail(e.ToString()); } }
public void TestAddingParameter1() { string result = Refactor.AddParameter( "void Method(){}" , "Method", "string a"); Assert.AreEqual("void Method(string a){}", result); }
public void TestAddingParameter4() { string cppCode = @" // void method() {} " ; string result = Refactor.AddParameter(cppCode, "method", "double num"); Assert.AreEqual(cppCode, result); }
public void Test_Refactor_Get_PreviousResult_Index() { string res; Refactor ref_calculator = new Refactor(); res = ref_calculator.getPreviousResult(0); Assert.AreEqual("Error: Index must between 1 and 10", res); res = ref_calculator.getPreviousResult(11); Assert.AreEqual("Error: Index must between 1 and 10", res); }
public void TestAddingParameter3() { string result = Refactor.AddParameter( "void Method(int a){}" , "Method", "string b"); Assert.AreEqual( "void Method(int a,string b){}" , result); }
public void TestAddingParameter5() { string cppCode = @" // void method() {} void method() {} " ; string newCppCode = @" // void method() {} void method(string a) {} " ; string result = Refactor.AddParameter(cppCode, "method", "string a"); Assert.AreEqual(newCppCode, result); }
public void TestAddingParameter7() { string cppCode = @" if(a == b){ someMethod(); } " ; string newCppCode = @" if(a == b){ someMethod(); } " ; string result = Refactor.AddParameter(cppCode, "someMethod", "string a"); Assert.AreEqual(newCppCode, result); }
public void TestAddingParameter6() { string cppCode = @" string method1() {} void method() { string name = method1(); } " ; string newCppCode = @" string method1(int num=0) {} void method() { string name = method1(); } " ; string result = Refactor.AddParameter(cppCode, "method1", "int num=0"); Assert.AreEqual(newCppCode, result); }
private void button1_Click(object sender, EventArgs e) { RefactorMethod refact = new RefactorMethod(); switch (comboBox1.SelectedIndex) { case 0: richTextBox1.Text = refact.DelParam(richTextBox1.Text, textBox1.Text, textBox2.Text); break; case 1: richTextBox1.Text = refact.Rename(richTextBox1.Text, textBox1.Text, textBox2.Text); break; case 2: richTextBox1.Text = Refactor.AddParameter(richTextBox1.Text, textBox1.Text, textBox2.Text); break; case 3: richTextBox1.Text = Refactor.RenameVariable(richTextBox1.Text, textBox1.Text, textBox2.Text); break; } }
public string Execute(string rSource, IText cSource, int selStart, int selLen) { string result = rSource; // Parse the C# code.. var editor = cSource.Boss.Get<ITextEditor>(); Boss boss = ObjectModel.Create("CsParser"); var parses = boss.Get<IParses>(); Parse parse = parses.Parse(editor.Key, cSource.EditCount, cSource.Text); if (parse.ErrorLength == 0 && parse.Globals != null) { CsGlobalNamespace globals = parse.Globals; // Parse the refactor script. var rParser = new CsRefactor.Script.Parser(rSource); CsRefactor.Script.Script script = rParser.Parse(); // Evaluate the script. var context = new CsRefactor.Script.Context(script, globals, cSource.Text, selStart, selLen); RefactorCommand[] commands = script.Evaluate(context); // Execute the script. Refactor refactor = new Refactor(cSource.Text); foreach (RefactorCommand command in commands) { refactor.Queue(command); } result = refactor.Process(); // Expand bullet characters. DoGetSettings(cSource.Boss); result = DoExpandText(result); } return result; }
public void TestAddingParameter8() { string cppCode = @" /* int ReturnInt() {} */ double ReturnDouble() {} " ; string newCppCode = @" /* int ReturnInt() {} */ double ReturnDouble() {} " ; string result = Refactor.AddParameter(cppCode, "ReturnInt", "int a"); Assert.AreEqual(newCppCode, result); }
public void Wrap1() { string text = @" internal sealed class Foo { static void Process(int x) { xxx; yyy; } } "; Refactor refactor = new Refactor(text); refactor.Queue(new InsertBeforeLine(text.IndexOf("xxx"), new string[]{"try", "{"})); refactor.Queue(new Indent(text.IndexOf("xxx"), 9, "\t")); refactor.Queue(new InsertAfterLine(text.IndexOf("yyy"), 0, new string[]{"}", "catch", "{", "}"})); string result= refactor.Process(); Assert.AreEqual(@" internal sealed class Foo { static void Process(int x) { try { xxx; yyy; } catch { } } } ", result); }
public void TestRenameVariable2() { string res = Refactor.RenameVariable("int a=1; int b=a*a;", "a", "Number"); Assert.AreEqual("int Number=1; int b=Number*Number;", res); }
private string DoEdit(string cs, string lines) { CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); refactor.Queue(new InsertFirst(globals.Types[0].Methods[0].Body, lines.Split('\n'))); return refactor.Process(); }
private string DoEdit(string cs, params string[] lines) { CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); refactor.Queue(new AddMember(globals.Types[0], lines)); return refactor.Process(); }
public void TestRenameVariable3() { string res = Refactor.RenameVariable("int i=1;", "i", "Number"); Assert.AreEqual("int Number=1;", res); }
public void TestRenameVariable9() { string res = Refactor.RenameVariable("bool b = True; //b=123", "b", "Var"); Assert.AreEqual("bool Var = True; //b=123", res); }
private string DoEdit(string cs, int index, string lines) { Refactor refactor = new Refactor(cs); refactor.Queue(new InsertAfterLine(index, 0, lines.Split('\n'))); return refactor.Process(); }
private string DoEdit(string cs, string access) { Log.WriteLine("Refactor Commands", "{0} {1} {2}", new string('*', 10), new StackTrace().GetFrame(1).GetMethod().Name, new string('*', 10)); CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); refactor.Queue(new ChangeAccess(globals.Types[0].Methods[0], access)); return refactor.Process(); }
public void TestAddingParameter10() { string cppCode = @" #include <iostream> #include <string> using namespace std; void check_pass () { string valid_pass = ""qwerty123""; if (password == valid_pass) { cout << ""Доступ разрешен."" << endl; } else { cout << ""Неверный пароль!"" << endl; } } int main() { string user_pass; cout << ""Введите пароль: ""; getline(cin, user_pass); check_pass(user_pass); return 0; } " ; string newCppCode = @" #include <iostream> #include <string> using namespace std; void check_pass (string password) { string valid_pass = ""qwerty123""; if (password == valid_pass) { cout << ""Доступ разрешен."" << endl; } else { cout << ""Неверный пароль!"" << endl; } } int main() { string user_pass; cout << ""Введите пароль: ""; getline(cin, user_pass); check_pass(user_pass); return 0; } " ; string result = Refactor.AddParameter(cppCode, "check_pass", "string password"); Assert.AreEqual(newCppCode, result); }
public void TestRenameVariable6() { string res = Refactor.RenameVariable("int a1 = 1; bool a = False;", "a", "Number"); Assert.AreEqual("int a1 = 1; bool Number = False;", res); }
public void TestRenameVariable5() { string res = Refactor.RenameVariable("int a=1; int mod = abs(a);", "a", "Number"); Assert.AreEqual("int Number=1; int mod = abs(Number);", res); }
public void TestRenameVariable7() { string res = Refactor.RenameVariable("int b = 1; double b1 = 1.0;", "b", "Number"); Assert.AreEqual("int Number = 1; double b1 = 1.0;", res); }
private string DoEdit(string cs, params string[] bases) { CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); foreach (string b in bases) { refactor.Queue(new AddBaseType(globals.Types[0], b)); } return refactor.Process(); }
public void TestRenameVariable10() { string res = Refactor.RenameVariable("int a1 = 1; string a = \"a is\";", "a", "Number"); Assert.AreEqual("int a1 = 1; string Number = \"a is\";", res); }
internal void Execute(bool upgradeDatastore, MethodInfo?unitTestScript, Predicate <UpgradeScript> predicate, bool standAloneScript) { #pragma warning disable CS0618 // Type or member is obsolete if (executed && standAloneScript) { throw new InvalidOperationException(); } List <UpgradeScript> scripts = GetUpgradeScripts(unitTestScript); bool anyScriptRan = false; foreach (UpgradeScript script in scripts.Where(item => predicate.Invoke(item))) { bool scriptCommitted = false; if (upgradeDatastore && PersistenceProvider.IsNeo4j) { using (Transaction.Begin(true)) { if (!Parser.HasScript(script)) { Debug.WriteLine("Running script: {0}.{1}.{2} ({3})", script.Major, script.Minor, script.Patch, script.Name); Stopwatch sw = Stopwatch.StartNew(); Refactor.ApplyFunctionalIds(); RunScriptChecked(script); Refactor.ApplyFunctionalIds(); Parser.CommitScript(script); anyScriptRan = true; scriptCommitted = true; sw.Stop(); Debug.WriteLine("Finished script in {0} ms.", sw.ElapsedMilliseconds); } else { RunScriptChecked(script); } } } else { RunScriptChecked(script); } if (upgradeDatastore && scriptCommitted) { using (Transaction.Begin(true)) { Parser.ForceScript(delegate() { Refactor.ApplyConstraints(); }); Transaction.Commit(); } } } if (upgradeDatastore) { using (Transaction.Begin(true)) { Parser.ForceScript(delegate() { Refactor.ApplyConstraints(); }); Transaction.Commit(); } using (Transaction.Begin(true)) { if (!anyScriptRan && Parser.ShouldRefreshFunctionalIds()) { Refactor.ApplyFunctionalIds(); Parser.SetLastRun(); } Transaction.Commit(); } } SubscribeEventHandlers(); executed = true; #pragma warning restore CS0618 // Type or member is obsolete }
public void TestRenameVariable4() { string res = Refactor.RenameVariable("int a=1,a1;", "a", "Number"); Assert.AreEqual("int Number=1,a1;", res); }
private string DoEdit(string cs, int offset, int length, string indent) { Refactor refactor = new Refactor(cs); refactor.Queue(new Indent(offset, length, indent)); return refactor.Process(); }
public void Init(string text) { Contract.Assert(m_refactor == null, "Create a new boss instance instead of calling Init multiple times"); m_refactor = new Refactor(text); }
private string DoEdit(string cs, bool after, int i, params string[] lines) { CsParser.Parser parser = new CsParser.Parser(); CsGlobalNamespace globals = parser.Parse(cs); Refactor refactor = new Refactor(cs); refactor.Queue(new AddRelativeMember(globals.Types[0].Methods[i], after, lines)); return refactor.Process(); }
public void TestRenameVariable8() { string res = Refactor.RenameVariable("int s = 5; int mass[s] = {0};", "s", "Size"); Assert.AreEqual("int Size = 5; int mass[Size] = {0};", res); }