Skip to content

Commit

Permalink
(test) Minor test improvements
Browse files Browse the repository at this point in the history
Extracted from changes originally done in
#409, to keep the git history
a bit more tidy.
  • Loading branch information
perlun committed Oct 1, 2023
1 parent d66c6a4 commit 1f88e9c
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 71 deletions.
1 change: 1 addition & 0 deletions release-notes/v0.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- The REPL is also noticeably nicer to use now, particularly for those of us used to bash/Emacs-like keybindings. [[#354][354]], [[#356][356]]
- API docs on the website was broken since the v0.2.0 release for unknown reasons. [[#344][344]] has more details.
- Based on community feedback, the project README was also slightly improved. [[#371][371]]
- All changes below were made by @perlun

### Added
#### Data types
Expand Down
6 changes: 6 additions & 0 deletions release-notes/v0.4.0.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [0.4.0] - Unreleased
- The fourth public release of Perlang.
- For more details on how to install Perlang on your own machine, see https://perlang.org/download/.
- All changes below were made by @perlun

### Added
#### Experimental compilation
Expand All @@ -22,6 +24,9 @@

### Fixed

### Tests
- Minor test improvements [[#410][410]]

[366]: https://github.com/perlang-org/perlang/pull/366
[369]: https://github.com/perlang-org/perlang/pull/369
[374]: https://github.com/perlang-org/perlang/pull/374
Expand All @@ -31,3 +36,4 @@
[386]: https://github.com/perlang-org/perlang/pull/386
[389]: https://github.com/perlang-org/perlang/pull/389
[407]: https://github.com/perlang-org/perlang/pull/407
[410]: https://github.com/perlang-org/perlang/pull/410
7 changes: 7 additions & 0 deletions src/Perlang.Common/Expr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ public override string ToString() =>

public class Get : Expr, ITokenAware
{
/// <summary>
/// Gets the target object whose field/property/method is being accessed.
/// </summary>
public Expr Object { get; }

/// <summary>
/// Gets the name of the field/property/method that is being accessed.
/// </summary>
public Token Name { get; }

// TODO: Would be much nicer to have this be without setter, but there is no easy way to accomplish this,
Expand Down
9 changes: 5 additions & 4 deletions src/Perlang.Common/Stmt.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Collections.Immutable;

Expand Down Expand Up @@ -99,9 +100,9 @@ public class If : Stmt
{
public Expr Condition { get; }
public Stmt ThenBranch { get; }
public Stmt ElseBranch { get; }
public Stmt? ElseBranch { get; }

public If(Expr condition, Stmt thenBranch, Stmt elseBranch)
public If(Expr condition, Stmt thenBranch, Stmt? elseBranch)
{
Condition = condition;
ThenBranch = thenBranch;
Expand Down Expand Up @@ -132,9 +133,9 @@ public override TR Accept<TR>(IVisitor<TR> visitor)
public class Return : Stmt
{
public Token Keyword { get; }
public Expr Value { get; }
public Expr? Value { get; }

public Return(Token keyword, Expr value)
public Return(Token keyword, Expr? value)
{
Keyword = keyword;
Value = value;
Expand Down
2 changes: 1 addition & 1 deletion src/Perlang.Interpreter/PerlangInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private void RegisterGlobalClasses()
// validation steps on the complete program now (all the statements executed up to now + the expression
// we just received).
var previousAndNewStatements = previousStatements
.Concat(ImmutableList.Create(new Stmt.ExpressionStmt(result.Expr)))
.Concat(ImmutableList.Create(new Stmt.ExpressionStmt(result.Expr!)))
.ToImmutableList();

//
Expand Down
2 changes: 1 addition & 1 deletion src/Perlang.Interpreter/Typing/TypeValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void Validate(
bool typeResolvingFailed = false;

//
// Phase 1: Resolve explicit and explicit type references to their corresponding CLR types.
// Phase 1: Resolve explicit and implicit type references to their corresponding CLR types.
//
var typeResolver = new TypeResolver(
getVariableOrFunctionCallback,
Expand Down
1 change: 1 addition & 0 deletions src/Perlang.Stdlib/Internal/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Numerics;
using Perlang.Internal.Extensions;
using Perlang.Lang;
using String = Perlang.Lang.String;
Expand Down
11 changes: 7 additions & 4 deletions src/Perlang.Tests.Integration/Comments/CommentsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FluentAssertions;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -27,19 +28,21 @@ public void only_line_comment()
{
string source = "// comment";

var output = Eval(source);
var output = EvalReturningOutputString(source);

Assert.Null(output);
output.Should()
.BeEmpty();
}

[Fact]
public void only_line_comment_and_line()
{
string source = "// comment\n";

var output = Eval(source);
var output = EvalReturningOutputString(source);

Assert.Null(output);
output.Should()
.BeEmpty();
}

[Fact]
Expand Down
6 changes: 5 additions & 1 deletion src/Perlang.Tests.Integration/For/Syntax.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FluentAssertions;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -128,7 +129,10 @@ public void statement_bodies()

var output = EvalReturningOutput(source);

Assert.Equal(new string[] { }, output);
// TODO: Nothing is expected to have been printed by the above, but perhaps we could make this test better
// TODO: and print in the branches?
output.Should()
.BeEmpty();
}
}
}
3 changes: 3 additions & 0 deletions src/Perlang.Tests.Integration/Function/Return.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public void function_can_return_values_in_if_statement()
fun f(i: int): int {
if (i < 10) return i;
if (i >= 10) return i / 2;
// Will never be reached
return -1;
}
print f(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using FluentAssertions;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -61,7 +62,8 @@ public void grouped_and_and_or_operators_does_not_emit_warnings()

string output = EvalReturningOutput(source).SingleOrDefault();

Assert.Equal("False", output);
output!.Should()
.Be("False");
}
}
}
7 changes: 5 additions & 2 deletions src/Perlang.Tests.Integration/LogicalOperator/And.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using FluentAssertions;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -47,7 +48,8 @@ public void true_is_truthy()

string output = EvalReturningOutput(source).SingleOrDefault();

Assert.Equal("True", output);
output!.Should()
.Be("True");
}

[Fact]
Expand All @@ -61,7 +63,8 @@ public void false_is_falsy()

string output = EvalReturningOutput(source).SingleOrDefault();

Assert.Equal("False", output);
output!.Should()
.Be("False");
}

[Fact]
Expand Down
7 changes: 5 additions & 2 deletions src/Perlang.Tests.Integration/LogicalOperator/Or.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using FluentAssertions;
using Xunit;
using static Perlang.Tests.Integration.EvalHelper;

Expand Down Expand Up @@ -47,7 +48,8 @@ public void true_is_truthy()

string output = EvalReturningOutput(source).SingleOrDefault();

Assert.Equal("True", output);
output!.Should()
.Be("True");
}

[Fact]
Expand All @@ -61,7 +63,8 @@ public void false_is_falsy()

string output = EvalReturningOutput(source).SingleOrDefault();

Assert.Equal("False", output);
output!.Should()
.Be("False");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ void Exponential_has_test_data_for_all_supported_primitive_types()
EnsureAllPrimitiveTypesAreHandled(Exponential_result, Exponential_unsupported_types, "Exponential");
}

// EnsureAllPrimitiveTypePairsAreHandled deliberately not tests for the exponential operator, since it only supports
// a limited subset of operand types.
// EnsureAllPrimitiveTypePairsAreHandled deliberately does not test for the exponential operator, since it only
// supports a limited subset of operand types.

[Fact]
void Modulo_has_test_data_for_all_supported_primitive_types()
Expand Down
Loading

0 comments on commit 1f88e9c

Please sign in to comment.