Skip to content

Commit 43eb2a5

Browse files
committed
Improve test coverage
1 parent c11910b commit 43eb2a5

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

src/D.Compiler.Tests/CSharp/CSharpRewriterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void IfElseIfElse()
166166
{
167167
return 5;
168168
}
169-
""".Replace("\r\n", "\n"),
169+
""".ReplaceLineEndings("\n"),
170170

171171
Rewrite(
172172
"""

src/D.Compiler.Tests/CSharp/ImplementationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Bezier(Vector3 c1, Vector3 c2, Vector3 c3, Vector3 c4)
7070
7171
private object B4(double t) => (1 - t) * (1 - t) * (1 - t);
7272
}
73-
""".Replace("\r\n", "\n"), r);
73+
""".ReplaceLineEndings("\n"), r);
7474
}
7575

7676
[Fact]
@@ -120,7 +120,7 @@ public static string A(Point<T> point)
120120
var y = point.Y;
121121
var z = point.Z;
122122
}
123-
""".Replace("\r\n", "\n"),
123+
""".ReplaceLineEndings("\n"),
124124

125125
Transpile(
126126
"""
@@ -144,7 +144,7 @@ public void X()
144144
public static object SinIn(double x) => Math.Sin(x * Math.PI * 0.5);
145145
146146
public static object SinOut(double x) => -Math.Cos(Math.PI * x) / 2 + 0.5;
147-
""".Replace("\r\n", "\n"),
147+
""".ReplaceLineEndings("\n"),
148148

149149
Transpile(
150150
"""

src/D.Scripting.Tests/Evaluator/EvaulatorTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32

43
using Carbon.Color;
54

@@ -181,20 +180,18 @@ public static object Evaluate(IExpression statement)
181180
{
182181
return new Evaluator().Evaluate(statement);
183182
}
184-
185183

186184
[Fact]
187185
public void Eval2()
188186
{
189187
var env = new Node(
190188
new ArithmeticModule()
191-
);
189+
);
192190

193191
var result = new Evaluator(env).Evaluate("1kg * 1lb");
194192

195193
Assert.Equal("0.453592kg²", result.ToString());
196-
}
197-
194+
}
198195

199196
[Theory]
200197
[InlineData("2kg * 3", "6kg")]

src/D.Tests/Parser/AssignmentTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,32 @@ public void AssignmentPattern()
5858
}
5959

6060
[Fact]
61-
public void Read2()
61+
public void CanReadTwoAssignments()
6262
{
6363
var parser = new Parser(
6464
"""
6565
image = 10
6666
b = 2
67-
""".ReplaceLineEndings(Environment.NewLine));
67+
""");
68+
69+
var one = (BinaryExpressionSyntax)parser.Next();
70+
var two = (BinaryExpressionSyntax)parser.Next();
71+
72+
Assert.Equal("image", one.Left.ToString());
73+
Assert.Equal("10", one.Right.ToString());
74+
75+
Assert.Equal("b", two.Left.ToString());
76+
Assert.Equal("2", two.Right.ToString());
77+
}
78+
79+
[Fact]
80+
public void CanReadTwoAssignments2()
81+
{
82+
var parser = new Parser(
83+
"""
84+
image = 10
85+
b = 2
86+
""".ReplaceLineEndings("\n"));
6887

6988
var one = (BinaryExpressionSyntax)parser.Next();
7089
var two = (BinaryExpressionSyntax)parser.Next();

src/D.Tests/TestBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ public static T Parse<T>(string text)
1212
private static readonly string RootDirectory = new DirectoryInfo(AppContext.BaseDirectory).Parent.Parent.Parent.Parent.Parent.FullName;
1313

1414
public FileInfo GetDocument(string name) => new FileInfo(Path.Combine(RootDirectory, "modules", name));
15-
15+
1616
public IEnumerable<FileInfo> ReadDocuments(string path)
17-
=> new DirectoryInfo(Path.Combine(RootDirectory, "modules", path)).EnumerateFiles();
17+
{
18+
return new DirectoryInfo(Path.Combine(RootDirectory, "modules", path)).EnumerateFiles();
19+
}
1820

1921
public string ReadDocument(string name) => GetDocument(name).OpenText().ReadToEnd();
2022
}

0 commit comments

Comments
 (0)