Skip to content

Commit 01b1aae

Browse files
committed
improve ObjectType.cs coverage
1 parent f74636f commit 01b1aae

File tree

2 files changed

+5
-19
lines changed
  • src/Domain/HydraScript.Domain.IR/Types
  • tests/HydraScript.IntegrationTests/Samples

2 files changed

+5
-19
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,14 @@ private class ObjectTypeHasher
9999
public ObjectTypeHasher(ObjectType reference) =>
100100
_reference = reference;
101101

102-
private int Hash(Type type) => type switch
103-
{
104-
ArrayType arrayType => HashArrayType(arrayType),
105-
ObjectType objectType => HashObjectType(objectType),
106-
NullableType nullableType => HashNullableType(nullableType),
107-
_ => type.GetHashCode()
108-
};
109-
110102
public int HashObjectType(ObjectType objectType) =>
111103
objectType._properties.Keys.Select(
112104
key => HashCode.Combine(
113105
key,
114106
objectType[key]!.Equals(_reference)
115107
? "@this".GetHashCode()
116-
: objectType[key]!.GetType().GetHashCode()))
108+
: HashCode.Combine(key, objectType[key]!.GetType())))
117109
.Aggregate(36, HashCode.Combine);
118-
119-
private int HashArrayType(ArrayType arrayType) =>
120-
arrayType.Type.Equals(_reference)
121-
? "@this".GetHashCode()
122-
: Hash(arrayType.Type);
123-
124-
private int HashNullableType(NullableType nullableType) =>
125-
nullableType.Type.Equals(_reference)
126-
? "@this".GetHashCode()
127-
: Hash(nullableType.Type);
128110
}
129111

130112
private class ObjectTypePrinter

tests/HydraScript.IntegrationTests/Samples/this.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ type ObjType = {
22
num: number;
33
flag: boolean;
44
str: string;
5+
arr: number[];
6+
nullableFlag: boolean?;
57
}
68

79
function toString(obj: ObjType): string {
@@ -13,6 +15,8 @@ let obj: ObjType = {
1315
num: 1;
1416
flag: true;
1517
str: "field";
18+
arr: [1, 2, 3];
19+
nullableFlag: null;
1620
}
1721

1822
>>> obj.toString()

0 commit comments

Comments
 (0)