Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored helpers, classes and namespaces for clarity #85

Merged
merged 3 commits into from
Sep 22, 2023
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
2 changes: 1 addition & 1 deletion StepLang.CLI/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using StepLang.Interpreting;
using StepLang.Parsing.Statements;
using StepLang.Statements;
using StepLang.Tokenizing;

namespace StepLang.CLI;
Expand Down
13 changes: 7 additions & 6 deletions StepLang.Tests/Framework/Mutating/DoAddFunctionTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using StepLang.Expressions;
using StepLang.Expressions.Results;
using StepLang.Framework.Mutating;
using StepLang.Interpreting;
using StepLang.Parsing.Expressions;
using StepLang.Tokenizing;

namespace StepLang.Tests.Framework.Mutating;
Expand Down Expand Up @@ -32,11 +33,11 @@ private sealed class DoAddData : TheoryData<ListResult, Expression>
{
public DoAddData()
{
Add(ListResult.Empty, ConstantExpression.Str("test"));
Add(ListResult.Empty, ConstantExpression.Number(1));
Add(ListResult.Empty, ConstantExpression.True);
Add(ListResult.Empty, Expression.Add(ConstantExpression.Number(1), ConstantExpression.Number(2)));
Add(ListResult.From(BoolResult.True), ConstantExpression.False);
Add(ListResult.Empty, LiteralExpression.Str("test"));
Add(ListResult.Empty, LiteralExpression.Number(1));
Add(ListResult.Empty, LiteralExpression.True);
Add(ListResult.Empty, BinaryExpression.Add(LiteralExpression.Number(1), LiteralExpression.Number(2)));
Add(ListResult.From(BoolResult.True), LiteralExpression.False);
}
}
}
15 changes: 8 additions & 7 deletions StepLang.Tests/Framework/Mutating/DoRemoveFunctionTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using StepLang.Expressions;
using StepLang.Expressions.Results;
using StepLang.Framework.Mutating;
using StepLang.Interpreting;
using StepLang.Parsing.Expressions;
using StepLang.Tokenizing;

namespace StepLang.Tests.Framework.Mutating;
Expand Down Expand Up @@ -30,12 +31,12 @@ private sealed class DoRemoveData : TheoryData<ListResult, Expression, ListResul
{
public DoRemoveData()
{
Add(ListResult.Empty, ConstantExpression.Str("test"), ListResult.Empty);
Add(ListResult.Empty, ConstantExpression.Number(1), ListResult.Empty);
Add(ListResult.Empty, ConstantExpression.True, ListResult.Empty);
Add(ListResult.Empty, Expression.Add(ConstantExpression.Number(1), ConstantExpression.Number(2)), ListResult.Empty);
Add(ListResult.From(BoolResult.True), ConstantExpression.False, ListResult.From(BoolResult.True));
Add(ListResult.From(BoolResult.False), ConstantExpression.False, ListResult.Empty);
Add(ListResult.Empty, LiteralExpression.Str("test"), ListResult.Empty);
Add(ListResult.Empty, LiteralExpression.Number(1), ListResult.Empty);
Add(ListResult.Empty, LiteralExpression.True, ListResult.Empty);
Add(ListResult.Empty, BinaryExpression.Add(LiteralExpression.Number(1), LiteralExpression.Number(2)), ListResult.Empty);
Add(ListResult.From(BoolResult.True), LiteralExpression.False, ListResult.From(BoolResult.True));
Add(ListResult.From(BoolResult.False), LiteralExpression.False, ListResult.Empty);
}
}
}
17 changes: 9 additions & 8 deletions StepLang.Tests/Framework/Other/FileFunctionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Runtime.InteropServices;
using StepLang.Expressions;
using StepLang.Expressions.Results;
using StepLang.Framework.Other;
using StepLang.Interpreting;
using StepLang.Parsing.Expressions;

namespace StepLang.Tests.Framework.Other;

Expand All @@ -22,37 +23,37 @@ public async Task TestFileFunctions(string platform, string filename, string con
var fileReadFunction = new FileReadFunction();
var fileDeleteFunction = new FileDeleteFunction();

var preWriteExistsResult = await fileExistsFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename) });
var preWriteExistsResult = await fileExistsFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename) });

Assert.IsType<BoolResult>(preWriteExistsResult);
Assert.False(preWriteExistsResult.ExpectBool().Value);

var writeResult = await fileWriteFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename), ConstantExpression.Str(content) });
var writeResult = await fileWriteFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename), LiteralExpression.Str(content) });

Assert.IsType<BoolResult>(writeResult);
Assert.True(writeResult.ExpectBool().Value);

var postWriteExistsResult = await fileExistsFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename) });
var postWriteExistsResult = await fileExistsFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename) });

Assert.IsType<BoolResult>(postWriteExistsResult);
Assert.True(postWriteExistsResult.ExpectBool().Value);

var firstReadResult = await fileReadFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename) });
var firstReadResult = await fileReadFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename) });

Assert.IsType<StringResult>(firstReadResult);
Assert.Equal(content, firstReadResult.ExpectString().Value);

var appendResult = await fileWriteFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename), ConstantExpression.Str(content), ConstantExpression.True });
var appendResult = await fileWriteFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename), LiteralExpression.Str(content), LiteralExpression.True });

Assert.IsType<BoolResult>(appendResult);
Assert.True(appendResult.ExpectBool().Value);

var secondReadResult = await fileReadFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename) });
var secondReadResult = await fileReadFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename) });

Assert.IsType<StringResult>(secondReadResult);
Assert.Equal(content + content, secondReadResult.ExpectString().Value);

