Skip to content

Commit

Permalink
Merge pull request #3 from PrestonLTaylor/refactoring-lib-chore
Browse files Browse the repository at this point in the history
Refactor and clean up the code base a bit
  • Loading branch information
PrestonLTaylor authored Apr 5, 2024
2 parents 8242014 + 0ac0ce8 commit 92a7746
Show file tree
Hide file tree
Showing 66 changed files with 901 additions and 930 deletions.
497 changes: 247 additions & 250 deletions JSS.Lib.UnitTests/ASTTests.cs

Large diffs are not rendered by default.

70 changes: 34 additions & 36 deletions JSS.Lib.UnitTests/AbstractOperationTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using JSS.Lib.AST;
using FluentAssertions;
using JSS.Lib.AST;
using JSS.Lib.AST.Literal;
using JSS.Lib.AST.Values;
using JSS.Lib.Execution;
using Boolean = JSS.Lib.AST.Values.Boolean;
using String = JSS.Lib.AST.Values.String;

namespace JSS.Lib.UnitTests;

Expand All @@ -12,15 +11,15 @@ internal sealed class AbstractOperationTests
static private readonly List<Value> toPrimitiveIdentityTestCases = new()
{
Null.The,
new Boolean(false),
new Boolean(true),
new Number(0.0),
new Number(1.0),
new Number(123456789.0),
new String(""),
new String("'"),
new String("\""),
new String("This is a string literal"),
false,
true,
0.0,
1.0,
123456789.0,
"",
"'",
"\"",
"This is a string literal",
};

[TestCaseSource(nameof(toPrimitiveIdentityTestCases))]
Expand All @@ -32,11 +31,10 @@ public void ToPrimitive_ReturnsNormalCompletion_WithTheSameValue_WhenNotProvidin
var completion = expected.ToPrimitive();

// Assert
Assert.That(completion.IsNormalCompletion(), Is.True);
Assert.That(completion.Value, Is.SameAs(expected));
completion.IsNormalCompletion().Should().BeTrue();
completion.Value.Should().Be(expected);
}

// FIXME: Replace other Dictionary test cases with object[]
static private readonly object[] valueToExpectedStringTestCases =
{
new object[] { Null.The, "null" },
Expand All @@ -60,11 +58,11 @@ public void ToString_ReturnsNormalCompletion_WithExpectedString_WhenProvidingVal
var asString = testCase.ToStringJS();

// Assert
Assert.That(asString.IsNormalCompletion(), Is.True);
asString.IsNormalCompletion().Should().BeTrue();

var stringValue = asString.Value as String;
Assert.That(stringValue, Is.Not.Null);
Assert.That(stringValue.Value, Is.EqualTo(expectedString));
stringValue.Should().NotBeNull();
stringValue!.Value.Should().Be(expectedString);
}

static private readonly object[] valueToExpectedNumberTestCases = new object[]
Expand All @@ -89,11 +87,11 @@ public void ToNumber_ReturnsNormalCompletion_WithExpectedNumber_WhenProvidingVal
var asNumber = testCase.ToNumber();

// Assert
Assert.That(asNumber.IsNormalCompletion(), Is.True);
asNumber.IsNormalCompletion().Should().BeTrue();

var numberValue = asNumber.Value as Number;
Assert.That(numberValue, Is.Not.Null);
Assert.That(numberValue.Value, Is.EqualTo(expectedNumber));
numberValue.Should().NotBeNull();
numberValue!.Value.Should().Be(expectedNumber);
}

[TestCaseSource(nameof(valueToExpectedNumberTestCases))]
Expand All @@ -105,11 +103,11 @@ public void ToNumeric_ReturnsNormalCompletion_WithExpectedNumber_WhenProvidingVa
var asNumeric = testCase.ToNumeric();

// Assert
Assert.That(asNumeric.IsNormalCompletion(), Is.True);
asNumeric.IsNormalCompletion().Should().BeTrue();

var numberValue = asNumeric.Value as Number;
Assert.That(numberValue, Is.Not.Null);
Assert.That(numberValue.Value, Is.EqualTo(expectedNumber));
numberValue.Should().NotBeNull();
numberValue!.Value.Should().Be(expectedNumber);
}

