public void SetUpFixture()
        {
            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            generator       = new DerivedPythonDesignerGenerator();
            mockViewContent = new MockTextEditorViewContent();
            viewContent     = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py"));
            viewContent.DesignerCodeFileContent = GetTextEditorCode();
            generator.Attach(viewContent);
            viewContentAttached = generator.GetViewContent();

            ParseInformation parseInfo             = new ParseInformation();
            PythonParser     parser                = new PythonParser();
            ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.py", GetTextEditorCode());

            parseInfo.SetCompilationUnit(parserCompilationUnit);
            generator.ParseInfoToReturnFromParseFileMethod = parseInfo;

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    generator.MergeRootComponentChanges(host, serializationManager);
                    generator.Detach();
                }
            }
        }
        public void TabIndent()
        {
            MockTextEditorProperties properties = new MockTextEditorProperties();

            properties.ConvertTabsToSpaces = false;
            Assert.AreEqual("\t", NRefactoryToPythonConverter.GetIndentString(properties));
        }
示例#3
0
        public void SetUpFixture()
        {
            mockViewContent      = new MockEditableViewContent();
            mockViewContent.Text =
                "class Foo\r\n" +
                "{\r\n" +
                "    public Foo()\r\n" +
                "    {\r\n" +
                "    }\r\n" +
                "}";

            mockViewContent.PrimaryFileName = "test.cs";

            MockWorkbench       workbench = new MockWorkbench();
            MockWorkbenchWindow window    = new MockWorkbenchWindow();

            window.ActiveViewContent        = mockViewContent;
            workbench.ActiveWorkbenchWindow = window;

            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            textEditorProperties.IndentationSize     = 4;
            textEditorProperties.ConvertTabsToSpaces = true;

            Run(workbench, textEditorProperties);
        }
示例#4
0
        public void SetUpFixture()
        {
            MSBuildEngineHelper.InitMSBuildEngine();

            List <LanguageBindingDescriptor> bindings = new List <LanguageBindingDescriptor>();

            using (TextReader reader = RubyBindingAddInFile.ReadAddInFile()) {
                AddIn addin = AddIn.Load(reader, String.Empty);
                bindings.Add(new LanguageBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/LanguageBindings", "Ruby")));
            }
            LanguageBindingService.SetBindings(bindings);

            mockTextEditorProperties = new MockTextEditorProperties();
            convertProjectCommand    = new DerivedConvertProjectToRubyProjectCommand(mockTextEditorProperties);
            parseInfo = new ParseInformation();
            convertProjectCommand.ParseInfo   = parseInfo;
            mockTextEditorProperties.Encoding = Encoding.Unicode;

            sourceProject           = new MockProject();
            sourceProject.Directory = @"d:\projects\test";
            source        = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Program.cs");
            targetProject = (RubyProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
            target        = new FileProjectItem(targetProject, source.ItemType, source.Include);
            source.CopyMetadataTo(target);

            textFileSource = new FileProjectItem(sourceProject, ItemType.None, @"src\readme.txt");
            textFileTarget = new FileProjectItem(targetProject, textFileSource.ItemType, textFileSource.Include);
            textFileSource.CopyMetadataTo(textFileTarget);

            convertProjectCommand.AddParseableFileContent(source.FileName, sourceCode);

            convertProjectCommand.CallConvertFile(source, target);
            convertProjectCommand.CallConvertFile(textFileSource, textFileTarget);
        }
        public void TwoChaSpaceIndent()
        {
            MockTextEditorProperties properties = new MockTextEditorProperties();

            properties.ConvertTabsToSpaces = true;
            properties.IndentationSize     = 2;
            Assert.AreEqual("  ", NRefactoryToPythonConverter.GetIndentString(properties));
        }
示例#6
0
        public void Init()
        {
            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            textEditorProperties.IndentStyle = IndentStyle.Smart;
            textEditorProperties.TabIndent   = 4;
            textEditor = new TextEditorControl();
            textEditor.TextEditorProperties = textEditorProperties;
            formattingStrategy = new PythonFormattingStrategy();
        }
        public void SetUpFixture()
        {
            MSBuildEngineHelper.InitMSBuildEngine();

            List <LanguageBindingDescriptor> bindings = new List <LanguageBindingDescriptor>();

            using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
                AddIn addin = AddIn.Load(reader, String.Empty);
                bindings.Add(new LanguageBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/LanguageBindings", "Python")));
            }
            LanguageBindingService.SetBindings(bindings);

            // Set up IProjectContent so the ConvertProjectToPythonProjectCommand can
            // locate the startup object and determine it's filename.

            mockProjectContent = new MockProjectContent();
            MockClass mainClass = new MockClass(mockProjectContent, startupObject);

            mainClass.CompilationUnit.FileName           = @"d:\projects\test\src\Main2.cs";
            mockProjectContent.ClassToReturnFromGetClass = mainClass;

            mockTextEditorProperties             = new MockTextEditorProperties();
            convertProjectCommand                = new DerivedConvertProjectToPythonProjectCommand(mockTextEditorProperties);
            convertProjectCommand.ProjectContent = mockProjectContent;
            mockTextEditorProperties.Encoding    = Encoding.Unicode;

            Solution solution = new Solution();

            sourceProject          = new MSBuildBasedProject(solution.BuildEngine);
            sourceProject.Parent   = solution;
            sourceProject.FileName = @"d:\projects\test\source.csproj";
            sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true);
            mainFile      = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs");
            targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
            convertProjectCommand.CallCopyProperties(sourceProject, targetProject);
            targetMainFile = new FileProjectItem(targetProject, mainFile.ItemType, mainFile.Include);
            mainFile.CopyMetadataTo(targetMainFile);

            main2File       = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs");
            targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include);
            main2File.CopyMetadataTo(targetMain2File);

            convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource);
            convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source);

            convertProjectCommand.CallConvertFile(mainFile, targetMainFile);
            convertProjectCommand.CallConvertFile(main2File, targetMain2File);
        }
