本文整理汇总了C#中TestUtilities.UI.Python.PythonVisualStudioApp.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# PythonVisualStudioApp.GetDocument方法的具体用法?C# PythonVisualStudioApp.GetDocument怎么用?C# PythonVisualStudioApp.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtilities.UI.Python.PythonVisualStudioApp
的用法示例。
在下文中一共展示了PythonVisualStudioApp.GetDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnregisteredFileExtensionEditor
public void UnregisteredFileExtensionEditor() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\UnregisteredFileExtension.sln");
var item = project.ProjectItems.Item("Fob.unregfileext");
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
// we shouldn't have opened this as a .py file, so we should have no classifications.
var classifier = doc.Classifier;
var spans = classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));
Assert.AreEqual(spans.Count, 0);
}
}
示例2: ExtensionReference
public void ExtensionReference() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\ExtensionReference.sln");
app.OpenSolutionExplorer();
var solutionTree = app.SolutionExplorerTreeView;
var dbPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Python Tools",
"ReferencesDB",
#if DEBUG
"Debug",
#endif
AssemblyVersionInfo.VSVersion
);
var existingFiles = Directory.GetFiles(dbPath, "spam*");
// open the solution, add a reference to our spam.pyd Python extension module
var folderNode = solutionTree.FindItem(
"Solution 'ExtensionReference' (1 project)",
"ExtensionReference",
SR.GetString(SR.ReferencesNodeName)
);
folderNode.Select();
var dialog = new AddReferenceDialog(AutomationElement.FromHandle(app.OpenDialogWithDteExecuteCommand("Project.AddReference")));
dialog.ActivateBrowseTab();
dialog.BrowseFilename = TestData.GetPath(@"TestData\spam.pyd");
dialog.ClickOK();
app.WaitForDialogDismissed();
// make sure the reference got added
var spamItem = solutionTree.WaitForItem(
"Solution 'ExtensionReference' (1 project)",
"ExtensionReference",
SR.GetString(SR.ReferencesNodeName),
"spam.pyd"
);
Assert.IsNotNull(spamItem);
// wait for scraping to complete
for (int retries = 10;
Directory.GetFiles(dbPath, "spam*").Length == existingFiles.Length && retries > 0;
--retries) {
System.Threading.Thread.Sleep(1000);
}
Assert.AreNotEqual(existingFiles.Length, Directory.GetFiles(dbPath, "spam*").Length, "File was not scraped");
// now open a file and make sure we get completions against the spam module
var item = project.ProjectItems.Item("Program.py");
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
doc.MoveCaret(doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);
Keyboard.Type("spam.");
using (var sh = doc.WaitForSession<ICompletionSession>()) {
var completion = sh.Session.CompletionSets.First().Completions.Select(x => x.InsertionText).FirstOrDefault(x => x == "system");
Assert.IsNotNull(completion);
}
// now clear the text we just typed
for (int i = 0; i < 5; i++) {
Keyboard.Type(Key.Back);
}
// remove the extension
app.Dte.Solution.Projects.Item(1).ProjectItems.Item("References").ProjectItems.Item(@"spam.pyd").Remove();
// make sure it got removed
solutionTree.WaitForItemRemoved(
"Solution 'ExtensionReference' (1 project)",
"ExtensionReference",
SR.GetString(SR.ReferencesNodeName),
"spam.pyd"
);
window.Activate();
// and make sure we no longer offer completions on the spam module.
Keyboard.Type("spam.");
using (var sh = doc.WaitForSession<ICompletionSession>()) {
var completion = sh.Session.CompletionSets.First().Completions.Select(x => x.DisplayText).Single();
Assert.AreEqual(SR.GetString(SR.NoCompletionsCompletion), completion);
}
}
}
示例3: FormattingTest
/// <summary>
/// Runs a single formatting test
/// </summary>
/// <param name="filename">The filename of the document to perform formatting in (lives in FormattingTests.sln)</param>
/// <param name="selection">The selection to format, or null if formatting the entire document</param>
/// <param name="expectedText">The expected source code after the formatting</param>
/// <param name="changedSpans">The spans which should be marked as changed in the buffer after formatting</param>
private static void FormattingTest(
string filename,
Span? selection,
string expectedText,
Span[] changedSpans,
Func<PythonToolsService, object> updateSettings,
Action<PythonToolsService, object> revertSettings,
Version version = null
) {
using (var app = new PythonVisualStudioApp())
using (version == null ? null : app.SelectDefaultInterpreter(PythonPaths.Versions.FirstOrDefault(v => v.Version.ToVersion() >= version))) {
var o = updateSettings?.Invoke(app.PythonToolsService);
if (revertSettings != null) {
app.OnDispose(() => revertSettings(app.PythonToolsService, o));
}
var project = app.OpenProject(@"TestData\FormattingTests\FormattingTests.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var aggFact = app.ComponentModel.GetService<IViewTagAggregatorFactoryService>();
var changeTags = aggFact.CreateTagAggregator<ChangeTag>(doc.TextView);
// format the selection or document
if (selection == null) {
DoFormatDocument();
} else {
doc.Invoke(() => doc.TextView.Selection.Select(new SnapshotSpan(doc.TextView.TextBuffer.CurrentSnapshot, selection.Value), false));
DoFormatSelection();
}
// verify the contents are correct
string actual = null;
int steady = 50;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
if (--steady <= 0) {
break;
}
} else {
steady = 50;
}
System.Threading.Thread.Sleep(100);
}
Assert.AreEqual(expectedText, actual);
// verify the change tags are correct
var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
var tags = changeTags.GetTags(
new SnapshotSpan(
doc.TextView.TextBuffer.CurrentSnapshot,
new Span(0, doc.TextView.TextBuffer.CurrentSnapshot.Length)
)
);
List<Span> result = new List<Span>();
foreach (var tag in tags) {
result.Add(
new Span(
tag.Span.Start.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position,
tag.Span.End.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position
)
);
}
// dump the spans for creating tests easier
foreach (var span in result) {
Console.WriteLine(span);
}
Assert.AreEqual(result.Count, changedSpans.Length);
for (int i = 0; i < result.Count; i++) {
Assert.AreEqual(result[i], changedSpans[i]);
}
}
}
示例4: RunOne
private void RunOne(string filename, params SendToStep[] inputs) {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\SendToInteractive.sln");
var program = project.ProjectItems.Item(filename);
var window = program.Open();
window.Activate();
var doc = app.GetDocument(program.Document.FullName);
doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0));
var interactive = ReplWindowProxy.Prepare(new ReplWindowPython35Tests().Settings, false);
interactive.ExecuteText("42").Wait();
interactive.ClearScreen();
WaitForText(interactive.TextView, ">>> ");
var state = new StepState(interactive, app, doc, window);
state.Content.Append(">>> ");
foreach (var input in inputs) {
input.Execute(state);
}
}
}
示例5: GetClassifications
private static IList<ClassificationSpan> GetClassifications(string filename) {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\Classification.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
var classifier = doc.Classifier;
var spans = classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));
return spans;
}
}
示例6: OpenInvalidUnicodeFile
public void OpenInvalidUnicodeFile() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\ErrorProjectUnicode.sln");
var item = project.ProjectItems.Item("Program.py");
var windowTask = Task.Run(() => item.Open());
VisualStudioApp.CheckMessageBox(TestUtilities.MessageBoxButton.Ok, "File Load", "Program.py", "Unicode (UTF-8) encoding");
var window = windowTask.Result;
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var text = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
Console.WriteLine(string.Join(" ", text.Select(c => c < ' ' ? " . " : string.Format(" {0} ", c))));
Console.WriteLine(string.Join(" ", text.Select(c => string.Format("{0:X04}", (int)c))));
// Characters should have been replaced
Assert.AreNotEqual(-1, text.IndexOf("\uFFFD\uFFFD\uFFFD\uFFFD", StringComparison.Ordinal));
}
}
示例7: CompletionsCaseSensitive
public void CompletionsCaseSensitive() {
// http://pytools.codeplex.com/workitem/457
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\Completions.sln");
var item = project.ProjectItems.Item("oar.py");
var window = item.Open();
window.Activate();
Keyboard.Type("from fob import ba\r");
var doc = app.GetDocument(item.Document.FullName);
doc.WaitForText("from fob import baz");
Keyboard.Type("\r");
Keyboard.Type("from fob import Ba\r");
doc.WaitForText("from fob import baz\r\nfrom fob import Baz");
}
}
示例8: MultiLineSignaturesTest
public void MultiLineSignaturesTest() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\Signatures.sln");
var item = project.ProjectItems.Item("multilinesigs.py");
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
doc.SetFocus();
((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(5 - 1).Start;
doc.TextView.Caret.MoveTo(point);
((UIElement)doc.TextView).Focus();
}));
app.ExecuteCommand("Edit.ParameterInfo");
using (var sh = doc.WaitForSession<ISignatureHelpSession>()) {
Assert.AreEqual("b", sh.Session.SelectedSignature.CurrentParameter.Name);
}
}
}
示例9: SignaturesTest
public void SignaturesTest() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\Signatures.sln");
var item = project.ProjectItems.Item("sigs.py");
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
doc.SetFocus();
((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
doc.TextView.Caret.MoveTo(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, doc.TextView.TextBuffer.CurrentSnapshot.Length));
((UIElement)doc.TextView).Focus();
}));
Keyboard.Type("f(");
using (var sh = doc.WaitForSession<ISignatureHelpSession>()) {
var session = sh.Session;
Assert.AreEqual("a", session.SelectedSignature.CurrentParameter.Name);
Keyboard.Type("b=");
WaitForCurrentParameter(session, "b");
Assert.AreEqual("b", session.SelectedSignature.CurrentParameter.Name);
window.Activate();
Keyboard.Type("42,");
WaitForNoCurrentParameter(session);
Assert.AreEqual(null, session.SelectedSignature.CurrentParameter);
Keyboard.Backspace();
WaitForCurrentParameter(session);
Assert.AreEqual("b", session.SelectedSignature.CurrentParameter.Name);
}
}
}
示例10: OutlineTest
private void OutlineTest(string filename, params ExpectedTag[] expected) {
using (var app = new PythonVisualStudioApp()) {
var prevOption = app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen;
try {
app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = true;
var project = app.OpenProject(@"TestData\Outlining.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
var tags = doc.GetTaggerAggregator<IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));
VerifyTags(doc.TextView.TextBuffer, tags, expected);
} finally {
app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = prevOption;
}
}
}