Skip to content

Commit 3c950aa

Browse files
committed
Fix tests.
1 parent 715e3d9 commit 3c950aa

14 files changed

Lines changed: 84 additions & 101 deletions

File tree

CodeJam.Blocks.Tests/Mapping/Examples/MapMemberTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#if NET40_OR_GREATER || TARGETS_NETCOREAPP // TODO: update after fixes in Theraot.Core
22
using System;
33

4-
using JetBrains.Annotations;
5-
64
using NUnit.Framework;
75

86
#pragma warning disable 649

CodeJam.Blocks.Tests/Metadata/XmlReaderTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace CodeJam.Metadata
1212
{
1313
public class XmlReaderTests
1414
{
15-
const string Data =
15+
private const string _data =
1616
@"<?xml version='1.0' encoding='utf-8' ?>
1717
<Types>
1818
<Type Name='MyType'>
@@ -48,28 +48,25 @@ public class XmlReaderTests
4848
[Test]
4949
public void Parse()
5050
{
51-
_ = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(Data)));
51+
_ = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(_data)));
5252
}
5353

5454
[AttributeUsage(AttributeTargets.All)]
5555
public class TableAttribute : Attribute
5656
{
57-
public TableAttribute(string name) => Name = name;
58-
59-
public string Name;
57+
public string? Name;
6058
}
6159

6260
[AttributeUsage(AttributeTargets.All)]
6361
public class ColumnAttribute : Attribute
6462
{
65-
public ColumnAttribute(string name) => Name = name;
66-
public string Name;
63+
public string? Name;
6764
}
6865

6966
[Test]
7067
public void TypeAttribute()
7168
{
72-
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(Data)));
69+
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(_data)));
7370
var attrs = rd.GetAttributes<TableAttribute>(typeof(XmlReaderTests));
7471

7572
NAssert.NotNull(attrs);
@@ -82,7 +79,7 @@ public void TypeAttribute()
8279
[Test]
8380
public void FieldAttribute()
8481
{
85-
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(Data)));
82+
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(_data)));
8683
var attrs = rd.GetAttributes<ColumnAttribute>(InfoOf.Member<XmlReaderTests>(a => a.Field1)!);
8784

8885
NAssert.NotNull(attrs);
@@ -95,7 +92,7 @@ public void FieldAttribute()
9592
[Test]
9693
public void PropertyAttribute()
9794
{
98-
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(Data)));
95+
var rd = new XmlAttributeReader(new MemoryStream(Encoding.UTF8.GetBytes(_data)));
9996

10097
MappingSchema.Default.AddMetadataReader(rd);
10198

CodeJam.Blocks/Mapping/ConvertBuilder.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
using JetBrains.Annotations;
1515

16-
using SuppressMessageAttribute = System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
17-
1816
namespace CodeJam.Mapping
1917
{
2018
using Reflection;
@@ -505,7 +503,7 @@ from a in dic
505503
}
506504

507505
private static ValueTuple<Expression, bool>? GetConverter(
508-
[AllowNull] MappingSchema? mappingSchema,
506+
MappingSchema mappingSchema,
509507
Expression expr,
510508
Type from,
511509
Type to)
@@ -518,33 +516,33 @@ from a in dic
518516
if (le != null)
519517
return ValueTuple.Create(le.ReplaceParameters(expr), false);
520518

521-
var lex = mappingSchema!.TryGetConvertExpression(from, to);
519+
var lex = mappingSchema.TryGetConvertExpression(from, to);
522520

523521
if (lex != null)
524522
return ValueTuple.Create(lex.ReplaceParameters(expr), true);
525523

526524
var ex =
527525
GetFromEnum(from, to, expr, mappingSchema) ??
528-
GetToEnum(from, to, expr, mappingSchema);
526+
GetToEnum(from, to, expr, mappingSchema);
529527

530528
if (ex != null)
531529
return ValueTuple.Create(ex, true);
532530

533531
ex =
534532
GetConversion(from, to, expr) ??
535-
GetCtor(from, to, expr) ??
536-
GetValue(from, to, expr) ??
537-
GetOperator(from, to, expr) ??
538-
GetParse(from, to, expr) ??
539-
GetToString(from, to, expr) ??
540-
GetParseEnum(from, to, expr);
541-
542-
return ex != null ? ValueTuple.Create(ex, false) : (ValueTuple<Expression, bool>?)null;
533+
GetCtor(from, to, expr) ??
534+
GetValue(from, to, expr) ??
535+
GetOperator(from, to, expr) ??
536+
GetParse(from, to, expr) ??
537+
GetToString(from, to, expr) ??
538+
GetParseEnum(from, to, expr);
539+
540+
return ex != null ? ValueTuple.Create(ex, false) : null;
543541
}
544542

