Ejemplo n.º 1
0
        public void GrammarCanParseHyphenRange()
        {
            ComparatorSet <Composer> cs = Composer.Grammar.HyphenRange.Parse("11.3 - 20");

            Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(cs[0].Version, new Composer(11, 3));
            Assert.Equal(cs[1].Operator, ExpressionType.LessThanOrEqual);
            Assert.Equal(cs[1].Version, new Composer(20));
        }
Ejemplo n.º 2
0
        public void GrammarCanParseTildeRange()
        {
            ComparatorSet <Composer> cs = Composer.Grammar.TildeRange.Parse("~4.8");

            //Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            //Assert.Equal(cs[0].Version, new Composer(11, 3));
            //Assert.Equal(cs[1].Operator, ExpressionType.LessThanOrEqual);
            //Assert.Equal(cs[1].Version, new Composer(20));
        }
Ejemplo n.º 3
0
        public void GrammarCanParseTildeRangeExpression()
        {
            ComparatorSet <SemanticVersion> tr1 = SemanticVersion.Grammar.MajorTildeRange.Parse("~4");
            ComparatorSet <SemanticVersion> tr2 = SemanticVersion.Grammar.MajorTildeRange.Parse("~14.4");
            ComparatorSet <SemanticVersion> tr3 = SemanticVersion.Grammar.MajorTildeRange.Parse("~7.0.1");

            Assert.NotNull(tr1);
            Assert.NotNull(tr2);
            Assert.NotNull(tr3);
        }
Ejemplo n.º 4
0
        public void CanParseTildeRangeExpression()
        {
            ComparatorSet tr1 = Grammar.MajorTildeRange.Parse("~4");
            ComparatorSet tr2 = Grammar.MajorTildeRange.Parse("~14.4");
            ComparatorSet tr3 = Grammar.MajorTildeRange.Parse("~7.0.1");

            Assert.NotNull(tr1);
            Assert.NotNull(tr2);
            Assert.NotNull(tr3);
        }
Ejemplo n.º 5
0
        public void GrammarCanParseTwoSidedIntervalRange()
        {
            ComparatorSet <Composer> cs = Composer.Grammar.TwoSidedIntervalRange.Parse(">= 2.0.0 < 2.4.8");

            Assert.Equal(cs.Count, 2);
            Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(cs[0].Version, new Composer(2));
            Assert.Equal(cs[1].Operator, ExpressionType.LessThan);
            Assert.Equal(cs[1].Version, new Composer(2, 4, 8));
        }
Ejemplo n.º 6
0
        public void GrammarCanParseOpenBracketsOpenBrackets()
        {
            ComparatorSet <NuGetv2> cs = NuGetv2.Grammar.OpenBracketOpenBracketRange.Parse("(2.0, 3.1.0)");

            Assert.Equal(2, cs.Count);
            Assert.Equal(ExpressionType.GreaterThan, cs[0].Operator);
            Assert.Equal(ExpressionType.LessThan, cs[1].Operator);
            cs = NuGetv2.Grammar.OpenBracketOpenBracketRange.Parse("(, 3.1)");
            Assert.Equal(2, cs.Count);
            Assert.Equal(ExpressionType.GreaterThan, cs[0].Operator);
        }
Ejemplo n.º 7
0
        public void GrammarCanParseOpenBracketsClosedBrackets()
        {
            ComparatorSet <NuGetv2> cs = NuGetv2.Grammar.OpenBracketClosedBracketRange.Parse("(2.3, 3.3.0-beta6]");

            Assert.Equal(cs.Count, 2);
            Assert.Equal(ExpressionType.GreaterThan, cs[0].Operator);
            Assert.Equal(ExpressionType.LessThanOrEqual, cs[1].Operator);
            cs = NuGetv2.Grammar.OpenBracketClosedBracketRange.Parse("(, 3.1]");
            Assert.Equal(2, cs.Count);
            Assert.Equal(ExpressionType.LessThanOrEqual, cs[1].Operator);
        }
Ejemplo n.º 8
0
        public void TwoSidedRangeIntersect()
        {
            ComparatorSet <Composer> r1 = Composer.Grammar.TwoSidedIntervalRange.Parse(">= 2.0.0 < 2.4.8");
            ComparatorSet <Composer> r2 = Composer.Grammar.TwoSidedIntervalRange.Parse(">= 2.3 < 4.4.8-alpha1");
            ComparatorSet <Composer> r3 = Composer.Grammar.CaretRange.Parse("^3.0");
            ComparatorSet <Composer> r4 = Composer.Grammar.TildeRange.Parse("~5");

            Assert.True(Range <Composer> .Intersect(r1, r2));
            Assert.False(Range <Composer> .Intersect(r1, r3));
            Assert.False(Range <Composer> .Intersect(r1, r4));
            Assert.False(Range <Composer> .Intersect(r3, r4));
        }
Ejemplo n.º 9
0
        public void GrammarCanParseTwoSidedIntervalRange()
        {
            ComparatorSet <Drupal> cs = Drupal.Grammar.TwoSidedIntervalRange.Parse(">=7.x-3.x & <7.x-3.8");

            Assert.Equal(cs[0].Version, new Drupal(7, 3, 0, 0));
            Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(cs[1].Version, new Drupal(7, 3, 0, 8));
            Assert.Equal(cs[1].Operator, ExpressionType.LessThan);
            ComparatorSet <Drupal> csb = Drupal.Grammar.BracketedTwoSidedIntervalRange.Parse("(>=7.x-3.x & <7.x-3.8)");

            Assert.Equal(cs[0].Version, csb[0].Version);
        }
