Skip to content

Commit

Permalink
Add annotation order tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
comintern committed Jan 18, 2019
1 parent 446f1e1 commit 2073155
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions RubberduckTests/CodeExplorer/CodeExplorerFolderTests.cs
Expand Up @@ -6,6 +6,7 @@
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
Expand Down Expand Up @@ -89,6 +90,70 @@ Sub Foo()
}
}

[Category("Code Explorer")]
[Test]
public void AddedModuleIsAtCorrectDepth_FirstAnnotation()
{
const string inputCode =
@"'@Folder(""First.Second.Third"")
Sub Foo()
Dim d As Boolean
d = True
End Sub";

using (var explorer = new MockedCodeExplorer(ProjectType.HostProject, new[] { ComponentType.StandardModule }, new[] { inputCode })
.SelectFirstCustomFolder())
{
var project = explorer.ViewModel.Projects.OfType<CodeExplorerProjectViewModel>().First();
var folder = (CodeExplorerCustomFolderViewModel)explorer.ViewModel.SelectedItem;
var declarations = project.State.AllUserDeclarations.ToList();

var annotation = new FolderAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(1, 1)), null, new[] { "\"First\"" });
var predeclared = new PredeclaredIdAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(2, 1)), null, Enumerable.Empty<string>());

declarations.Add(GetNewClassDeclaration(project.Declaration, "Foo", new IAnnotation [] { annotation, predeclared }));

project.Synchronize(declarations);
var added = folder.Children.OfType<CodeExplorerComponentViewModel>().Single();

Assert.AreEqual(DeclarationType.ClassModule, added.Declaration.DeclarationType);
Assert.AreEqual("\"First\"", added.Declaration.CustomFolder);
}
}

[Category("Code Explorer")]
[Test]
public void AddedModuleIsAtCorrectDepth_NotFirstAnnotation()
{
const string inputCode =
@"'@Folder(""First.Second.Third"")
Sub Foo()
Dim d As Boolean
d = True
End Sub";

using (var explorer = new MockedCodeExplorer(ProjectType.HostProject, new[] { ComponentType.StandardModule }, new[] { inputCode })
.SelectFirstCustomFolder())
{
var project = explorer.ViewModel.Projects.OfType<CodeExplorerProjectViewModel>().First();
var folder = (CodeExplorerCustomFolderViewModel)explorer.ViewModel.SelectedItem;
var declarations = project.State.AllUserDeclarations.ToList();

var annotation = new FolderAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(2, 1)), null, new[] { "\"First\"" });
var predeclared = new PredeclaredIdAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(1, 1)), null, Enumerable.Empty<string>());

declarations.Add(GetNewClassDeclaration(project.Declaration, "Foo", new IAnnotation[] { predeclared, annotation }));

project.Synchronize(declarations);
var added = folder.Children.OfType<CodeExplorerComponentViewModel>().Single();

Assert.AreEqual(DeclarationType.ClassModule, added.Declaration.DeclarationType);
Assert.AreEqual("\"First\"", added.Declaration.CustomFolder);
}
}

[Category("Code Explorer")]
[Test]
public void AddedModuleIsAtCorrectDepth_RootNode()
Expand Down Expand Up @@ -298,6 +363,11 @@ private static Declaration GetNewClassDeclaration(Declaration project, string na
? Enumerable.Empty<IAnnotation>()
: new[] { new FolderAnnotation(new QualifiedSelection(project.QualifiedModuleName, new Selection(1, 1)), null, new[] { folder }) };

return GetNewClassDeclaration(project, name, annotations);
}

private static Declaration GetNewClassDeclaration(Declaration project, string name, IEnumerable<IAnnotation> annotations)
{
var declaration =
new ClassModuleDeclaration(new QualifiedMemberName(project.QualifiedModuleName, name), project, name, true, annotations, new Attributes());

Expand Down

0 comments on commit 2073155

Please sign in to comment.