public void TestBuildMetadataOnly() { SemverVersionTestHelper.AssertVersionsEqual( 1, 0, 0, null, "20130313144700", SemverVersion.Parse("1.0.0+20130313144700")); }
public void TestPreReleaseHyphenatedIdentifier() { SemverVersionTestHelper.AssertVersionsEqual( 1, 2, 3, "alpha-2.1", null, SemverVersion.Parse("1.2.3-alpha-2.1")); }
public void TestBasicMajorMinorPatchVersion() { SemverVersionTestHelper.AssertVersionsEqual( 1, 2, 3, null, null, SemverVersion.Parse("1.2.3")); }
private IEnumerable <SemverVersion> GetVersions(JToken versionsToken) { IEnumerable <string> versionStrings = versionsToken.OfType <JProperty>().Select(v => (string)v.Name); foreach (var versionString in versionStrings) { if (!string.IsNullOrEmpty(versionString)) { yield return(SemverVersion.Parse(versionString)); } } }
public void TestPreReleaseAndBuildMetadata() { // 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85 SemverVersionTestHelper.AssertVersionsEqual(1, 0, 0, "alpha", "001", SemverVersion.Parse("1.0.0-alpha+001")); SemverVersionTestHelper.AssertVersionsEqual( 1, 0, 0, "beta", "exp.sha.5114f85", SemverVersion.Parse("1.0.0-beta+exp.sha.5114f85")); }
public void TestPreReleaseHyphenatedIdentifierWithoutVersion() { // This version code is crazy, and for that reason it fail when // regional settings is set to Turkish. SemverVersionTestHelper.AssertVersionsEqual( 0, 1, 4, "DEPRECATED-USE-cfenv-INSTEAD", null, SemverVersion.Parse("0.1.4-DEPRECATED-USE-cfenv-INSTEAD")); }
public void CheckDatabaseUpdateArray() { string cachePath = "NpmCacheUpdate"; string registryPath = Path.Combine(cachePath, "registry", NpmGetCatalogCommand.RegistryCacheFilename); FileUtils.CopyDirectory(PackageCacheDirectory, cachePath); using (var reader = GetCatalogueReader(PackageCacheSinceJsonArrayFilename)) { new NpmGetCatalogCommand(string.Empty, cachePath, false).ParseResultsAndAddToDatabase(reader, registryPath, RegistryUrl); } IDictionary <string, IPackage> byName; var target = GetTestPackageList(cachePath, out byName); Assert.AreEqual(90066, target.Count); // Package updated successfully CheckPackage( target, byName, 13986, "cordova", "Cordova command line interface tool", "Anis Kadri", "10/16/2014 18:05:13", SemverVersion.Parse("4.0.0"), new[] { SemverVersion.Parse("4.0.0"), SemverVersion.Parse("3.6.0-0.2.8"), }, new[] { "cordova", "client", "cli" } ); // Package added successfully CheckPackage( target, byName, 253, "9e-sass-lint", "Makes sure you stick to our CSS rule order http://9elements.com/css-rule-order/", "Sascha Gehlich", "08/19/2015 08:21:25", SemverVersion.Parse("0.0.12"), new[] { SemverVersion.Parse("0.0.12") }, new[] { "sass", "css", "lint", "rules" } ); }
public void CheckDatabaseUpdate() { string cachePath = "NpmCacheUpdate"; string registryPath = Path.Combine(cachePath, "registry", NpmGetCatalogCommand.RegistryCacheFilename); FileUtils.CopyDirectory(PackageCacheDirectory, cachePath); using (var reader = GetCatalogueReader(PackageCacheSinceJsonFilename)) { new NpmGetCatalogCommand(string.Empty, cachePath, false).ParseResultsAndAddToDatabase(reader, registryPath, RegistryUrl); } IDictionary <string, IPackage> byName; var target = GetTestPackageList(cachePath, out byName); Assert.AreEqual(89978, target.Count); // Package updated successfully CheckPackage( target, byName, 13898, "cordova", "Cordova command line interface tool", "Anis Kadri", "10/16/2014 18:05:13", SemverVersion.Parse("4.0.0"), new[] { SemverVersion.Parse("4.0.0"), SemverVersion.Parse("3.6.0-0.2.8"), }, new[] { "cordova", "client", "cli" } ); // Package added successfully CheckPackage( target, byName, 54151, "mytestpackage98", null, null, "08/14/2014 19:46:24", SemverVersion.Parse("0.1.3"), new[] { SemverVersion.Parse("0.1.3") }, Enumerable.Empty <string>() ); }
private IPackage ReadPackage(JToken package, NodeModuleBuilder builder) { builder.Reset(); try { builder.Name = (string)package["name"]; if (string.IsNullOrEmpty(builder.Name)) { // I don't believe this should ever happen if the data returned is // well formed. Could throw an exception, but just skip instead for // resiliency on the NTVS side. return(null); } builder.AppendToDescription((string)package["description"] ?? string.Empty); var date = package["date"]; if (date != null) { builder.SetDate((string)date); } var version = package["version"]; if (version != null) { var semver = SemverVersion.Parse((string)version); builder.AddVersion(semver); } AddKeywords(builder, package["keywords"]); AddAuthor(builder, package["author"]); AddHomepage(builder, package["links"]); return(builder.Build()); } catch (InvalidOperationException) { // Occurs if a JValue appears where we expect JProperty return(null); } catch (ArgumentException) { return(null); } }
private IEnumerable <SemverVersion> GetVersions(JToken versionsToken) { var versionStrings = versionsToken.OfType <JProperty>().Select(v => (string)v.Name); foreach (var versionString in versionStrings) { if (!string.IsNullOrEmpty(versionString)) { SemverVersion ver; try { ver = SemverVersion.Parse(versionString); } catch (SemverVersionFormatException) { continue; } yield return(ver); } } }
private void CheckSensibleNumberOfNonZeroVersions(ICollection <IPackage> target) { int sensibleVersionCount = 0; var zero = SemverVersion.Parse("0.0.0"); foreach (var package in target) { if (package.Version != zero) { ++sensibleVersionCount; } } // Let's say (it'll be much higher) but at least 25% of packages must have a sensible version number Assert.IsTrue( sensibleVersionCount > target.Count / 4, string.Format("There are only {0} packages with version numbers other than {1}", sensibleVersionCount, zero)); }
public void CheckPackageEqualsInDescription() { IDictionary <string, IPackage> byName; var target = GetTestPackageList(PackageCacheDirectory, out byName); CheckPackage( target, byName, 62060, "particularizable", "particularizable ================ `enumerable` was taken.", "ELLIOTTCABLE", "06/11/2013 22:48:35", SemverVersion.Parse("1.0.0"), new[] { SemverVersion.Parse("1.0.0") }, Enumerable.Empty <string>()); }
public void CheckPackageNoDescription() { IDictionary <string, IPackage> byName; var target = GetTestPackageList(PackageCacheDirectory, out byName); CheckPackage( target, byName, 455, "active-client", null, "Subbu Allamaraju", "01/03/2011 21:21:12", SemverVersion.Parse("0.1.1"), new[] { SemverVersion.Parse("0.1.1") }, Enumerable.Empty <string>()); }
public void CheckDatabaseCreation() { string databaseFilename = NpmGetCatalogCommand.DatabaseCacheFilename; string registryFilename = NpmGetCatalogCommand.RegistryCacheFilename; string cachePath = "CachePath"; string registryDirectory = "registry"; Uri registryUrl = new Uri(RegistryUrl); string catalogDatabaseFilename = Path.Combine(cachePath, databaseFilename); string registryDatabaseFilename = Path.Combine(cachePath, registryDirectory, registryFilename); string relativeRegistryDatabaseFilename = Path.Combine(registryDirectory, registryFilename); using (var reader = GetCatalogueReader(PackageCacheAllJsonFilename)) { var getCatalogCommand = new NpmGetCatalogCommand(string.Empty, cachePath, false, RegistryUrl); getCatalogCommand.CreateCatalogDatabaseAndInsertEntries(catalogDatabaseFilename, registryUrl, registryDirectory); new NpmGetCatalogCommand(string.Empty, cachePath, false).ParseResultsAndAddToDatabase(reader, registryDatabaseFilename, registryUrl.ToString()); } IDictionary <string, IPackage> byName; var target = GetTestPackageList(cachePath, out byName); Assert.AreEqual(102, target.Count); CheckPackage( target, byName, 93, "cordova", "Cordova command line interface tool", "Anis Kadri", "07/08/2014 17:55:34", SemverVersion.Parse("3.5.0-0.2.6"), new[] { SemverVersion.Parse("3.5.0-0.2.6"), SemverVersion.Parse("3.5.0-0.2.4") }, new[] { "cordova", "client", "cli" } ); }
public void CheckPackageWithBuildPreReleaseInfo() { IDictionary <string, IPackage> byName; var target = GetTestPackageList(PackageCacheDirectory, out byName); CheckPackage( target, byName, 65900, "psc-cms-js", "js library for Psc CMS (pscheit/psc-cms). shim reposistory for builds.", "Philipp Scheit", "01/07/2014 10:57:58", SemverVersion.Parse("1.3.0-517056d"), new[] { SemverVersion.Parse("1.3.0-95847e2"), SemverVersion.Parse("1.3.0-517056d"), SemverVersion.Parse("1.4.0-e14fdf0") }, new[] { "cms", "framework" }); }
public void TestAlphaPreRelease() { SemverVersionTestHelper.AssertVersionsEqual(1, 2, 3, "alpha", null, SemverVersion.Parse("1.2.3-alpha")); }
public void TestNegativeMajorVersionFails() { SemverVersion.Parse("-1.2.3"); }
private IPackage ReadPackage(JsonTextReader jsonReader, NodeModuleBuilder builder) { IPackage package = null; builder.Reset(); try { // The JsonTextReader should be positioned at the start of the // object literal token for the package var module = JToken.ReadFrom(jsonReader); builder.Name = (string)module["name"]; if (string.IsNullOrEmpty(builder.Name)) { // I don't believe this should ever happen if the data returned is // well formed. Could throw an exception, but just skip instead for // resiliency on the NTVS side. return(null); } builder.AppendToDescription((string)module["description"] ?? string.Empty); var time = module["time"]; if (time != null) { builder.AppendToDate((string)time["modified"]); } var distTags = module["dist-tags"]; if (distTags != null) { var latestVersion = distTags .OfType <JProperty>() .Where(v => (string)v.Name == "latest") .Select(v => (string)v.Value) .FirstOrDefault(); if (!string.IsNullOrEmpty(latestVersion)) { try { builder.LatestVersion = SemverVersion.Parse(latestVersion); } catch (SemverVersionFormatException) { OnOutputLogged(String.Format( Resources.InvalidPackageSemVersion, latestVersion, builder.Name)); } } } var versions = module["versions"]; if (versions != null) { builder.AvailableVersions = GetVersions(versions); } AddKeywords(builder, module["keywords"]); AddAuthor(builder, module["author"]); AddHomepage(builder, module["homepage"]); package = builder.Build(); } catch (InvalidOperationException) { // Occurs if a JValue appears where we expect JProperty return(null); } catch (ArgumentException) { OnOutputLogged(string.Format(Resources.ParsingError, builder.Name)); return(null); } return(package); }
private static void CheckPackage(IPackageJson pkg) { Assert.IsNotNull(pkg, "Package should not be null."); Assert.AreEqual("TestPkg", pkg.Name, "Package name mismatch."); Assert.AreEqual(SemverVersion.Parse("0.1.0"), pkg.Version, "Package version mismatch."); }
public void TestNegativeMinorVersionFails() { SemverVersion.Parse("1.-2.3"); }
public void TestNegativePatchVersionFails() { SemverVersion.Parse("1.2.-3"); }
public void TestNonNumericMajorVersionFails() { SemverVersion.Parse("a.2.3"); }
public void TestNonNumericMinorVersionFails() { SemverVersion.Parse("1.b.3"); }
internal void ParseResultsAndAddToDatabase(TextReader reader, string dbFilename, string registryUrl) { Directory.CreateDirectory(Path.GetDirectoryName(dbFilename)); using (var db = new SQLiteConnection(dbFilename)) { db.RunInTransaction(() => { db.CreateRegistryTableIfNotExists(); using (var jsonReader = new JsonTextReader(reader)) { while (jsonReader.Read()) { if (JsonToken.PropertyName != jsonReader.TokenType) { continue; } if ((string)jsonReader.Value == "_updated") { jsonReader.Read(); db.InsertOrReplace(new RegistryInfo() { RegistryUrl = registryUrl, Revision = (long)jsonReader.Value, UpdatedOn = DateTime.Now }); continue; } var builder = new NodeModuleBuilder(); JToken token = null; #if DEV14_OR_LATER try { #endif token = JToken.ReadFrom(jsonReader); #if DEV14_OR_LATER } catch (JsonReaderException) { // Reached end of file, so continue. break; } #endif var module = token.FirstOrDefault(); while (module != null) { try { builder.Name = (string)module["name"]; if (string.IsNullOrEmpty(builder.Name)) { continue; } builder.AppendToDescription((string)module["description"] ?? string.Empty); var time = module["time"]; if (time != null) { builder.AppendToDate((string)time["modified"]); } var distTags = module["dist-tags"]; if (distTags != null) { var latestVersion = distTags .OfType <JProperty>() .Where(v => (string)v.Name == "latest") .Select(v => (string)v.Value) .FirstOrDefault(); if (!string.IsNullOrEmpty(latestVersion)) { try { builder.LatestVersion = SemverVersion.Parse(latestVersion); } catch (SemverVersionFormatException) { OnOutputLogged(String.Format(Resources.InvalidPackageSemVersion, latestVersion, builder.Name)); } } } var versions = module["versions"]; if (versions != null) { builder.AvailableVersions = GetVersions(versions); } AddKeywords(builder, module["keywords"]); AddAuthor(builder, module["author"]); AddHomepage(builder, module["homepage"]); var package = builder.Build(); InsertCatalogEntry(db, package); } catch (InvalidOperationException) { // Occurs if a JValue appears where we expect JProperty } catch (ArgumentException) { OnOutputLogged(string.Format(Resources.ParsingError, builder.Name)); if (!string.IsNullOrEmpty(builder.Name)) { var package = builder.Build(); InsertCatalogEntry(db, package); } } builder.Reset(); #if DEV14_OR_LATER try { #endif token = JToken.ReadFrom(jsonReader); #if DEV14_OR_LATER } catch (JsonReaderException) { // Reached end of file, so continue. break; } #endif module = token.FirstOrDefault(); } } } // FTS doesn't support INSERT OR REPLACE. This is the most efficient way to bypass that limitation. db.Execute("DELETE FROM CatalogEntry WHERE docid NOT IN (SELECT MAX(docid) FROM CatalogEntry GROUP BY Name)"); }); } }
public void TestNonNumericPatchVersionFails() { SemverVersion.Parse("1.2.c"); }
public void TestNumericPreRelease() { SemverVersionTestHelper.AssertVersionsEqual(1, 2, 3, "4.5.6", null, SemverVersion.Parse("1.2.3-4.5.6")); }