static private readonly object[] unaryMinusValueToExpectedNumberTestCases = new object[]
Expand All @@ -128,7 +126,7 @@ public void UnaryMinus_ReturnsExpectedNumber_WhenProvidingValue(Number testCase,
var result = Number.UnaryMinus(testCase);

// Assert
Assert.That(result?.Value, Is.EqualTo(expectedNumber));
result?.Value.Should().Be(expectedNumber);
}

// FIXME: Individual test cases for the underlying abstract operations in ApplyStringOrNumericBinaryOperator
Expand Down Expand Up @@ -164,8 +162,8 @@ public void ApplyStringOrNumericBinaryOperator_ReturnsNormalCompletion_WithExpec
var result = IExpression.ApplyStringOrNumericBinaryOperator(lhs, op, rhs);

// Assert
Assert.That(result.IsNormalCompletion(), Is.True);
Assert.That(result.Value, Is.EqualTo(expectedValue));
result.IsNormalCompletion().Should().BeTrue();
result.Value.Should().Be(expectedValue);
}

static private readonly object[] binaryAstExpressionToExpectedValueTestCases =
Expand Down Expand Up @@ -201,8 +199,8 @@ public void EvaluateStringOrNumericBinaryExpression_ReturnsNormalCompletion_With
var result = IExpression.EvaluateStringOrNumericBinaryExpression(vm, lhs, op, rhs);

// Assert
Assert.That(result.IsNormalCompletion(), Is.True);
Assert.That(result.Value, Is.EqualTo(expectedValue));
result.IsNormalCompletion().Should().BeTrue();
result.Value.Should().Be(expectedValue);
}

// FIXME: Tests for Number::lessThan
Expand Down Expand Up @@ -231,9 +229,9 @@ public void IsLessThan_ReturnsNormalCompletion_WithExpectedResult(Value lhs, Val
var completion = Value.IsLessThan(lhs, rhs, false);

// Assert
Assert.That(completion.IsNormalCompletion(), Is.True);
completion.IsNormalCompletion().Should().BeTrue();

Assert.That(completion.Value, Is.EqualTo(expectedValue));
completion.Value.Should().Be(expectedValue);
}

static private readonly object[] toBooleanValueToExpectedResultTestCases =
Expand Down Expand Up @@ -261,7 +259,7 @@ public void ToBoolean_ReturnsBoolean_WithExpectedResult(Value testCase, bool exp
var result = testCase.ToBoolean();

// Assert
Assert.That(result, Is.EqualTo(expectedValue));
result.Should().Be(expectedValue);
}

// FIXME: Tests for Number::equal and SameValueNonNumber
Expand Down Expand Up @@ -294,7 +292,7 @@ public void IsStrictlyEqual_ReturnsBoolean_WithExpectedResult(Value lhs, Value r
var result = Value.IsStrictlyEqual(lhs, rhs);

// Assert
Assert.That(result, Is.EqualTo(expectedValue));
result.Should().Be(expectedValue);
}

static private readonly object[] isLooselyEqualLhsAndRhsToExpectedResultTestCases =
Expand Down Expand Up @@ -326,9 +324,9 @@ public void IsLooselyEqual_ReturnsNormalCompletion_WithExpectedResult(Value lhs,
var completion = Value.IsLooselyEqual(lhs, rhs);

// Assert
Assert.That(completion.IsNormalCompletion(), Is.True);
completion.IsNormalCompletion().Should().BeTrue();

Assert.That(completion.Value, Is.EqualTo(expectedValue));
completion.Value.Should().Be(expectedValue);
}

static private readonly object[] loopContinuesValueToExpectedResultTestCases =
Expand All @@ -350,6 +348,6 @@ public void LoopContinues_ReturnsExpectedBoolean_WhenProvidedCompletion(Completi
var result = completion.LoopContinues();

// Assert
Assert.That(result, Is.EqualTo(expectedValue));
result.Should().Be(expectedValue);
}
}
Loading

0 comments on commit 92a7746

Please sign in to comment.