Beispiel #1
0
        private static void TokenizeFileImplementation <TToken, TTokenType, TTokenizer>(DeployFilesFixture fixture, string name, string language)
            where TTokenizer : ITokenizer <TToken>, new() where TToken : IToken <TTokenType>
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tokens";

            string        text         = fixture.LoadDestinationFile(name);
            ITextProvider textProvider = new TextStream(text);
            var           tokenizer    = new TTokenizer();

            var    tokens = tokenizer.Tokenize(textProvider, 0, textProvider.Length);
            string actual = DebugWriter.WriteTokens <TToken, TTokenType>(tokens);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                string enlistmentPath = @"F:\RTVS\src\R\Support\Test\" + language + @"\Files\Tokenization";
                baselineFile = Path.Combine(enlistmentPath, Path.GetFileName(testFile)) + ".tokens";

                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #2
0
        private void ClassifyFile(MarkdownTestFilesFixture fixture, string fileName)
        {
            var testFile = fixture.GetDestinationPath(fileName);
            var content  = fixture.LoadDestinationFile(fileName);

            var textBuffer = new TextBufferMock(content, MdContentTypeDefinition.ContentType);

            var crs  = _coreShell.GetService <IClassificationTypeRegistryService>();
            var ctrs = _coreShell.GetService <IContentTypeRegistryService>();
            var classifierProvider = new MdClassifierProvider(crs, ctrs);
            var cls = classifierProvider.GetClassifier(textBuffer);

            var spans        = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length)));
            var actual       = ClassificationWriter.WriteClassifications(spans);
            var baselineFile = testFile + ".colors";

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(fixture.SourcePath, @"Classification\", Path.GetFileName(testFile)) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #3
0
        private void ClassifyFile(MarkdownTestFilesFixture fixture, string fileName)
        {
            string testFile = fixture.GetDestinationPath(fileName);
            string content  = fixture.LoadDestinationFile(fileName);

            TextBufferMock textBuffer = new TextBufferMock(content, MdContentTypeDefinition.ContentType);

            var crs  = _exportProvider.GetExportedValue <IClassificationTypeRegistryService>();
            var ctrs = _exportProvider.GetExportedValue <IContentTypeRegistryService>();
            var cnp  = _exportProvider.GetExports <IClassificationNameProvider, IComponentContentTypes>();

            MdClassifierProvider classifierProvider = new MdClassifierProvider(crs, ctrs, cnp, _exportProvider.GetExportedValue <ICoreShell>());

            _exportProvider.GetExportedValue <ICoreShell>().CompositionService.SatisfyImportsOnce(classifierProvider);

            IClassifier cls = classifierProvider.GetClassifier(textBuffer);

            IList <ClassificationSpan> spans = cls.GetClassificationSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, new Span(0, textBuffer.CurrentSnapshot.Length)));
            string actual = ClassificationWriter.WriteClassifications(spans);

            string baselineFile = testFile + ".colors";

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(fixture.SourcePath, @"Classification\", Path.GetFileName(testFile)) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #4
0
        private void CompareToBaseline(string baselineFileName, string actual)
        {
            var baselineFilePath = Path.Combine(_files.SourcePath, _folder, baselineFileName) + ".html";

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                TestFiles.UpdateBaseline(baselineFilePath, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFilePath, actual);
            }
        }