var deleteResult = await fileDeleteFunction.EvaluateAsync(interpreter, new List<Expression> { ConstantExpression.Str(filename) });
var deleteResult = await fileDeleteFunction.EvaluateAsync(interpreter, new List<Expression> { LiteralExpression.Str(filename) });

Assert.IsType<BoolResult>(deleteResult);
Assert.True(deleteResult.ExpectBool().Value);
Expand Down
27 changes: 14 additions & 13 deletions StepLang.Tests/Framework/Pure/LengthFunctionTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using StepLang.Expressions;
using StepLang.Expressions.Results;
using StepLang.Framework.Pure;
using StepLang.Interpreting;
using StepLang.Parsing.Expressions;
using StepLang.Tokenizing;

namespace StepLang.Tests.Framework.Pure;
Expand All @@ -25,7 +26,7 @@ public async Task TestEvaluateAsync(Expression value, NumberResult expected)
public async Task TestEvaluateWithVariableAsync()
{
var interpreter = new Interpreter();
interpreter.CurrentScope.SetVariable("foo", ConstantExpression.Str("Hello").Result);
interpreter.CurrentScope.SetVariable("foo", LiteralExpression.Str("Hello").Result);

var function = new LengthFunction();
var result = await function.EvaluateAsync(interpreter, new[] { new VariableExpression(new(TokenType.Identifier, "foo", null)) });
Expand All @@ -41,27 +42,27 @@ public async Task TestEvaluateThrowsForUnexpectedType()
var interpreter = new Interpreter();
var function = new LengthFunction();

await Assert.ThrowsAsync<InvalidArgumentTypeException>(() => function.EvaluateAsync(interpreter, new[] { ConstantExpression.Number(0) }));
await Assert.ThrowsAsync<InvalidArgumentTypeException>(() => function.EvaluateAsync(interpreter, new[] { LiteralExpression.Number(0) }));
}

[SuppressMessage("Performance", "CA1812:Avoid uninstantiated internal classes", Justification = "Used by xUnit")]
private sealed class LengthData : TheoryData<Expression, NumberResult>
{
public LengthData()
{
Add(ConstantExpression.Str(""), new NumberResult(0));
Add(ConstantExpression.Str("Hello"), new NumberResult(5));
Add(LiteralExpression.Str(""), new NumberResult(0));
Add(LiteralExpression.Str("Hello"), new NumberResult(5));

var list = new ListExpression(new List<Expression>
{
ConstantExpression.Str("A"),
ConstantExpression.Number(1),
ConstantExpression.Bool(true),
LiteralExpression.Str("A"),
LiteralExpression.Number(1),
LiteralExpression.Bool(true),
});

Add(list, new NumberResult(3));

var constantList = ConstantExpression.List(new List<ExpressionResult>(new[]
var constantList = LiteralExpression.List(new List<ExpressionResult>(new[]
{
new NumberResult(123),
}));
Expand All @@ -70,16 +71,16 @@ public LengthData()
var map = new MapExpression(new Dictionary<string, Expression>
{
{
"Foo", ConstantExpression.Str("A")
"Foo", LiteralExpression.Str("A")
},
{
"Bar", ConstantExpression.Number(1)
"Bar", LiteralExpression.Number(1)
},
{
"Baz", ConstantExpression.Bool(true)
"Baz", LiteralExpression.Bool(true)
},
{
"Bum", ConstantExpression.Str("lol")
"Bum", LiteralExpression.Str("lol")
},
});

Expand Down
2 changes: 1 addition & 1 deletion StepLang.Tests/Framework/Pure/SubstringFunctionTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using StepLang.Interpreting;
using StepLang.Parsing.Statements;
using StepLang.Statements;
using StepLang.Tokenizing;

namespace StepLang.Tests.Framework.Pure;
Expand Down
2 changes: 1 addition & 1 deletion StepLang.Tests/Integration/ExamplesIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using StepLang.Interpreting;
using StepLang.Parsing.Statements;
using StepLang.Statements;
using StepLang.Tokenizing;

namespace StepLang.Tests.Integration;
Expand Down
2 changes: 1 addition & 1 deletion StepLang.Tests/Integration/FailuresIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using StepLang.Interpreting;
using StepLang.Parsing.Statements;
using StepLang.Statements;
using StepLang.Tokenizing;

namespace StepLang.Tests.Integration;
Expand Down
4 changes: 2 additions & 2 deletions StepLang.Tests/Interpreting/InterpretationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using StepLang.Expressions;
using StepLang.Interpreting;
using StepLang.Parsing.Expressions;
using StepLang.Parsing.Statements;
using StepLang.Statements;

namespace StepLang.Tests.Interpreting;

Expand Down
3 changes: 2 additions & 1 deletion StepLang.Tests/Parsing/ExpressionParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using StepLang.Expressions;
using StepLang.Expressions.Results;
using StepLang.Interpreting;
using StepLang.Parsing;
using StepLang.Parsing.Expressions;
using StepLang.Tokenizing;

namespace StepLang.Tests.Parsing;
Expand Down
4 changes: 2 additions & 2 deletions StepLang.Tests/Parsing/ParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StepLang.Expressions;
using StepLang.Interpreting;
using StepLang.Parsing;
using StepLang.Parsing.Expressions;
using StepLang.Parsing.Statements;
using StepLang.Statements;

namespace StepLang.Tests.Parsing;

Expand Down
2 changes: 1 addition & 1 deletion StepLang.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StepLang.Parsing.Statements;
using StepLang.Statements;
using StepLang.Tokenizing;

namespace StepLang.Tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using StepLang.Expressions.Results;
using StepLang.Interpreting;
using StepLang.Tokenizing;

namespace StepLang.Parsing.Expressions;
namespace StepLang.Expressions;

public abstract class BaseFunctionCallExpression : Expression
{
Expand Down
Loading