This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compound assignments (let x be with 5) are working.
- Loading branch information
1 parent
a10f784
commit d330694
Showing
14 changed files
with
123 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class CompoundAssignmentTests(ITestOutputHelper output) : ParserTestBase(output) { | ||
[Theory] | ||
[InlineData("let x be with 5")] | ||
[InlineData("let x be without 5")] | ||
[InlineData("let x be over 2")] | ||
[InlineData("let the night be without regret")] | ||
public void ParserParsesSimpleConditionals(string source) | ||
=> Parse(source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class IncrementDecrementTests(ITestOutputHelper output) { | ||
[Theory] | ||
[InlineData("build X up")] | ||
[InlineData("build X up up")] | ||
[InlineData("build X up, up")] | ||
[InlineData("knock X down")] | ||
[InlineData("knock X down, down, down")] | ||
[InlineData("knock X down down down")] | ||
public void ParserParsesIncrementsAndDecrements(string source) { | ||
var parser = new Parser(); // { Tracer = DiagnosticsTracer.Instance }; | ||
var result = parser.Parse(source); | ||
output.WriteLine(result.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Pegasus.Common.Tracing; | ||
|
||
namespace Rockstar.Test; | ||
|
||
public class LiteralTests { | ||
[Theory] | ||
[InlineData("say 1")] | ||
[InlineData("say 1.1")] | ||
[InlineData("say .1")] | ||
public void ParserParsesNumberLiterals(string source) { | ||
var parser = new Parser() { Tracer = DiagnosticsTracer.Instance }; | ||
var result = parser.Parse(source); | ||
result.Statements.Count.ShouldBe(1); | ||
} | ||
|
||
[Theory] | ||
[InlineData("the sky is crying", 6)] | ||
[InlineData("Tommy was a lovestruck ladykiller", 100)] | ||
[InlineData("Tommy was a", 1)] | ||
[InlineData("Tommy was a aa", 12)] | ||
[InlineData("Tommy was a aa aaa", 123)] | ||
[InlineData("Tommy was a aa aaa aaaa aaaaa", 12345)] | ||
[InlineData("Tommy was a. aa aaa aaaa", 1.234)] | ||
[InlineData("Tommy was a aa. aaa aaaa", 12.34)] | ||
public void PoeticLiteralAssignsCorrectValue(string source, decimal value) { | ||
var parser = new Parser() { Tracer = DiagnosticsTracer.Instance }; | ||
var assign = parser.Parse(source).Statements[0] as Assign; | ||
((Number) assign.Expr).Value.ShouldBe(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Pegasus.Common.Tracing; | ||
|
||
namespace Rockstar.Test; | ||
|
||
public class OperatorTests { | ||
[Theory] | ||
[InlineData("say 1 + 2 + 3")] | ||
[InlineData("say 1 plus 2 plus 3")] | ||
[InlineData("say \"hello\" plus \" \" plus .11")] | ||
public void AdditionOperatorWorks(string source) { | ||
var parser = new Parser() { Tracer = DiagnosticsTracer.Instance }; | ||
var result = parser.Parse(source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class ParserTestBase(ITestOutputHelper output) { | ||
protected void Parse(string source) { | ||
var parser = new Parser(); // { Tracer = DiagnosticsTracer.Instance }; | ||
var result = parser.Parse(source); | ||
output.WriteLine(result.ToString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System.Diagnostics; | ||
using Pegasus.Common.Tracing; | ||
using Rockstar.Engine.Expressions; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class TestEnvironment : RockstarEnvironment { | ||
|
||
private readonly StringBuilder outputStringBuilder = new(); | ||
public string Output => outputStringBuilder.ToString(); | ||
public override string? ReadInput() => null; | ||
|
||
public override void WriteLine(string output) | ||
=> this.outputStringBuilder.Append(output + Environment.NewLine); | ||
|
||
public override void Write(string s) | ||
=> this.outputStringBuilder.Append(s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters