Skip to content

Commit b1872cb

Browse files
authored
improve coverage (#219)
* improve ObjectType.cs coverage * backend frame coverage * fix * reduce csproj of integration tests * type decl fix * exclude src gen code * prev exclude fix * improve config * fix usings
1 parent f74636f commit b1872cb

File tree

15 files changed

+49
-170
lines changed

15 files changed

+49
-170
lines changed

.github/workflows/develop.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ jobs:
5353
run: dotnet test -c Debug --no-build -v n --filter-trait Category=Unit
5454
- name: Integration Tests
5555
run: |
56-
dotnet test --project tests/HydraScript.IntegrationTests -c Debug --no-build -v n --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml
56+
dotnet test --project tests/HydraScript.IntegrationTests `
57+
-c Debug --no-build -v n `
58+
--coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml `
59+
--coverage-settings tests/coverage-exclude.xml
5760
mkdir coverage-report
5861
- name: Code Coverage Summary Report For Merge Request
5962
if: github.event_name == 'pull_request'

ExtendedJavaScriptSubset.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Project Path="tests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests/HydraScript.Infrastructure.LexerRegexGenerator.UnitTests.csproj" />
5050
<Project Path="tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj" />
5151
<Project Path="tests/HydraScript.UnitTests/HydraScript.UnitTests.csproj" />
52+
<File Path="tests/coverage-exclude.xml" />
5253
<File Path="tests/Directory.Build.props" />
5354
<File Path="tests/Directory.Packages.props" />
5455
</Folder>

src/Application/HydraScript.Application.StaticAnalysis/Impl/DefaultValueForTypeCalculator.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@ namespace HydraScript.Application.StaticAnalysis.Impl;
44

55
internal class DefaultValueForTypeCalculator : IDefaultValueForTypeCalculator
66
{
7-
private readonly Type _boolean = "boolean";
8-
private readonly Type _number = "number";
9-
private readonly Type _string = "string";
10-
private readonly Type _void = "void";
11-
private readonly Type _null = new NullType();
12-
137
public object? GetDefaultValueForType(Type type)
148
{
159
if (type is NullableType)
1610
return null;
17-
if (type.Equals(_boolean))
11+
if (type.Equals("boolean"))
1812
return false;
19-
if (type.Equals(_number))
13+
if (type.Equals("number"))
2014
return 0;
21-
if (type.Equals(_string))
15+
if (type.Equals("string"))
2216
return string.Empty;
23-
if (type.Equals(_void))
17+
if (type.Equals("void"))
2418
return new object();
25-
if (type.Equals(_null))
19+
if (type.Equals(new NullType()))
2620
return null;
2721
if (type is ArrayType)
2822
return new List<object>();

src/Application/HydraScript.Application.StaticAnalysis/Visitors/DeclarationVisitor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
101101
if (parameters is [ObjectType methodOwner, ..] && visitable.Arguments is [{ TypeValue: TypeIdentValue }, ..])
102102
_methodStorage.BindMethod(methodOwner, functionSymbol, functionSymbolId);
103103

104-
Type undefined = "undefined";
105-
if (functionSymbol.Type.Equals(undefined))
104+
if (functionSymbol.Type.Equals("undefined"))
106105
{
107106
if (visitable.HasReturnStatement)
108107
_functionStorage.Save(functionSymbol, visitable);

src/Application/HydraScript.Application.StaticAnalysis/Visitors/SemanticChecker.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public Type Visit(ScriptBody visitable)
9595
public Type Visit(WhileStatement visitable)
9696
{
9797
var condType = visitable.Condition.Accept(This);
98-
Type boolean = "boolean";
99-
if (!condType.Equals(boolean))
98+
if (!condType.Equals("boolean"))
10099
throw new NotBooleanTestExpression(visitable.Segment, condType);
101100

102101
visitable.Statement.Accept(This);
@@ -107,8 +106,7 @@ public Type Visit(WhileStatement visitable)
107106
public Type Visit(IfStatement visitable)
108107
{
109108
var testType = visitable.Test.Accept(This);
110-
Type boolean = "boolean";
111-
if (!testType.Equals(boolean))
109+
if (!testType.Equals("boolean"))
112110
throw new NotBooleanTestExpression(visitable.Segment, testType);
113111

114112
visitable.Then.Accept(This);
@@ -219,8 +217,7 @@ public ObjectType Visit(ObjectLiteral visitable)
219217
public Type Visit(ConditionalExpression visitable)
220218
{
221219
var tType = visitable.Test.Accept(This);
222-
Type boolean = "boolean";
223-
if (!tType.Equals(boolean))
220+
if (!tType.Equals("boolean"))
224221
throw new NotBooleanTestExpression(visitable.Test.Segment, tType);
225222

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

297294
public Type Visit(LexicalDeclaration visitable)
298295
{
299-
Type undefined = "undefined", @void = "void";
296+
Type undefined = "undefined";
300297

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

307304
if (sourceType.Equals(undefined))
308305
throw new CannotDefineType(assignment.Source.Segment);
309-
if (sourceType.Equals(@void))
306+
if (sourceType.Equals("void"))
310307
throw new CannotAssignVoid(assignment.Source.Segment);
311308
if (!registeredSymbol.Type.Equals(undefined) && !registeredSymbol.Type.Equals(sourceType))
312309
throw new IncompatibleTypesOfOperands(
@@ -384,9 +381,8 @@ public Type Visit(IndexAccess visitable)
384381
if (prevType is not ArrayType arrayType)
385382
throw new NonAccessibleType(prevType);
386383

387-
Type number = "number";
388384
var indexType = visitable.Index.Accept(This);
389-
if (!indexType.Equals(number))
385+
if (!indexType.Equals("number"))
390386
throw new ArrayAccessException(visitable.Segment, indexType);
391387

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

438434
public Type Visit(CastAsExpression visitable)
439435
{
440-
Type undefined = "undefined";
441436
var from = visitable.Expression.Accept(This);
442437

443-
if (from.Equals(undefined))
438+
if (from.Equals("undefined"))
444439
throw new CannotDefineType(visitable.Expression.Segment);
445440

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

498-
Type undefined = "undefined";
499-
if (functionSymbol.Type.Equals(undefined))
493+
if (functionSymbol.Type.Equals("undefined"))
500494
{
501495
var declaration = _functionStorage.Get(functionSymbol);
502496
functionReturnType = declaration.Accept(This);

src/Domain/HydraScript.Domain.BackEnd/Impl/Values/Name.cs

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

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

2022
internal static readonly IFrame NullFrameInstance = new NullFrame();
2123

24+
[ExcludeFromCodeCoverage]
2225
private sealed class NullFrame : IFrame
2326
{
2427
public object? this[string id]

src/Domain/HydraScript.Domain.FrontEnd/Lexer/Impl/Structure.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections;
22
using System.Collections.Frozen;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Text.RegularExpressions;
54
using Cysharp.Text;
65
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;
@@ -23,7 +22,6 @@ public TokenType FindByTag(string tag) =>
2322
public IEnumerator<TokenType> GetEnumerator() =>
2423
Types.Values.AsEnumerable().GetEnumerator();
2524

26-
[ExcludeFromCodeCoverage]
2725
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
2826

2927
public int Count => Types.Values.Length;

src/Domain/HydraScript.Domain.IR/Impl/Symbols/FunctionSymbol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics.CodeAnalysis;
21
using Cysharp.Text;
32
using HydraScript.Domain.IR.Impl.Symbols.Ids;
43

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

28-
[ExcludeFromCodeCoverage]
2927
public override string ToString()
3028
{
3129
using var zsb = ZString.CreateStringBuilder();

src/Domain/HydraScript.Domain.IR/Impl/Symbols/TypeSymbol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics.CodeAnalysis;
21
using HydraScript.Domain.IR.Impl.Symbols.Ids;
32

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

18-
[ExcludeFromCodeCoverage]
1917
public override string ToString() =>
2018
$"type {Name} = {Type}";
2119
}

src/Domain/HydraScript.Domain.IR/Impl/Symbols/VariableSymbol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics.CodeAnalysis;
21
using HydraScript.Domain.IR.Impl.Symbols.Ids;
32

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

1615
public void Initialize() => Initialized = true;
1716

18-
[ExcludeFromCodeCoverage]
1917
public override string ToString() =>
2018
$"{(ReadOnly ? "const " : "")}{Name}: {Type}";
2119
}

0 commit comments

Comments
 (0)