Exemplo n.º 1
0
        public virtual bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
        {
            object othervalue = attr.GetValue();

            if (!othervalue.GetType().IsArray)
            {
                return(false);
            }

            IList a = value as IList;
            IList b = othervalue as IList;

            if (a.Count != b.Count)
            {
                return(false);
            }

            for (int i = 0; i < a.Count; i++)
            {
                if (!a[i].Equals(b[i]))
                {
                    if (!EqualityUtil.NumberEquals(a[i], b[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 public void Equality1()
 {
     EqualityUtil.RunAll(
         (left, right) => left == right,
         (left, right) => left != right,
         EqualityUnit.Create(new LinePosition(1, 2)).WithEqualValues(new LinePosition(1, 2)),
         EqualityUnit.Create(new LinePosition()).WithEqualValues(new LinePosition()),
         EqualityUnit.Create(new LinePosition(1, 2)).WithNotEqualValues(new LinePosition(1, 3)),
         EqualityUnit.Create(new LinePosition(1, 2)).WithNotEqualValues(new LinePosition(2, 2)));
 }
Exemplo n.º 3
0
 public void Equality()
 {
     EqualityUtil.RunAll(
         (left, right) => left == right,
         (left, right) => left != right,
         EqualityUnit.Create(new TextChangeRange()).WithEqualValues(new TextChangeRange()),
         EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithEqualValues(new TextChangeRange(new TextSpan(42, 2), 13)),
         EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithNotEqualValues(new TextChangeRange(new TextSpan(42, 2), 5)),
         EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithNotEqualValues(new TextChangeRange(new TextSpan(42, 4), 13)));
 }
Exemplo n.º 4
0
        public void Equality_ControlLetterIsCaseInsensitive()
        {
            var unit = EqualityUnit.Create(KeyInputUtil.CharWithControlToKeyInput('a'))
                       .WithEqualValues(KeyInputUtil.CharWithControlToKeyInput('A'))
                       .WithNotEqualValues(KeyInputUtil.CharToKeyInput('a'));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: unit);
        }
Exemplo n.º 5
0
 public void Equality_AlternatesAreEqual()
 {
     foreach (var pair in KeyInputUtil.AlternateKeyInputPairList)
     {
         var unit = EqualityUnit.Create(pair.Item1).WithEqualValues(pair.Item2).WithNotEqualValues(KeyInputUtil.VimKeyToKeyInput(VimKey.Colon));
         EqualityUtil.RunAll(
             (x, y) => x == y,
             (x, y) => x != y,
             values: unit);
     }
 }
Exemplo n.º 6
0
 public void Equality_Operator()
 {
     Create("cat", "dog");
     EqualityUtil.RunAll(
         (left, right) => left == right,
         (left, right) => left != right,
         false,
         false,
         EqualityUnit.Create(new CharacterSpan(_textBuffer.GetPoint(0), 1, 2))
         .WithEqualValues(new CharacterSpan(_textBuffer.GetPoint(0), 1, 2))
         .WithNotEqualValues(new CharacterSpan(_textBuffer.GetPoint(1), 1, 2)));
 }
Exemplo n.º 7
0
        public void LocalizableResourceStringEquality()
        {
            var resourceManager = GetTestResourceManagerInstance();
            var unit            = EqualityUnit
                                  .Create(
                new LocalizableResourceString(
                    @"ResourceWithArguments",
                    resourceManager,
                    typeof(CustomResourceManager),
                    "arg"
                    )
                )
                                  .WithEqualValues(
                new LocalizableResourceString(
                    @"ResourceWithArguments",
                    resourceManager,
                    typeof(CustomResourceManager),
                    "arg"
                    )
                )
                                  .WithNotEqualValues(
                new LocalizableResourceString(
                    @"ResourceWithArguments",
                    resourceManager,
                    typeof(CustomResourceManager),
                    "otherarg"
                    ),
                new LocalizableResourceString(
                    @"Resource1",
                    resourceManager,
                    typeof(CustomResourceManager)
                    )
                );

            EqualityUtil.RunAll(unit, checkIEquatable: false);

            var str = new LocalizableResourceString(
                @"ResourceWithArguments",
                resourceManager,
                typeof(CustomResourceManager),
                "arg"
                );
            var threw = false;

            str.OnException += (sender, e) =>
            {
                threw = true;
            };
            Assert.False(str.Equals(42));
            Assert.False(str.Equals(42));
            Assert.False(threw);
        }
Exemplo n.º 8
0
        public void Equals3()
        {
            var value = EqualityUnit
                        .Create(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.None))
                        .WithEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.None))
                        .WithNotEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('d'), KeyModifiers.None))
                        .WithNotEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.Shift));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: value);
        }
Exemplo n.º 9
0
            public void Guids()
            {
                var guid = Guid.NewGuid();
                var unit = EqualityUnit
                           .Create(new CommandId(guid, 42))
                           .WithEqualValues(new CommandId(guid, 42))
                           .WithNotEqualValues(new CommandId(Guid.NewGuid(), 42));

                EqualityUtil.RunAll(
                    (x, y) => x == y,
                    (x, y) => x != y,
                    unit);
            }
Exemplo n.º 10
0
        public void Equality5()
        {
            var values = EqualityUnit
                         .Create(KeyInputUtil.CharToKeyInput('c'))
                         .WithEqualValues(KeyInputUtil.CharToKeyInput('c'))
                         .WithNotEqualValues(KeyInputUtil.CharToKeyInput('d'))
                         .WithNotEqualValues(KeyInputUtil.CharWithControlToKeyInput('c'));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: values);
        }
