public void DetectSqlDialects(Language language) { var testFolder = Path.Combine(TestUtility.GrammarsDirectory, language.ToString().ToLowerInvariant(), "examples"); var directoryCodeRepository = new DirectorySourceRepository(testFolder); var fileNames = directoryCodeRepository.GetFileNames(); int totalFilesCount = 0; int ambiguousFilesCount = 0; foreach (var fileName in fileNames) { TextFile textFile = new TextFile(File.ReadAllText(fileName), fileName); List <Language> sqls = SqlDialectDetector.Detect(textFile); if (sqls.Count > 1) { Console.WriteLine($"{fileName} has been recognized as {string.Join(", ", sqls)}"); ambiguousFilesCount++; } totalFilesCount++; CollectionAssert.Contains(sqls, language, $"File {fileName} has not been detected as {language}"); } Console.WriteLine($"Ambiguous files count: {ambiguousFilesCount}"); Console.WriteLine($"Total files count: {totalFilesCount}"); }
public static SourceRepository CreateSourceRepository(string path, string tempDir, CliParameters parameters) { SourceRepository sourceRepository; if (string.IsNullOrWhiteSpace(path)) { sourceRepository = DummySourceRepository.Instance; } else if (DirectoryExt.Exists(path)) { sourceRepository = new DirectorySourceRepository(path); } else if (FileExt.Exists(path)) { string extension = Path.GetExtension(path); if (extension.EqualsIgnoreCase(".zip")) { var zipCachingRepository = new ZipCachingRepository(path); if (tempDir != null) { zipCachingRepository.ExtractPath = tempDir; } sourceRepository = zipCachingRepository; } else { sourceRepository = new FileSourceRepository(path); } } else { string url = path; string projectName = null; string urlWithoutHttp = TextUtils.HttpRegex.Replace(url, ""); if (!url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { if (urlWithoutHttp.StartsWith("github.com", StringComparison.OrdinalIgnoreCase)) { url = url + "/archive/master.zip"; } } if (urlWithoutHttp.StartsWith("github.com", StringComparison.OrdinalIgnoreCase)) { projectName = urlWithoutHttp.Split('/').ElementAtOrDefault(2); } var zipAtUrlCachedCodeRepository = new ZipAtUrlCachingRepository(url, projectName); if (tempDir != null) { zipAtUrlCachedCodeRepository.DownloadPath = tempDir; } sourceRepository = zipAtUrlCachedCodeRepository; } return(sourceRepository); }
public void AggregateFiles_TestProject_CorrectCountAndRelativePaths() { string rootPath = Path.Combine(TestUtility.TestsDataPath, "Test Project"); var repository = new DirectorySourceRepository(rootPath, languages: Language.CSharp); var fileNames = repository.GetFileNames().Select(fileName => repository.ReadFile(fileName)).ToArray(); Assert.AreEqual(7, fileNames.Length); Assert.IsNotNull(fileNames.SingleOrDefault(f => f.Name == "1.cs" && f.RelativePath == "" && f.FullName == Path.Combine(rootPath, "1.cs"))); Assert.IsNotNull(fileNames.SingleOrDefault(f => f.Name == "1.cs" && f.RelativePath == "Folder" && f.FullName == Path.Combine(rootPath, "Folder", "1.cs"))); }
public void Check_AspxFileWithCSharpLanguage_NotIgnored() { var repository = new DirectorySourceRepository("", Language.CSharp); CollectionAssert.IsNotEmpty(repository.GetLanguages("page.aspx", true)); }