public void AssertResource(string name) { var parser = new AnnotationParser(); parser.RegisterAnnotation <AssertInspectionAnnotation>(); SkriptFile file = null; var host = new InspectionDelegatingHost((uri, list) => { foreach (var diagnostic in list) { // ReSharper disable AccessToModifiedClosure Debug.Assert(file != null, nameof(file) + " != null"); var node = file.Nodes[diagnostic.Range.Start.Line]; //TODO: Allow multiple annotations to a single node by parsing the comments directly above. var comment = node.RawComment.TrimStart('#').Trim(); if (!comment.StartsWith("@")) { continue; } var annotation = parser.TryParse(comment); switch (annotation) { case AssertInspectionAnnotation assertInspectionAnnotation: Assert.Equal(assertInspectionAnnotation.InspectionType, diagnostic.Code); break; default: throw new ArgumentOutOfRangeException(nameof(annotation)); } // ReSharper restore AccessToModifiedClosure } }); WorkspaceManager.CurrentHost = host; var current = WorkspaceManager.CurrentWorkspace; var code = ReadResource(name); file = new SkriptFile(new Uri($"memory://{name}")); file.HandleChange(new TextDocumentContentChangeEvent { Text = code }); file.PrepareNodes(); parser.UnregisterAnnotation <AssertInspectionAnnotation>(); }
public void EmptyAnnotationParserWorks() { var code = "@empty"; var parser = new AnnotationParser(); parser.RegisterAnnotation <EmptyAnnotation>(); var annotation = parser.TryParse(code); Assert.NotNull(annotation); Assert.IsType <EmptyAnnotation>(annotation); parser.UnregisterAnnotation <EmptyAnnotation>(); }
public void OneStringParserWorks() { var code = new[] { "@onestring ", "@1str " }; var args = "one argument parameter"; var parser = new AnnotationParser(); parser.RegisterAnnotation <OneStringAnnotation>(); foreach (var prefix in code) { var annotation = parser.TryParse(prefix + args); Assert.NotNull(annotation); Assert.IsType <OneStringAnnotation>(annotation); Assert.Equal(args, ((OneStringAnnotation)annotation).Value); } parser.UnregisterAnnotation <EmptyAnnotation>(); }