Exemplo n.º 11
0
 public void Equality()
 {
     EqualityUtil.RunAll(
         (left, right) => left == right,
         (left, right) => left != right,
         false,
         true,
         EqualityUnit.Create(CreateOne('a')).WithEqualValues(CreateOne('a')),
         EqualityUnit.Create(CreateOne('a')).WithNotEqualValues(CreateOne('b')),
         EqualityUnit.Create(CreateOne('a')).WithEqualValues(CreateMany('a')),
         EqualityUnit.Create(CreateOne('D')).WithEqualValues(KeyNotationUtil.StringToKeyInputSet("D")),
         EqualityUnit.Create(KeyInputSet.NewOneKeyInput(KeyInputUtil.CharToKeyInput('D'))).WithEqualValues(KeyNotationUtil.StringToKeyInputSet("D")));
 }
Exemplo n.º 12
0
        public void Equality1()
        {
            var value = EqualityUnit
                        .Create(KeyBinding.Parse("::b"))
                        .WithEqualValues(KeyBinding.Parse("::b"))
                        .WithNotEqualValues(KeyBinding.Parse("local::b"))
                        .WithNotEqualValues(KeyBinding.Parse("::Shift+b"))
                        .WithNotEqualValues(KeyBinding.Parse("::Left Arrow"));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: value);
        }
Exemplo n.º 13
0
 public void Equality1()
 {
     EqualityUtil.RunAll(
         (left, right) => object.Equals(left, right),
         (left, right) => !object.Equals(left, right),
         EqualityUnit.Create(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 2), new LinePosition(3, 5)))
         .WithNotEqualValues(new FileLinePositionSpan("C:\\Goo.cs", new LinePosition(1, 2), new LinePosition(3, 5))),
         EqualityUnit.Create(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 2), new LinePosition(3, 5)))
         .WithNotEqualValues(new FileLinePositionSpan("C:\\bar.cs", new LinePosition(1, 2), new LinePosition(3, 5))),
         EqualityUnit.Create(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 2), new LinePosition(3, 5)))
         .WithNotEqualValues(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 4), new LinePosition(3, 5))),
         EqualityUnit.Create(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 2), new LinePosition(3, 5)))
         .WithNotEqualValues(new FileLinePositionSpan("C:\\goo.cs", new LinePosition(1, 2), new LinePosition(4, 5))));
 }
Exemplo n.º 14
0
            public void KeyBindings()
            {
                var id          = new CommandId(Guid.NewGuid(), 42);
                var keyBinding1 = KeyBinding.Parse("Global::Enter");
                var keyBinding2 = KeyBinding.Parse("Global::h");

                EqualityUtil.RunAll(
                    (left, right) => left == right,
                    (left, right) => left != right,
                    false,
                    false,
                    EqualityUnit.Create(new CommandKeyBinding(id, "Test", keyBinding1))
                    .WithEqualValues(new CommandKeyBinding(id, "Test", keyBinding1))
                    .WithNotEqualValues(new CommandKeyBinding(id, "Test", keyBinding2)));
            }
Exemplo n.º 15
0
            public void CommandId()
            {
                var id1        = new CommandId(Guid.NewGuid(), 42);
                var id2        = new CommandId(id1.Group, 13);
                var id3        = new CommandId(Guid.NewGuid(), 42);
                var keyBinding = KeyBinding.Parse("Global::Enter");

                EqualityUtil.RunAll(
                    (left, right) => left == right,
                    (left, right) => left != right,
                    false,
                    false,
                    EqualityUnit.Create(new CommandKeyBinding(id1, "Test", keyBinding))
                    .WithEqualValues(new CommandKeyBinding(id1, "Test", keyBinding))
                    .WithNotEqualValues(new CommandKeyBinding(id2, "Test", keyBinding))
                    .WithNotEqualValues(new CommandKeyBinding(id3, "Test", keyBinding)));
            }
Exemplo n.º 16
0
        public void Equality()
        {
            var lineMappings = new LineMapping[]
            {
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: true)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 2)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(2, 2)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 1), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(1, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("file.cs", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), 0, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 2)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 0), new LinePosition(2, 2)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(0, 1), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
                new LineMapping(new LinePositionSpan(new LinePosition(1, 0), new LinePosition(1, 1)), null, new FileLinePositionSpan("", new LinePositionSpan(new LinePosition(0, 0), new LinePosition(1, 1)), hasMappedPath: false)),
            };
            var equalityUnits = lineMappings.SelectMany((left, leftIndex) => lineMappings.Select((right, rightIndex) => CreateEqualityUnit(left, leftIndex, right, rightIndex))).ToArray();

            EqualityUtil.RunAll(
                (left, right) => left == right,
                (left, right) => left != right,
                equalityUnits);
Exemplo n.º 17
0
 public override bool Equals(object obj)
 {
     // It's slow. So in case of requiring performance, override this equality method by your code.
     return(EqualityUtil.EntityEquals(this, obj));
 }
Exemplo n.º 18
0
 public virtual bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
 {
     return(attr.GetValue().Equals(value) || EqualityUtil.NumberEquals(value as object, attr.GetValue()));
 }
Exemplo n.º 19
0
 private static void RunAll(EqualityUnit <UsedNamespaceOrType> unit)
 {
     EqualityUtil.RunAll(unit);
 }