Beispiel #5
0
        private void VerifyClassifications(string testFileName, string actual)
        {
            var testFilePath = _files.GetDestinationPath(testFileName);
            var baselineFile = testFilePath + ".colors";

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(_files.SourcePath, testFileName) + ".colors";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #6
0
        public static void CompareVisualTrees(DeployFilesFixture fixture, VisualTreeObject actual, string fileName)
        {
            var testFileName = fileName + ".tree";

            var serializedActual = SerializeVisualTree(actual);
            var baselineFilePath = fixture.GetSourcePath(testFileName);

            if (_regenerateBaselineFiles)
            {
                TestFiles.UpdateBaseline(baselineFilePath, serializedActual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFilePath, serializedActual);
            }
        }
Beispiel #7
0
        private static void CompareVisualTreesImplementation(DeployFilesFixture fixture, VisualTreeObject actual, string fileName)
        {
            string testFileName = fileName + ".tree";
            string testFilePath = fixture.GetDestinationPath(testFileName);

            var    serializedActual = SerializeVisualTree(actual);
            string baselineFilePath = fixture.GetSourcePath(testFileName);

            if (_regenerateBaselineFiles)
            {
                TestFiles.UpdateBaseline(baselineFilePath, serializedActual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFilePath, serializedActual);
            }
        }
Beispiel #8
0
        public static void OutlineFile(IServiceContainer services, EditorTestFilesFixture fixture, string name)
        {
            var testFile     = fixture.GetDestinationPath(name);
            var baselineFile = testFile + ".outline";
            var text         = fixture.LoadDestinationFile(name);

            var rc     = BuildOutlineRegions(services, text);
            var actual = TextRangeCollectionWriter.WriteCollection(rc);

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(fixture.SourcePath, Path.GetFileName(testFile)) + ".outline";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #9
0
        public static void OutlineFile(IEditorShell editorShell, EditorTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".outline";
            string text         = fixture.LoadDestinationFile(name);

            OutlineRegionCollection rc = BuildOutlineRegions(editorShell, text);
            string actual = TextRangeCollectionWriter.WriteCollection(rc);

            if (_regenerateBaselineFiles)
            {
                baselineFile = Path.Combine(fixture.SourcePath, Path.GetFileName(testFile)) + ".outline";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #10
0
        public async Task PreviewAutomatic(string sourceFile)
        {
            _settings.AutomaticSync = true;
            var content      = _files.LoadDestinationFile(sourceFile);
            var baselinePath = Path.Combine(_files.DestinationPath, sourceFile) + ".html";

            using (var script = await _editorHost.StartScript(_services, content, sourceFile, MdContentTypeDefinition.ContentType, _sessionProvider)) {
                script.DoIdle(500);
                var margin  = script.View.Properties.GetProperty <PreviewMargin>(typeof(PreviewMargin));
                var control = margin?.Browser?.Control;
                control.Should().NotBeNull();

                await _services.MainThread().SwitchToAsync();

                var htmlDoc = (HTMLDocument)control.Document;
                var actual  = htmlDoc.documentElement.outerHTML.Replace("\n", "\r\n");
                TestFiles.CompareToBaseLine(baselinePath, actual);
            }
        }
Beispiel #11
0
        private static void FormatFileImplementation(CoreTestFilesFixture fixture, string name, RFormatOptions options)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".formatted";
            string text         = fixture.LoadDestinationFile(name);

            RFormatter formatter = new RFormatter(options);

            string actual = formatter.Format(text);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, @"Formatting\", Path.GetFileName(testFile)) + ".formatted";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #12
0
        private static void ParseFileImplementation(CoreTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tree";
            string text         = fixture.LoadDestinationFile(name);

            AstRoot actualTree = RParser.Parse(text);

            AstWriter astWriter = new AstWriter();
            string    actual    = astWriter.WriteTree(actualTree);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, name) + ".tree";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #13
0
        public static void OutlineFile(EditorTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".outline";
            string text         = fixture.LoadDestinationFile(name);

            OutlineRegionCollection rc = BuildOutlineRegions(text);
            string actual = TextRangeCollectionWriter.WriteCollection(rc);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                string enlistmentPath = @"F:\RTVS\src\R\Editor\Test\Files";
                baselineFile = Path.Combine(enlistmentPath, Path.GetFileName(testFile)) + ".outline";

                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #14
0
        public static void TokenizeFileImplementation(CoreTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tokens";
            string text         = fixture.LoadDestinationFile(name);

            ITextProvider textProvider = new TextStream(text);
            var           tokenizer    = new RTokenizer();

            var    tokens = tokenizer.Tokenize(textProvider, 0, textProvider.Length);
            string actual = DebugWriter.WriteTokens <RToken, RTokenType>(tokens);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, @"Tokenization\", Path.GetFileName(testFile)) + ".tokens";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #15
0
        static public void BuildTree(HtmlTestFilesFixture fixture, string name)
        {
            string testFile     = fixture.GetDestinationPath(name);
            string baselineFile = testFile + ".tree";
            string text         = fixture.LoadDestinationFile(name);

            var tree = new HtmlTree(new TextStream(text), null, null, ParsingMode.Html);

            tree.Build();

            TreeWriter tw     = new TreeWriter();
            string     actual = tw.WriteTree(tree);

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, name) + ".tree";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }
Beispiel #16
0
        static public void ParseText(HtmlTestFilesFixture fixture, string name)
        {
            string      testFile     = fixture.GetDestinationPath(name);
            string      baselineFile = testFile + ".log";
            string      text         = fixture.LoadDestinationFile(name);
            EventLogger logger       = null;

            HtmlParser p = new HtmlParser();

            logger = new EventLogger(p);
            p.Parse(text);
            var actual = logger.ToString();

            if (_regenerateBaselineFiles)
            {
                // Update this to your actual enlistment if you need to update baseline
                baselineFile = Path.Combine(fixture.SourcePath, name) + ".log";
                TestFiles.UpdateBaseline(baselineFile, actual);
            }
            else
            {
                TestFiles.CompareToBaseLine(baselineFile, actual);
            }
        }