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.
Parser support for functions and function calls. No returns yet.
- Loading branch information
1 parent
2c65764
commit f53ec56
Showing
10 changed files
with
155 additions
and
77 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
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,10 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class FunLyricTests(ITestOutputHelper output) : ParserTestBase(output) { | ||
|
||
[Theory] | ||
[InlineData("It's more than a feeling (More than a feeling)")] | ||
[InlineData("If it's more than a feeling (More than a feeling) say yeah")] | ||
public void ParserParsesLyric(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class FunctionTests(ITestOutputHelper output) : ParserTestBase(output) { | ||
[Theory] | ||
[InlineData(""" | ||
Echo takes X | ||
say X | ||
(end function) | ||
""")] | ||
[InlineData("sum taking 2, 3")] | ||
[InlineData(""" | ||
Echo takes X | ||
say X | ||
(end function) | ||
Echo taking true | ||
Echo taking "hello world" | ||
put 5 into Temp | ||
Echo taking Temp | ||
""")] | ||
public void ParserParsesFunctions(string source) { | ||
var result = 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,66 @@ | ||
namespace Rockstar.Test; | ||
|
||
public class LoopTests(ITestOutputHelper output) : ParserTestBase(output) { | ||
[Theory] | ||
[InlineData("while true say loop")] | ||
[InlineData(""" | ||
while true | ||
say loop1 | ||
say loop2 | ||
say loop3 | ||
say done | ||
""")] | ||
public void ParserParsesLoop(string source) => Parse(source); | ||
|
||
[Theory] | ||
[InlineData(""" | ||
X is 10 | ||
While X is greater than nothing | ||
While Y is less than 3 | ||
Build Y up | ||
Say Y | ||
Knock X down | ||
""")] | ||
public void ParserParsesNestedLoop(string source) { | ||
var parsed = Parse(source); | ||
parsed.Statements.Count.ShouldBe(2); | ||
} | ||
|
||
[Fact] | ||
public void WhileLoopWorks() { | ||
var source = """ | ||
let i be 0 | ||
while i is less than 5 | ||
say i | ||
build i up | ||
say "finished" | ||
"""; | ||
var parsed = Parse(source); | ||
var e = new TestEnvironment(); | ||
var i = new Interpreter(e); | ||
var result = i.Exec(parsed); | ||
e.Output.ReplaceLineEndings().ShouldBe("0\n1\n2\n3\n4\nfinished\n".ReplaceLineEndings()); | ||
} | ||
|
||
[Fact] | ||
public void UntilLoopWorks() { | ||
var source = """ | ||
let i be 0 | ||
until i is as great as 5 | ||
say i | ||
build i up | ||
say "finished" | ||
"""; | ||
var parsed = Parse(source); | ||
var e = new TestEnvironment(); | ||
var i = new Interpreter(e); | ||
var result = i.Exec(parsed); | ||
e.Output.ReplaceLineEndings().ShouldBe("0\n1\n2\n3\n4\nfinished\n".ReplaceLineEndings()); | ||
} | ||
|
||
} |
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