Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ jobs:
run: dotnet test -c Debug --no-build -v n --filter-trait Category=Unit
- name: Integration Tests
run: |
dotnet test --project tests/HydraScript.IntegrationTests -c Debug --no-build -v n --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml
dotnet test --project tests/HydraScript.IntegrationTests `
-c Debug --no-build -v n `
--coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml `
--coverage-settings tests/coverage-exclude.xml
mkdir coverage-report
- name: Code Coverage Summary Report For Merge Request
if: github.event_name == 'pull_request'
Expand Down
1 change: 1 addition & 0 deletions ExtendedJavaScriptSubset.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Project Path="tests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests.csproj" />
<Project Path="tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj" />
<Project Path="tests/HydraScript.UnitTests/HydraScript.UnitTests.csproj" />
<File Path="tests/coverage-exclude.xml" />
<File Path="tests/Directory.Build.props" />
<File Path="tests/Directory.Packages.props" />
</Folder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@ namespace HydraScript.Application.StaticAnalysis.Impl;

internal class DefaultValueForTypeCalculator : IDefaultValueForTypeCalculator
{
private readonly Type _boolean = "boolean";
private readonly Type _number = "number";
private readonly Type _string = "string";
private readonly Type _void = "void";
private readonly Type _null = new NullType();

public object? GetDefaultValueForType(Type type)
{
if (type is NullableType)
return null;
if (type.Equals(_boolean))
if (type.Equals("boolean"))
return false;
if (type.Equals(_number))
if (type.Equals("number"))
return 0;
if (type.Equals(_string))
if (type.Equals("string"))
return string.Empty;
if (type.Equals(_void))
if (type.Equals("void"))
return new object();
if (type.Equals(_null))
if (type.Equals(new NullType()))
return null;
if (type is ArrayType)
return new List<object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
if (parameters is [ObjectType methodOwner, ..] && visitable.Arguments is [{ TypeValue: TypeIdentValue }, ..])
_methodStorage.BindMethod(methodOwner, functionSymbol, functionSymbolId);

Type undefined = "undefined";
if (functionSymbol.Type.Equals(undefined))
if (functionSymbol.Type.Equals("undefined"))
{
if (visitable.HasReturnStatement)
_functionStorage.Save(functionSymbol, visitable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public Type Visit(ScriptBody visitable)
public Type Visit(WhileStatement visitable)
{
var condType = visitable.Condition.Accept(This);
Type boolean = "boolean";
if (!condType.Equals(boolean))
if (!condType.Equals("boolean"))
throw new NotBooleanTestExpression(visitable.Segment, condType);

visitable.Statement.Accept(This);
Expand All @@ -107,8 +106,7 @@ public Type Visit(WhileStatement visitable)
public Type Visit(IfStatement visitable)
{
var testType = visitable.Test.Accept(This);
Type boolean = "boolean";
if (!testType.Equals(boolean))
if (!testType.Equals("boolean"))
throw new NotBooleanTestExpression(visitable.Segment, testType);

visitable.Then.Accept(This);
Expand Down Expand Up @@ -219,8 +217,7 @@ public ObjectType Visit(ObjectLiteral visitable)
public Type Visit(ConditionalExpression visitable)
{
var tType = visitable.Test.Accept(This);
Type boolean = "boolean";
if (!tType.Equals(boolean))
if (!tType.Equals("boolean"))
throw new NotBooleanTestExpression(visitable.Test.Segment, tType);

var cType = visitable.Consequent.Accept(This);
Expand Down Expand Up @@ -296,7 +293,7 @@ public Type Visit(UnaryExpression visitable)

public Type Visit(LexicalDeclaration visitable)
{
Type undefined = "undefined", @void = "void";
Type undefined = "undefined";

for (var i = 0; i < visitable.Assignments.Count; i++)
{
Expand All @@ -306,7 +303,7 @@ public Type Visit(LexicalDeclaration visitable)

if (sourceType.Equals(undefined))
throw new CannotDefineType(assignment.Source.Segment);
if (sourceType.Equals(@void))
if (sourceType.Equals("void"))
throw new CannotAssignVoid(assignment.Source.Segment);
if (!registeredSymbol.Type.Equals(undefined) && !registeredSymbol.Type.Equals(sourceType))
throw new IncompatibleTypesOfOperands(
Expand Down Expand Up @@ -384,9 +381,8 @@ public Type Visit(IndexAccess visitable)
if (prevType is not ArrayType arrayType)
throw new NonAccessibleType(prevType);

Type number = "number";
var indexType = visitable.Index.Accept(This);
if (!indexType.Equals(number))
if (!indexType.Equals("number"))
throw new ArrayAccessException(visitable.Segment, indexType);

var elemType = arrayType.Type;
Expand Down Expand Up @@ -437,10 +433,9 @@ public ObjectType Visit(WithExpression visitable)

public Type Visit(CastAsExpression visitable)
{
Type undefined = "undefined";
var from = visitable.Expression.Accept(This);

if (from.Equals(undefined))
if (from.Equals("undefined"))
throw new CannotDefineType(visitable.Expression.Segment);

var to = visitable.Cast.Accept(_typeBuilder);
Expand Down Expand Up @@ -495,8 +490,7 @@ public Type Visit(CallExpression visitable)
throw new WrongTypeOfArgument(expr.Segment, expectedType, actualType);
});

Type undefined = "undefined";
if (functionSymbol.Type.Equals(undefined))
if (functionSymbol.Type.Equals("undefined"))
{
var declaration = _functionStorage.Get(functionSymbol);
functionReturnType = declaration.Accept(This);
Expand Down
3 changes: 3 additions & 0 deletions src/Domain/HydraScript.Domain.BackEnd/Impl/Values/Name.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace HydraScript.Domain.BackEnd.Impl.Values;

public class Name(string id, IFrame frame) : IValue
Expand All @@ -19,6 +21,7 @@ other is Name that &&

internal static readonly IFrame NullFrameInstance = new NullFrame();

[ExcludeFromCodeCoverage]
private sealed class NullFrame : IFrame
{
public object? this[string id]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections;
using System.Collections.Frozen;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using Cysharp.Text;
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;
Expand All @@ -23,7 +22,6 @@ public TokenType FindByTag(string tag) =>
public IEnumerator<TokenType> GetEnumerator() =>
Types.Values.AsEnumerable().GetEnumerator();

[ExcludeFromCodeCoverage]
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => Types.Values.Length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using Cysharp.Text;
using HydraScript.Domain.IR.Impl.Symbols.Ids;

Expand All @@ -25,7 +24,6 @@ public class FunctionSymbol(
public void DefineReturnType(Type returnType) =>
_returnType = returnType;

[ExcludeFromCodeCoverage]
public override string ToString()
{
using var zsb = ZString.CreateStringBuilder();
Expand Down
2 changes: 0 additions & 2 deletions src/Domain/HydraScript.Domain.IR/Impl/Symbols/TypeSymbol.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using HydraScript.Domain.IR.Impl.Symbols.Ids;

namespace HydraScript.Domain.IR.Impl.Symbols;
Expand All @@ -15,7 +14,6 @@ obj is TypeSymbol typeSymbol &&
public override int GetHashCode() =>
HashCode.Combine(Name, Type);

[ExcludeFromCodeCoverage]
public override string ToString() =>
$"type {Name} = {Type}";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using HydraScript.Domain.IR.Impl.Symbols.Ids;

namespace HydraScript.Domain.IR.Impl.Symbols;
Expand All @@ -15,7 +14,6 @@ public class VariableSymbol(

public void Initialize() => Initialized = true;

[ExcludeFromCodeCoverage]
public override string ToString() =>
$"{(ReadOnly ? "const " : "")}{Name}: {Type}";
}
20 changes: 1 addition & 19 deletions src/Domain/HydraScript.Domain.IR/Types/ObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,14 @@ private class ObjectTypeHasher
public ObjectTypeHasher(ObjectType reference) =>
_reference = reference;

private int Hash(Type type) => type switch
{
ArrayType arrayType => HashArrayType(arrayType),
ObjectType objectType => HashObjectType(objectType),
NullableType nullableType => HashNullableType(nullableType),
_ => type.GetHashCode()
};

public int HashObjectType(ObjectType objectType) =>
objectType._properties.Keys.Select(
key => HashCode.Combine(
key,
objectType[key]!.Equals(_reference)
? "@this".GetHashCode()
: objectType[key]!.GetType().GetHashCode()))
: HashCode.Combine(key, objectType[key]!.GetType())))
.Aggregate(36, HashCode.Combine);

private int HashArrayType(ArrayType arrayType) =>
arrayType.Type.Equals(_reference)
? "@this".GetHashCode()
: Hash(arrayType.Type);

private int HashNullableType(NullableType nullableType) =>
nullableType.Type.Equals(_reference)
? "@this".GetHashCode()
: Hash(nullableType.Type);
}

private class ObjectTypePrinter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using Cysharp.Text;
using HydraScript.Domain.FrontEnd.Lexer;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -10,7 +9,6 @@ internal class DumpingLexer(
ILexer lexer,
IDumpingService dumpingService) : ILexer
{
[ExcludeFromCodeCoverage]
public IStructure Structure => lexer.Structure;

public IEnumerable<Token> GetTokens(string text)
Expand Down
115 changes: 2 additions & 113 deletions tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,119 +17,8 @@
</ItemGroup>

<ItemGroup>
<None Update="Samples\abs.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\arraddremove.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\arreditread.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\cast.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\ceil.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\counter.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\cycled.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\defaultarray.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\defaultparams.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\equals.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\exprtest.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\fastpow.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\forwardref.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\gcd.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\jump.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\lcm.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\linkedlist.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\nullable.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\objeditread.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\overload.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\overload_object.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\posneg.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\prime.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\primefactor.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\quicksort.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\range.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\recur.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\scope.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\searchinll.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\settable.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\squareroot.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\summator.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\tern.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\this.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\typeresolving.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\vec2d.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\with.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Samples\xxx.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<None Include="Samples\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions tests/HydraScript.IntegrationTests/Samples/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type ObjType = {
num: number;
flag: boolean;
str: string;
arr: number[];
nullableFlag: boolean?;
}

function toString(obj: ObjType): string {
Expand All @@ -13,6 +15,8 @@ let obj: ObjType = {
num: 1;
flag: true;
str: "field";
arr: [1, 2, 3];
nullableFlag: null;
}

>>> obj.toString()
Loading