示例#8
0
        public void SetUpFixture()
        {
            textEditorProperties = new MockTextEditorProperties();
            generator            = new DerivedPythonDesignerGenerator(textEditorProperties);
            mockViewContent      = new MockTextEditorViewContent();
            viewContent          = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName));
            generator.Attach(viewContent);
            viewContent.DesignerCodeFileContent = GetTextEditorCode();

            ParseInformation parseInfo             = new ParseInformation();
            PythonParser     parser                = new PythonParser();
            ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), fileName, GetTextEditorCode());

            parseInfo.SetCompilationUnit(parserCompilationUnit);
            generator.ParseInfoToReturnFromParseFileMethod = parseInfo;

            AfterSetUpFixture();
        }
        public void SetUpFixture()
        {
            using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(null, new MockOpenedFile("Test.py"))) {
                viewContent.DesignerCodeFileContent =
                    "class MainForm < Form\r\n" +
                    " def initialize()\r\n" +
                    "  self.InitializeComponent()\r\n" +
                    " end\r\n" +
                    "\r\n" +
                    " def InitializeComponent()\r\n" +
                    " end\r\n" +
                    "end";

                document = viewContent.DesignerCodeFileDocument;

                ParseInformation parseInfo       = new ParseInformation();
                RubyParser       parser          = new RubyParser();
                ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.TextContent);
                parseInfo.SetCompilationUnit(compilationUnit);

                using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                    IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                    Form          form = (Form)host.RootComponent;
                    form.ClientSize = new Size(284, 264);

                    PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                    PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                    namePropertyDescriptor.SetValue(form, "MainForm");

                    MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();
                    textEditorProperties.ConvertTabsToSpaces = true;
                    textEditorProperties.IndentationSize     = 1;

                    DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(textEditorProperties);
                    generator.ParseInfoToReturnFromParseFileMethod = parseInfo;
                    generator.Attach(viewContent);
                    DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                    using (serializationManager.CreateSession()) {
                        generator.MergeRootComponentChanges(host, serializationManager);
                    }
                }
            }
        }
