Пример #1
0
        public void VBPowerOperator()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(GetCode(vb, "^="));
            string expectedRuby = GetCode(RubyCodeTemplate, "**=");

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #2
0
        public void ModulusOperator()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(GetCode(csharp, "%="));
            string expectedRuby = GetCode(RubyCodeTemplate, "%=");

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void GeneratedMainMethodCallWithNoParametersCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "  ";
            converter.Convert(mainMethodWithNoParametersCode);
            string code = converter.GenerateMainMethodCall(converter.EntryPointMethods[0]);

            Assert.AreEqual("Foo.Main()", code);
        }
Пример #4
0
        public void ConvertedRubyCode()
        {
            string expectedCode =
                "class Foo < Bar, IMyInterface\r\n" +
                "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(csharp);

            Assert.AreEqual(expectedCode, code);
        }
        public void GeneratedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);
            string Ruby         = converter.Convert(csharp);
            string expectedRuby = "require \"mscorlib\"\r\n" +
                                  "require \"System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" +
                                  "\r\n" +
                                  "class Foo\r\n" +
                                  "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #6
0
        public static bool Convert(SupportedLanguage inputLanguage, string ProvidedSource, out string ConvertedSource, out string ErrorMessage)
        {
            NRefactoryToRubyConverter converter = new
                                                  NRefactoryToRubyConverter(inputLanguage);

            string convertedCode = converter.Convert(ProvidedSource);

            ConvertedSource = convertedCode;
            ErrorMessage    = "";

            return(true);
        }
        public void ConvertedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby = "class Foo\r\n" +
                                  "    def initialize()\r\n" +
                                  "    end\r\n" +
                                  "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void ExpectedCodeWrittenToFile()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp, parseInfo);
            string expectedCode = converter.Convert(sourceCode, SupportedLanguage.CSharp) +
                                  "\r\n" +
                                  "\r\n" +
                                  converter.GenerateMainMethodCall(converter.EntryPointMethods[0]);

            List <ConvertedFile> expectedSavedFiles = new List <ConvertedFile>();

            expectedSavedFiles.Add(new ConvertedFile(target.FileName, expectedCode, Encoding.Unicode));
            Assert.AreEqual(expectedSavedFiles, convertProjectCommand.SavedFiles);
        }
        public void ConvertedRubyCode()
        {
            string expectedCode = "class Foo\r\n" +
                                  "    def Run()\r\n" +
                                  "        raise XmlException.new()\r\n" +
                                  "    end\r\n" +
                                  "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(csharp);

            Assert.AreEqual(expectedCode, code);
        }
        public void GeneratedRubySourceCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(vb);
            string expectedRuby =
                "module DefaultNamespace\r\n" +
                "    class Class1\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void GeneratedRubySourceCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby =
                "module MyNamespace\r\n" +
                "    class Foo\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #12
0
        public void SwitchStatement()
        {
            string csharp =
                "class Foo\r\n" +
                "{\r\n" +
                "    public int Run(int i)\r\n" +
                "    {\r\n" +
                "        switch (i) {\r\n" +
                "            case 7:\r\n" +
                "                i = 4;\r\n" +
                "                break;\r\n" +
                "            case 10:\r\n" +
                "                return 0;\r\n" +
                "            case 9:\r\n" +
                "                return 2;\r\n" +
                "            case 8:\r\n" +
                "                break;\r\n" +
                "            default:\r\n" +
                "                return -1;\r\n" +
                "        }\r\n" +
                "        return i;\r\n" +
                "    }\r\n" +
                "}";

            string expectedRuby =
                "class Foo\r\n" +
                "  def Run(i)\r\n" +
                "    case i\r\n" +
                "      when 7\r\n" +
                "        i = 4\r\n" +
                "      when 10\r\n" +
                "        return 0\r\n" +
                "      when 9\r\n" +
                "        return 2\r\n" +
                "      when 8\r\n" +
                "      else\r\n" +
                "        return -1\r\n" +
                "    end\r\n" +
                "    return i\r\n" +
                "  end\r\n" +
                "end";

            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "  ";
            string code = converter.Convert(csharp);

            Assert.AreEqual(expectedRuby, code, code);
        }
        public void ConvertCSharpClassWithFieldsWhereFirstFieldDoesNotHaveInitialValue()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string ruby         = converter.Convert(csharpClassWithTwoFieldsWhereFirstDoesNotHaveInitialValue);
            string expectedRuby =
                "class Foo\r\n" +
                "    def initialize()\r\n" +
                "        @j = 1\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, ruby);
        }
        public void ConvertedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby = "class Foo\r\n" +
                                  "    def TestMe(test)\r\n" +
                                  "        a = test ? \"Ape\" : \"Monkey\"\r\n" +
                                  "        return a\r\n" +
                                  "    end\r\n" +
                                  "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void ConvertedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby =
                "class Foo\r\n" +
                "    def IsEqual(o)\r\n" +
                "        return System::Object.ReferenceEquals(o, nil)\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby, Ruby);
        }
        protected void Run(IWorkbench workbench, ITextEditorProperties textEditorProperties)
        {
            // Get the code to convert.
            IViewContent viewContent = workbench.ActiveWorkbenchWindow.ActiveViewContent;
            IEditable    editable    = viewContent as IEditable;

            // Generate the ruby code.
            ParseInformation          parseInfo = GetParseInformation(viewContent.PrimaryFileName);
            NRefactoryToRubyConverter converter = NRefactoryToRubyConverter.Create(viewContent.PrimaryFileName, parseInfo);

            converter.IndentString = NRefactoryToRubyConverter.GetIndentString(textEditorProperties);
            string pythonCode = converter.Convert(editable.Text);

            // Show the python code in a new window.
            NewFile("Generated.rb", "Ruby", pythonCode);
        }