Ejemplo n.º 10
0
        public void GrammarCanParseXRange()
        {
            ComparatorSet <Composer> cs = Composer.Grammar.XRange.Parse("1.*");

            Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(cs[0].Version, new Composer(1));
            Assert.Equal(cs[1].Operator, ExpressionType.LessThan);
            Assert.Equal(cs[1].Version, new Composer(2));
            cs = Composer.Grammar.XRange.Parse("1.4.*");
            Assert.Equal(cs[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(cs[0].Version, new Composer(1, 4, 0));
            Assert.Equal(cs[1].Operator, ExpressionType.LessThan);
            Assert.Equal(cs[1].Version, new Composer(1, 5, 0));
        }
Ejemplo n.º 11
0
        public void GrammarCanParseXRangeExpression()
        {
            ComparatorSet <SemanticVersion> xr1 = SemanticVersion.Grammar.MajorXRange.Parse("4.x");

            Assert.NotNull(xr1);
            Assert.Equal(xr1[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Equal(xr1[0].Version, new SemanticVersion(4));
            Assert.Equal(xr1[1].Operator, ExpressionType.LessThan);
            Assert.Equal(xr1[1].Version, new SemanticVersion(5));
            ComparatorSet <SemanticVersion> xr2 = SemanticVersion.Grammar.MajorMinorXRange.Parse("4.3.x");

            Assert.NotNull(xr1);
            Assert.Equal(xr1[0].Operator, ExpressionType.GreaterThanOrEqual);
            Assert.Throws(typeof(Sprache.ParseException), () => SemanticVersion.Grammar.MajorXRange.Parse("*"));
            Assert.Throws(typeof(Sprache.ParseException), () => SemanticVersion.Grammar.MajorXRange.Parse("4.3.x"));
        }
Ejemplo n.º 12
0
        public void GrammarCanParseOneSidedRange()
        {
            Comparator <Composer> re = Composer.Grammar.OneSidedRange.Parse("<10.3.4").Last();

            Assert.Equal(ExpressionType.LessThan, re.Operator);
            Assert.Equal(10, re.Version.Major);
            Assert.Equal(3, re.Version.Minor);
            Assert.Equal(4, re.Version.Patch);
            re = Composer.Grammar.OneSidedRange.Parse("<=0.0.4-alpha").Last();
            Assert.Equal(ExpressionType.LessThanOrEqual, re.Operator);
            Assert.Equal(0, re.Version.Major);
            Assert.Equal(4, re.Version.Patch);
            Assert.Equal("alpha", re.Version.PreRelease.ToString());
            ComparatorSet <Composer> r = Composer.Grammar.OneSidedRange.Parse(">1.13.4-beta7");

            Assert.Equal(r.Count, 2);
            Assert.Equal(r[0].Operator, ExpressionType.LessThan);
            Assert.Equal(r[0].Version, new Composer().Max());
        }
Ejemplo n.º 13
0
        public void CanIntervalIntersect()
        {
            ComparatorSet <NuGetv2> cs1 = NuGetv2.Grammar.OpenBracketOpenBracketRange.Parse("(3.2, 5.3.1)");
            ComparatorSet <NuGetv2> cs2 = NuGetv2.Grammar.OpenBracketOpenBracketRange.Parse("(4.2.1, 5.6.1)");
            Interval <NuGetv2>      i1  = cs1.ToInterval();
            Interval <NuGetv2>      i2  = cs2.ToInterval();

            Assert.True(i1.Intersect(i1));
            Assert.True(i1.Intersect(i2));
            Interval <NuGetv2> i3 = NuGetv2.Grammar.OneOrTwoSidedRange.Parse("[3.2, 5.3.1)").ToInterval();

            Assert.True(i1.Intersect(i3));
            i3 = NuGetv2.Grammar.OneOrTwoSidedRange.Parse("(3.2, 5.3.1)").ToInterval();
            Assert.True(i1.Intersect(i3));
            Interval <NuGetv2> i4 = NuGetv2.Grammar.OneOrTwoSidedRange.Parse("( , 5.3.1]").ToInterval();

            Assert.True(i2.Intersect(i4));
            Assert.False(i1.Intersect(NuGetv2.Grammar.OneOrTwoSidedRange.Parse("(5.3.1, 6.3.1)").ToInterval()));
            Assert.True(i4.Intersect(NuGetv2.Grammar.OneOrTwoSidedRange.Parse("[5.3.1, )").ToInterval()));
            Assert.False(i4.Intersect(NuGetv2.Grammar.OneOrTwoSidedRange.Parse("(5.3.1, )").ToInterval()));
            Assert.True(i2.Intersect(NuGetv2.Grammar.OneOrTwoSidedRange.Parse("(5.3.1, )").ToInterval()));
        }
Ejemplo n.º 14
0
 public void GrammarCanParseTwoSidedIntervalRange()
 {
     ComparatorSet <SemanticVersion> cs = SemanticVersion.Grammar.TwoSidedIntervalRange.Parse("<3 >=5");
 }
Ejemplo n.º 15
0
 public static bool Satisfies(SemanticVersion v, ComparatorSet s)
 {
     return InvokeBinaryExpression(GetBinaryExpression(v, s));
 }
Ejemplo n.º 16
0
 public static BinaryExpression GetBinaryExpression(SemanticVersion left, ComparatorSet right)
 {
     if (right.Count() == 0)
     {
         return GetBinaryExpression(ExpressionType.Equal, left, left);
     }
     else
     {
         BinaryExpression c = null;
         foreach (Comparator r in right)
         {
             if (c == null)
             {
                 c = GetBinaryExpression(r.Operator, left, r.Version);
             }
             else
             {
                 c = Expression.AndAlso(c, GetBinaryExpression(r.Operator, left, r.Version));
             }
         }
         return c;
     }
 }