Merge branch 'master' into bug/deserialize-nulls

This commit is contained in:
Carl de Billy 2020-01-06 11:05:29 -05:00 коммит произвёл GitHub
Родитель a7cbed0e4e 171ce749a8
Коммит 11f544f49d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 116 добавлений и 16 удалений

Просмотреть файл

@ -7,6 +7,8 @@ phases:
- powershell: './build/build.ps1 -script build/build.cake' - powershell: './build/build.ps1 -script build/build.cake'
- task: VSTest@2
- task: CopyFiles@2 - task: CopyFiles@2
inputs: inputs:
SourceFolder: $(Build.SourcesDirectory)/build SourceFolder: $(Build.SourcesDirectory)/build

Просмотреть файл

@ -22,4 +22,10 @@ namespace Uno.CodeGen.Tests.ExternalClasses
[EqualityHash] [EqualityHash]
public string Id { get; } public string Id { get; }
} }
[GeneratedImmutable]
public partial class ConcreteExternalClassNoHash
{
public string Id { get; }
}
} }

Просмотреть файл

@ -0,0 +1,83 @@
// ******************************************************************
// Copyright <20> 2015-2018 nventive inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ******************************************************************
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Uno.Equality;
namespace Uno.CodeGen.Tests
{
public partial class Given_GeneratedEquality
{
[TestMethod]
public void Equality_WhenUsingDifferentDerivedTypes()
{
var d1 = new MyDerived1.Builder { a = 10, b = 15, }.ToImmutable();
var d2 = new MyDerived2.Builder { a = 10, c = 25, }.ToImmutable();
var d3 = new MyDerived3.Builder { a = 10, b = 15, c=25 }.ToImmutable();
(d1 == d2).Should().BeFalse("d1 == d2");
(d2 == d1).Should().BeFalse("d2 == d1");
(d1 != d2).Should().BeTrue("d1 != d2");
(d2 != d1).Should().BeTrue("d2 != d1");
d1.Should().NotBe(d2, "d1.Equals(d2)");
d2.Should().NotBe(d1, "d2.Equals(d1)");
(d1 == d3).Should().BeFalse("d1 == d3");
(d3 == d1).Should().BeFalse("d3 == d1");
(d1 != d3).Should().BeTrue("d1 == d3");
(d3 != d1).Should().BeTrue("d3 == d1");
d1.Should().NotBe(d3, "d1.Equals(d3)");
d3.Should().NotBe(d1, "d3.Equals(d1)");
}
[TestMethod]
public void Equality_WhenUsingDerivedFromExternal()
{
var d1 = new MyADerived.Builder { Id = "d1", a = 15, }.ToImmutable();
var d2 = new MyADerived.Builder { Id = "d2", a = 15, }.ToImmutable();
(d1 == d2).Should().BeFalse("d1 == d2");
(d2 == d1).Should().BeFalse("d2 == d1");
(d1 != d2).Should().BeTrue("d1 != d2");
(d2 != d1).Should().BeTrue("d2 != d1");
d1.Should().NotBe(d2, "d1.Equals(d2)");
d2.Should().NotBe(d1, "d2.Equals(d1)");
}
}
[GeneratedImmutable]
internal partial class MyBase
{
public int a { get; }
}
internal partial class MyDerived1 : MyBase
{
public int b { get; }
}
internal partial class MyDerived2 : MyBase
{
public int c { get; }
}
internal partial class MyDerived3 : MyDerived1
{
public int c { get; }
}
internal partial class MyADerived : Uno.CodeGen.Tests.ExternalClasses.ConcreteExternalClassNoHash
{
public int a { get; }
}
}

Просмотреть файл