Пример #17
0
        public void GeneratedRubySourceCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby =
                "class Foo\r\n" +
                "    def Print()\r\n" +
                "        i = 0\r\n" +
                "        self.PrintInt(i)\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void ConvertVBNetClassWithTwoArrayVariablesOnSameLine()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);

            converter.IndentString = "    ";
            string ruby         = converter.Convert(vnetClassWithTwoArrayLocalVariablesOnSameLine);
            string expectedRuby =
                "class Foo\r\n" +
                "    def initialize()\r\n" +
                "        i = Array.CreateInstance(System::Int32, 10)\r\n" +
                "        j = Array.CreateInstance(System::Int32, 20)\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, ruby);
        }
        public void ConvertedTypeOfIntegerCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(typeofIntCode);
            string expectedRuby =
                "require \"mscorlib\"\r\n" +
                "\r\n" +
                "class Foo\r\n" +
                "    def ToString()\r\n" +
                "        System::Int32.to_clr_type.FullName\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #20
0
        public void ConvertedStringArrayCode()
        {
            string expectedCode =
                "class Foo\r\n" +
                "    def Run()\r\n" +
                "        i = Array[System::String].new([\"a\", \"b\"])\r\n" +
                "        i[0] = \"c\"\r\n" +
                "        return i\r\n" +
                "    end\r\n" +
                "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(stringArray);

            Assert.AreEqual(expectedCode, code);
        }
Пример #21
0
        public void ConvertedUriArrayCode()
        {
            string expectedCode =
                "class Foo\r\n" +
                "    def Run()\r\n" +
                "        i = Array[Uri].new([Uri.new(\"a\"), Uri.new(\"b\")])\r\n" +
                "        i[0] = Uri.new(\"c\")\r\n" +
                "        return i\r\n" +
                "    end\r\n" +
                "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(uriArray);

            Assert.AreEqual(expectedCode, code);
        }
Пример #22
0
        public void ConvertedIntegerArrayCode()
        {
            string expectedCode =
                "class Foo\r\n" +
                "    def Run()\r\n" +
                "        i = Array[System::Int32].new([1, 2, 3, 4])\r\n" +
                "        i[0] = 5\r\n" +
                "        return i\r\n" +
                "    end\r\n" +
                "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(integerArray);

            Assert.AreEqual(expectedCode, code);
        }
        public void GeneratedRubySourceCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby =
                "require \"mscorlib\"\r\n" +
                "require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\r\n" +
                "\r\n" +
                "module MyNamespace\r\n" +
                "    class Foo\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #24
0
        public void ConvertedBarArrayCode()
        {
            string expectedCode =
                "class Foo\r\n" +
                "    def Run()\r\n" +
                "        i = Array[Bar].new([Bar.new(), Bar.new()])\r\n" +
                "        i[0] = Bar.new()\r\n" +
                "        return i\r\n" +
                "    end\r\n" +
                "end";
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string code = converter.Convert(barArray);

            Assert.AreEqual(expectedCode, code);
        }
        public void ConvertedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet);

            converter.IndentString = "    ";
            string ruby         = converter.Convert(vb);
            string expectedRuby =
                "class Class1\r\n" +
                "    def Test()\r\n" +
                "        while true\r\n" +
                "            break\r\n" +
                "        end\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, ruby);
        }
        public void GeneratedRubySourceCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby =
                "class Foo\r\n" +
                "    def Assign()\r\n" +
                "        elements = Array.CreateInstance(System::Int32, 10)\r\n" +
                "        list = List[Array[System::Int32]].new()\r\n" +
                "        list.Add(elements.Clone())\r\n" +
                "    end\r\n" +
                "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
Пример #27
0
        public void ConvertedRubyCode()
        {
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby         = converter.Convert(csharp);
            string expectedRuby = "class Foo\r\n" +
                                  "    def Run(a)\r\n" +
                                  "        if a == nil then\r\n" +
                                  "            return 4\r\n" +
                                  "        end\r\n" +
                                  "        return 2\r\n" +
                                  "    end\r\n" +
                                  "end";

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void ConvertedRubyCode()
        {
            string expectedRuby =
                "class Foo\r\n" +
                "    def initialize()\r\n" +
                "        doc = XmlDocument.new()\r\n" +
                "        doc.LoadXml(\"<root/>\")\r\n" +
                "    end\r\n" +
                "end";

            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string Ruby = converter.Convert(csharp);

            Assert.AreEqual(expectedRuby, Ruby);
        }
        public void ConvertedRubyCode()
        {
            string expectedCode =
                "class Foo\r\n" +
                "    def initialize()\r\n" +
                "        button = Button.new()\r\n" +
                "        button.Click { self.ButtonClick() }\r\n" +
                "        button.MouseDown { self.OnMouseDown() }\r\n" +
                "    end\r\n" +
                "end";

            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp, parseInfo);

            converter.IndentString = "    ";
            string code = converter.Convert(csharp);

            Assert.AreEqual(expectedCode, code, code);
        }
Пример #30
0
        public void Equals()
        {
            string code = GetCode(@"==");
            NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.CSharp);

            converter.IndentString = "    ";
            string RubyCode         = converter.Convert(code);
            string expectedRubyCode = "class Foo\r\n" +
                                      "    def Run(i)\r\n" +
                                      "        if i == 0 then\r\n" +
                                      "            return 10\r\n" +
                                      "        end\r\n" +
                                      "        return 0\r\n" +
                                      "    end\r\n" +
                                      "end";

            Assert.AreEqual(expectedRubyCode, RubyCode);
        }