public void SetUpFixture() { AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text); using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); UserControl userControl = (UserControl)host.RootComponent; userControl.ClientSize = new Size(489, 389); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(userControl, "userControl1"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null); RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions()); generator.Merge(host, docAdapter, compilationUnit, serializationManager); } } }
public void SetUpFixture() { string ruby = "class Test\r\n" + "\tdef initialize\r\n" + "\t\tputs 'test'\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { classFold = folds[0]; methodFold = folds[1]; } } }
public void SetUpFixture() { resourceWriter = new MockResourceWriter(); resourceService = new MockResourceService(); resourceService.SetResourceWriter(resourceWriter); AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.Text); 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()) { RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions()); generator.Merge(host, new AvalonEditDocumentAdapter(document, null), compilationUnit, serializationManager); } } }
public void SetUpFixture() { string Ruby = "require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\""; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); }
public void SetLexerTags() { RubyParser parser = new RubyParser(); string[] tags = new string[] {"Test"}; parser.LexerTags = tags; Assert.AreEqual(tags, parser.LexerTags); }
public void SetUpFixture() { string ruby = "class Class1\r\n" + " @\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); }
public void ParseDoesNotThrowNullReferenceException() { string ruby = "require #"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); ICompilationUnit unit = null; Assert.DoesNotThrow(delegate { unit = parser.Parse(projectContent, @"C:\test.rb", ruby); }); Assert.IsNotNull(unit); }
/// <summary> /// Creates a control either a UserControl or Form from the Ruby code. /// </summary> public IComponent CreateComponent(string rubyCode) { RubyParser parser = new RubyParser(); SourceUnitTree ast = parser.CreateAst(@"Control.rb", new StringTextBuffer(rubyCode)); Walk(ast); // Did we find the InitializeComponent method? if (!FoundInitializeComponentMethod) { throw new RubyComponentWalkerException("Unable to find InitializeComponents method."); } return component; }
public void SetUpFixture() { string Ruby = "class Test\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\Projects\Test\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; } }
public void SetUpFixture() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\test\MainForm.py", GetRubyCode()); parseInfo = new ParseInformation(compilationUnit); if (compilationUnit.Classes.Count > 0) { mainFormClass = compilationUnit.Classes[0]; initializeComponentsMethod = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(mainFormClass); } }
public void InitializeComponentsUsedInsteadOfInitializeComponent() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); string code = GetFormCode().Replace("InitializeComponent", "InitializeComponents"); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.rb", code); ParseInformation parseInfo = new ParseInformation(compilationUnit); IMethod expectedMethod = GetInitializeComponentMethod(compilationUnit); IMethod method = RubyDesignerGenerator.GetInitializeComponents(compilationUnit); Assert.IsNotNull(method); Assert.AreSame(expectedMethod, method); }
/// <summary> /// Creates a control either a UserControl or Form from the Ruby code. /// </summary> public IComponent CreateComponent(string rubyCode) { RubyParser parser = new RubyParser(); SourceUnitTree ast = parser.CreateAst(@"Control.rb", new StringTextBuffer(rubyCode)); Walk(ast); // Did we find the InitializeComponent method? if (!FoundInitializeComponentMethod) { throw new RubyComponentWalkerException("Unable to find InitializeComponents method."); } return(component); }
public void SetUpFixture() { textEditorOptions = new MockTextEditorOptions(); generator = new DerivedRubyDesignerGenerator(textEditorOptions); mockViewContent = new MockTextEditorViewContent(); viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName)); generator.Attach(viewContent); viewContent.DesignerCodeFileContent = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), fileName, GetTextEditorCode()); ParseInformation parseInfo = new ParseInformation(parserCompilationUnit); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; AfterSetUpFixture(); }
public void SetUpFixture() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.rb", GetFormCode()); // Create parse info to return from ParseFile method. parseInfo = new ParseInformation(compilationUnit); // Get the InitializeComponent method from the // compilation unit. expectedInitializeComponentMethod = GetInitializeComponentMethod(compilationUnit); // Find the InitializeComponent method using the designer generator. initializeComponentMethod = RubyDesignerGenerator.GetInitializeComponents(compilationUnit); }
public void SetUpFixture() { AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); 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.Text); 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); MockTextEditorOptions options = new MockTextEditorOptions(); options.ConvertTabsToSpaces = true; options.IndentationSize = 4; DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null); RubyDesignerGenerator generator = new RubyDesignerGenerator(options); generator.Merge(host, docAdapter, compilationUnit, serializationManager); } } }
public void SetUpFixture() { string Ruby = "class Test\r\n" + "\tdef foo(a = 1, b = 'test')\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { IClass c = compilationUnit.Classes[0]; method = c.Methods[0]; if (method.Parameters.Count > 1) { parameterA = method.Parameters[0]; parameterB = method.Parameters[1]; } } }
public void SetUpFixture() { string ruby = "def foo\r\n" + "end\r\n" + "\r\n" + "def bar(i)\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { globalClass = compilationUnit.Classes[0]; if (globalClass.Methods.Count > 1) { fooMethod = globalClass.Methods[0]; barMethod = globalClass.Methods[1]; } } // Get folds. TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { fooMethodFold = folds[0]; barMethodFold = folds[1]; } }
public void SetUpFixture() { parser = new RubyParser(); }
/// <summary> /// Checks the file's extension represents a Ruby file. /// </summary> static bool IsRubyFile(string fileName) { RubyParser parser = new RubyParser(); return(parser.CanParse(fileName)); }
/// <summary> /// Checks the file's extension represents a Ruby file. /// </summary> static bool IsRubyFile(string fileName) { RubyParser parser = new RubyParser(); return parser.CanParse(fileName); }
static Statements Parse(string code) { RubyParser parser = new RubyParser(); SourceUnitTree unit = parser.CreateAst(@"snippet.rb", new StringTextBuffer(code)); return unit.Statements; }
ClassDefinition GetClassDefinition(string code) { RubyParser parser = new RubyParser(); SourceUnitTree unit = parser.CreateAst(@"test.rb", new StringTextBuffer(code)); return unit.Statements.First as ClassDefinition; }