示例#10
0
        public void SetUpFixture()
        {
            using (TextEditorControl textEditor = new TextEditorControl()) {
                document        = textEditor.Document;
                textEditor.Text = GetTextEditorCode();

                RubyParser         parser         = new RubyParser();
                MockProjectContent projectContent = new MockProjectContent();
                MockProject        project        = new MockProject();
                project.RootNamespace  = "RootNamespace";
                projectContent.Project = project;
                ICompilationUnit compilationUnit = parser.Parse(projectContent, @"test.py", document.TextContent);

                using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                    IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                    IEventBindingService eventBindingService = new MockEventBindingService(host);
                    Form form = (Form)host.RootComponent;
                    form.ClientSize = new Size(200, 300);

                    PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                    PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                    namePropertyDescriptor.SetValue(form, "MainForm");

                    // Add picture box
                    PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1");
                    pictureBox.Location = new Point(0, 0);
                    pictureBox.Image    = new Bitmap(10, 10);
                    pictureBox.Size     = new Size(100, 120);
                    pictureBox.TabIndex = 0;
                    form.Controls.Add(pictureBox);

                    MockTextEditorProperties properties = new MockTextEditorProperties();
                    properties.ConvertTabsToSpaces = true;
                    properties.IndentationSize     = 4;

                    DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                    using (serializationManager.CreateSession()) {
                        RubyDesignerGenerator.Merge(host, document, compilationUnit, properties, serializationManager);
                    }
                }
            }
        }
        public void SetUpFixture()
        {
            MSBuildEngineHelper.InitMSBuildEngine();

            List <LanguageBindingDescriptor> bindings = new List <LanguageBindingDescriptor>();

            using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) {
                AddIn addin = AddIn.Load(reader, String.Empty);
                bindings.Add(new LanguageBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/LanguageBindings", "Python")));
            }
            LanguageBindingService.SetBindings(bindings);

            mockTextEditorProperties          = new MockTextEditorProperties();
            convertProjectCommand             = new DerivedConvertProjectToPythonProjectCommand(mockTextEditorProperties);
            mockTextEditorProperties.Encoding = Encoding.Unicode;

            sourceProject           = new MockProject();
            sourceProject.Directory = @"d:\projects\test";
            source        = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Program.cs");
            targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject);
            target        = new FileProjectItem(targetProject, source.ItemType, source.Include);
            source.CopyMetadataTo(target);

            textFileSource = new FileProjectItem(sourceProject, ItemType.None, @"src\readme.txt");
            textFileTarget = new FileProjectItem(targetProject, textFileSource.ItemType, textFileSource.Include);
            textFileSource.CopyMetadataTo(textFileTarget);

            foreach (ProjectItem item in targetProject.Items)
            {
                ReferenceProjectItem reference = item as ReferenceProjectItem;
                if ((reference != null) && (reference.Name == "IronPython"))
                {
                    ironPythonReference = reference;
                    break;
                }
            }

            convertProjectCommand.AddParseableFileContent(source.FileName, sourceCode);

            convertProjectCommand.CallConvertFile(source, target);
            convertProjectCommand.CallConvertFile(textFileSource, textFileTarget);
        }
        public void SetUpFixture()
        {
            mockViewContent      = new MockEditableViewContent();
            mockViewContent.Text =
                "class Foo\r\n" +
                "    Public Sub New\r\n" +
                "    End Sub\r\n" +
                "end class";
            mockViewContent.PrimaryFileName = "test.vb";

            MockWorkbench       workbench = new MockWorkbench();
            MockWorkbenchWindow window    = new MockWorkbenchWindow();

            window.ActiveViewContent        = mockViewContent;
            workbench.ActiveWorkbenchWindow = window;

            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            textEditorProperties.ConvertTabsToSpaces = false;
            textEditorProperties.IndentationSize     = 2;

            Run(workbench, textEditorProperties);
        }