545543
[return: MaybeNull]
546544
private static ValueTuple<Expression, bool>? ConvertUnderlying(
547-
[AllowNull] MappingSchema mappingSchema,
545+
MappingSchema mappingSchema,
548546
Expression expr,
549547
Type from,
550548
Type ufrom,
@@ -597,8 +595,8 @@ from a in dic
597595

598596
var ex =
599597
GetConverter(mappingSchema, p, from, to) ??
600-
ConvertUnderlying(mappingSchema, p, from, from.ToNullableUnderlying(), to, to.ToNullableUnderlying()) ??
601-
ConvertUnderlying(mappingSchema, p, from, from.ToUnderlying(), to, to.ToUnderlying());
598+
ConvertUnderlying(mappingSchema, p, from, from.ToNullableUnderlying(), to, to.ToNullableUnderlying()) ??
599+
ConvertUnderlying(mappingSchema, p, from, from.ToUnderlying(), to, to.ToUnderlying());
602600

603601
if (ex != null)
604602
{
@@ -613,9 +611,7 @@ from a in dic
613611
ex.Value.Item2);
614612
else if (from.GetIsClass())
615613
ex = ValueTuple.Create(
616-
Expression.Condition(
617-
Expression.NotEqual(p, Expression.Constant(null, from)), ex.Value.Item1,
618-
new DefaultValueExpression(mappingSchema, to)) as Expression,
614+
Expression.Condition(Expression.NotEqual(p, Expression.Constant(null, from)), ex.Value.Item1, new DefaultValueExpression(mappingSchema, to)) as Expression,
619615
ex.Value.Item2);
620616
}
621617

@@ -626,8 +622,7 @@ from a in dic
626622
{
627623
var uto = to.ToNullableUnderlying();
628624

629-
var defex = Expression.Call(
630-
_defaultConverter,
625+
var defex = Expression.Call(_defaultConverter,
631626
Expression.Convert(p, typeof(object)),
632627
Expression.Constant(uto)) as Expression;
633628

@@ -636,12 +631,11 @@ from a in dic
636631

637632
defex = GetCtor(uto, to, defex);
638633

639-
return ValueTuple.Create(Expression.Lambda(defex!, p), nullLambda, false);
634+
return ValueTuple.Create(Expression.Lambda(defex ?? p, p), nullLambda, false);
640635
}
641636
else
642637
{
643-
var defex = Expression.Call(
644-
_defaultConverter,
638+
var defex = Expression.Call(_defaultConverter,
645639
Expression.Convert(p, typeof(object)),
646640
Expression.Constant(to)) as Expression;
647641

CodeJam.Blocks/Mapping/ExpressionBuilder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ private ExpressionBuilder(IMapperBuilder mapperBuilder, BuilderData data)
111111
return l;
112112
}
113113

114-
[return: MaybeNull]
115-
private LambdaExpression GetExpressionExInner()
114+
private LambdaExpression? GetExpressionExInner()
116115
{
117116
if (_mapperBuilder.MappingSchema.IsScalarType(_fromType) || _mapperBuilder.MappingSchema.IsScalarType(_toType))
118117
return _mapperBuilder.MappingSchema.GetConvertExpression(_fromType, _toType);
119118

120119
var pFrom = Parameter(_fromType, "from");
121-
var expr = GetExpressionExImpl(pFrom, _toType);
122-
Debug.Assert(expr != null);
120+
var expr = GetExpressionExImpl(pFrom, _toType);
123121

124122
if (_data.IsRestart)
125123
return null;
126124

125+
Debug.Assert(expr != null);
127126
var l = Lambda(expr!, pFrom);
128127

129128
return l;

CodeJam.Blocks/Mapping/IGenericInfoProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES. TODO: update after fixes in Theraot.Core
22
using System;
33

4-
using JetBrains.Annotations;
5-
64
namespace CodeJam.Mapping
75
{
86
internal interface IGenericInfoProvider

CodeJam.Blocks/Mapping/MapValue.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES. TODO: update after fixes in Theraot.Core
22
using System;
33

4-
using JetBrains.Annotations;
5-
64
namespace CodeJam.Mapping
75
{
86
/// <summary>

CodeJam.Blocks/Mapping/MappingSchemaInfo.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
using System.Collections.Generic;
55
using System.Diagnostics.CodeAnalysis;
66
using System.Linq;
7-
using System.Reflection;
87

98
using CodeJam.Collections;
109

11-
using JetBrains.Annotations;
12-
1310
namespace CodeJam.Mapping
1411
{
1512
using Metadata;

CodeJam.Blocks/Metadata/AttributeInfo.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ public Attribute MakeAttribute(Type type)
3737
Expression.Convert(
3838
Expression.MemberInit(
3939
Expression.New(ctor),
40-
_values.Select(
41-
k =>
42-
{
43-
var member = type.GetMember(k.Key)[0];
44-
var mtype = member.GetMemberType();
40+
_values.Select(k =>
41+
{
42+
var member = type.GetMember(k.Key)[0];
43+
var mtype = member.GetMemberType();
4544

46-
return Expression.Bind(
47-
member,
48-
Expression.Constant(Converter.ChangeType(k.Value, mtype), mtype));
49-
})),
45+
return Expression.Bind(
46+
member,
47+
Expression.Constant(Converter.ChangeType(k.Value, mtype), mtype));
48+
})),
5049
typeof(Attribute)));
5150

5251
_func = expr.Compile();

CodeJam.Blocks/Metadata/AttributeReader.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Linq;
44
using System.Reflection;
55

6-
using JetBrains.Annotations;
7-
86
namespace CodeJam.Metadata
97
{
108
internal class AttributeReader : IMetadataReader

CodeJam.Blocks/Metadata/MetaMemberInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
using CodeJam.Strings;
77

8-
using JetBrains.Annotations;
9-
108
namespace CodeJam.Metadata
119
{
1210
internal class MetaMemberInfo

0 commit comments

Comments
 (0)