@ -99,28 +99,36 @@ namespace Uno
private string _currentType = "unknown"; private string _currentType = "unknown";
private INamedTypeSymbol GetMandatoryTypeSymbol(string name)
{
var s = _context.Compilation.GetTypeByMetadataName(name);
if (s == null)
throw new InvalidOperationException($"Invalid type symbol '{name}'");
return s;
}
/// <inheritdoc /> /// <inheritdoc />
public override void Execute(SourceGeneratorContext context) public override void Execute(SourceGeneratorContext context)
{ {
_context = context; _context = context;
_logger = context.GetLogger(); _logger = context.GetLogger();
_objectSymbol = context.Compilation.GetTypeByMetadataName("System.Object"); _objectSymbol = GetMandatoryTypeSymbol("System.Object");
_valueTypeSymbol = context.Compilation.GetTypeByMetadataName("System.ValueType"); _valueTypeSymbol = GetMandatoryTypeSymbol("System.ValueType");
_boolSymbol = context.Compilation.GetTypeByMetadataName("System.Bool"); _boolSymbol = GetMandatoryTypeSymbol("System.Boolean");
_intSymbol = context.Compilation.GetTypeByMetadataName("System.Int32"); _intSymbol = GetMandatoryTypeSymbol("System.Int32");
_enumSymbol = context.Compilation.GetTypeByMetadataName("System.Enum"); _enumSymbol = GetMandatoryTypeSymbol("System.Enum");
_arraySymbol = context.Compilation.GetTypeByMetadataName("System.Array"); _arraySymbol = GetMandatoryTypeSymbol("System.Array");
_collectionSymbol = context.Compilation.GetTypeByMetadataName("System.Collections.ICollection"); _collectionSymbol = GetMandatoryTypeSymbol("System.Collections.ICollection");
_iEquatableSymbol = context.Compilation.GetTypeByMetadataName("System.IEquatable`1"); _iEquatableSymbol = GetMandatoryTypeSymbol("System.IEquatable`1");
_iKeyEquatableSymbol = context.Compilation.GetTypeByMetadataName("Uno.Equality.IKeyEquatable"); _iKeyEquatableSymbol = _context.Compilation.GetTypeByMetadataName("Uno.Equality.IKeyEquatable");
_iKeyEquatableGenericSymbol = context.Compilation.GetTypeByMetadataName("Uno.Equality.IKeyEquatable`1"); _iKeyEquatableGenericSymbol = _context.Compilation.GetTypeByMetadataName("Uno.Equality.IKeyEquatable`1");
_generatedEqualityAttributeSymbol = context.Compilation.GetTypeByMetadataName("Uno.GeneratedEqualityAttribute"); _generatedEqualityAttributeSymbol = GetMandatoryTypeSymbol("Uno.GeneratedEqualityAttribute");
_ignoreForEqualityAttributeSymbol = context.Compilation.GetTypeByMetadataName("Uno.EqualityIgnoreAttribute"); _ignoreForEqualityAttributeSymbol = GetMandatoryTypeSymbol("Uno.EqualityIgnoreAttribute");
_equalityHashAttributeSymbol = context.Compilation.GetTypeByMetadataName("Uno.EqualityHashAttribute"); _equalityHashAttributeSymbol = GetMandatoryTypeSymbol("Uno.EqualityHashAttribute");
_equalityKeyAttributeSymbol = context.Compilation.GetTypeByMetadataName("Uno.EqualityKeyAttribute"); _equalityKeyAttributeSymbol = GetMandatoryTypeSymbol("Uno.EqualityKeyAttribute");
_equalityComparerOptionsAttributeSymbol = context.Compilation.GetTypeByMetadataName("Uno.Equality.EqualityComparerOptionsAttribute"); _equalityComparerOptionsAttributeSymbol = GetMandatoryTypeSymbol("Uno.Equality.EqualityComparerOptionsAttribute");
_dataAnnonationsKeyAttributeSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.KeyAttribute"); _dataAnnonationsKeyAttributeSymbol = GetMandatoryTypeSymbol("System.ComponentModel.DataAnnotations.KeyAttribute");
_isPureAttributePresent = context.Compilation.GetTypeByMetadataName("System.Diagnostics.Contracts.Pure") != null; _isPureAttributePresent = context.Compilation.GetTypeByMetadataName("System.Diagnostics.Contracts.Pure") != null;
_generateKeyEqualityCode = _iKeyEquatableSymbol != null; _generateKeyEqualityCode = _iKeyEquatableSymbol != null;
@ -254,6 +262,7 @@ namespace Uno
builder.AppendLineInvariant("// private method doing the real .Equals() job"); builder.AppendLineInvariant("// private method doing the real .Equals() job");
using (builder.BlockInvariant($"private bool InnerEquals({symbolNameWithGenerics} other)")) using (builder.BlockInvariant($"private bool InnerEquals({symbolNameWithGenerics} other)"))
{ {
builder.AppendLineInvariant("if (other.GetType() != GetType()) return false;");
builder.AppendLineInvariant("if (other.GetHashCode() != GetHashCode()) return false;"); builder.AppendLineInvariant("if (other.GetHashCode() != GetHashCode()) return false;");
var baseCall = baseTypeInfo.baseOverridesEquals var baseCall = baseTypeInfo.baseOverridesEquals