Skip to content

Commit ae09dfc

Browse files
committed
#167 - fix code cov
1 parent 78d6a20 commit ae09dfc

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-13
lines changed

ExtendedJavaScriptSubset.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{04AB
7171
samples\overload_object.js = samples\overload_object.js
7272
samples\overload.js = samples\overload.js
7373
samples\defaultparams.js = samples\defaultparams.js
74+
samples\nullable.js = samples\nullable.js
7475
EndProjectSection
7576
EndProject
7677
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{FB8F6EE1-1942-46D6-954E-9A1647BBDF10}"

samples/nullable.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function indexOrNull(arr:number[], val:number): number?{
2+
const n = ~arr
3+
let i = 0
4+
while(i < n){
5+
if (arr[i] == val)
6+
return i
7+
i = i + 1
8+
}
9+
return null
10+
}
11+
12+
>>> indexOrNull([1,2,3], 4)
13+
>>> indexOrNull([1,2,3], 2)

src/Domain/HydraScript.Domain.IR/Types/Any.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
13
namespace HydraScript.Domain.IR.Types;
24

5+
[ExcludeFromCodeCoverage]
36
public class Any() : Type("any")
47
{
58
public override bool Equals(object? obj) => true;

src/Domain/HydraScript.Domain.IR/Types/NullType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace HydraScript.Domain.IR.Types;
33
public class NullType() : Type("null")
44
{
55
public override bool Equals(object? obj) =>
6-
obj is NullableType or NullType or Any;
6+
obj is ObjectType or NullableType or NullType or Any;
77

88
public override int GetHashCode() =>
99
"null".GetHashCode();

src/Domain/HydraScript.Domain.IR/Types/NullableType.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
namespace HydraScript.Domain.IR.Types;
22

3-
public class NullableType : Type
3+
public class NullableType(Type type) : Type($"{type}?")
44
{
5-
public Type Type { get; private set; } = default!;
6-
7-
public NullableType(Type type) :
8-
base($"{type}?") =>
9-
Type = type;
10-
11-
protected NullableType()
12-
{
13-
}
5+
public Type Type { get; private set; } = type;
146

157
public override void ResolveReference(
168
Type reference,
@@ -28,7 +20,7 @@ public override bool Equals(object? obj)
2820
if (obj is NullableType that)
2921
return Equals(Type, that.Type);
3022

31-
return obj is NullType or Any;
23+
return obj is NullType or Any || (obj is Type type && type.Equals(Type));
3224
}
3325

3426
public override int GetHashCode() =>

src/Domain/HydraScript.Domain.IR/Types/ObjectType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace HydraScript.Domain.IR.Types;
55

6-
public class ObjectType : NullableType
6+
public class ObjectType : Type
77
{
88
private readonly Dictionary<string, Type> _properties;
99
private readonly List<FunctionSymbolId> _methods = [];

tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
<Link>Samples\linkedlist.js</Link>
8181
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
8282
</Content>
83+
<Content Include="..\..\samples\nullable.js">
84+
<Link>Samples\nullable.js</Link>
85+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
86+
</Content>
8387
<Content Include="..\..\samples\objeditread.js">
8488
<Link>Samples\objeditread.js</Link>
8589
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

tests/HydraScript.UnitTests/Domain/IR/TypeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ public void TypeEqualityTest()
1010
{
1111
var number = new Type("number");
1212
var arrayOfNumbers = new ArrayType(number);
13+
var nullableNumber = new NullableType(number);
1314
Assert.False(arrayOfNumbers.Equals(number));
1415
Assert.False(number.Equals(arrayOfNumbers));
16+
Assert.True(nullableNumber.Equals(number));
1517
}
1618

1719
[Fact]

0 commit comments

Comments
 (0)