-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
331 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Sct; | ||
|
||
namespace SocietalConstructionToolTests | ||
{ | ||
[TestClass] | ||
public class CompilerTests | ||
{ | ||
private static IEnumerable<string[]> Files => TestFileUtils.GetTestFiles("CompilerTests"); | ||
|
||
[DataTestMethod] | ||
[DynamicData(nameof(Files), DynamicDataSourceType.Property)] | ||
public void ParseFile(string testFile) | ||
{ | ||
var (outputText, errors) = SctRunner.CompileSct([testFile]); | ||
|
||
Assert.IsFalse(errors.Any(), "SCT compiled with errors:\n" + string.Join('\n', errors)); | ||
Assert.IsNotNull(outputText); | ||
|
||
// Discard the generated assembly | ||
var stream = Stream.Null; | ||
|
||
var result = SctRunner.Emit(outputText, stream); | ||
Assert.IsTrue(result.Success, $"Could not compile generated C#\nCompilation diagnostics: {string.Join('\n', result.Diagnostics)}\n\nCode:\n" + outputText); | ||
} | ||
} | ||
} |
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 SocietalConstructionToolTests | ||
{ | ||
public static class TestFileUtils | ||
{ | ||
// yield all files in some subdirectory of the TestFiles directory | ||
public static IEnumerable<string[]> GetTestFiles(string dir) => | ||
Directory.GetFiles(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", dir)) | ||
.Select(f => new[] { f }); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
SocietalConstructionToolTests/TestFiles/CompilerTests/Arithmetic.sct
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,3 @@ | ||
function Setup() -> void { | ||
int a = (2 + 3 * 4) / (2 - 1); | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/AssignFloat.sct
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,5 @@ | ||
function Setup() -> void { | ||
float pi = 3.14159; | ||
float a = 1.5; | ||
float b = 2.0; | ||
} |
3 changes: 3 additions & 0 deletions
3
SocietalConstructionToolTests/TestFiles/CompilerTests/AssignInt.sct
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,3 @@ | ||
function Setup() -> void { | ||
int a = 5; | ||
} |
6 changes: 6 additions & 0 deletions
6
SocietalConstructionToolTests/TestFiles/CompilerTests/BinaryNumeric.sct
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,6 @@ | ||
function Setup() -> void { | ||
int a = 1 + 1; | ||
float b = 0.4 + 2; | ||
float c = 2 + 0.4; | ||
float d = 0.4 + 0.4; | ||
} |
83 changes: 83 additions & 0 deletions
83
SocietalConstructionToolTests/TestFiles/CompilerTests/BinaryPredicate.sct
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,83 @@ | ||
// Add behavour which tests if stuff is equal | ||
class Foo(int a, int b) { | ||
state Bar { | ||
enter End; | ||
} | ||
|
||
state Baz { | ||
enter End; | ||
} | ||
|
||
state End { | ||
exit; | ||
} | ||
} | ||
|
||
class Output() { | ||
state Equal { enter Equal; } | ||
state Unequal { enter Equal; } | ||
} | ||
|
||
function Setup() -> void { | ||
// Arrange | ||
Predicate fullEqual = Foo::Bar(a: 1, b: 2); | ||
Predicate fullEqual2 = Foo::Bar(a: 1, b: 2); | ||
Predicate fullDifferent = Foo::Bar(a: 2, b: 3); | ||
|
||
Predicate partialEqual = Foo::Bar(a: 1); | ||
Predicate partialEqual2 = Foo::Bar(a: 1); | ||
Predicate partialDifferent = Foo::Bar(a: 2); | ||
|
||
Predicate wildcardEqual = Foo::?(a: 1, b: 2); | ||
Predicate wildcardEqual2 = Foo::?(a: 1, b: 2); | ||
Predicate wildcardDifferent = Foo::?(a: 2, b: 3); | ||
|
||
// Assert | ||
int equal = fullEqual == fullEqual2; | ||
|
||
if (equal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
|
||
equal = partialEqual == partialEqual2; | ||
|
||
if (equal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
|
||
equal = wildcardEqual == wildcardEqual2; | ||
|
||
if (equal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
|
||
int unequal = fullEqual == fullDifferent; | ||
|
||
if (!unequal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
|
||
unequal = partialEqual == partialDifferent; | ||
|
||
if (!unequal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
|
||
unequal = wildcardEqual == wildcardDifferent; | ||
|
||
if (!unequal) { | ||
create Output::Equal(); | ||
} else { | ||
create Output::Unequal(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/BreakInLoop.sct
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,5 @@ | ||
function Setup() -> void { | ||
while (1) { | ||
break; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/CompilerTests/EnterInDecorator.sct
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,12 @@ | ||
class C() { | ||
decorator D { | ||
enter S; | ||
} | ||
|
||
state S { | ||
enter S; | ||
} | ||
} | ||
|
||
function Setup() -> void { | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/CompilerTests/ExpressionBoolean.sct
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,12 @@ | ||
function Setup() -> void { | ||
int a = 1 && 1; | ||
a = 1 || 0; | ||
|
||
a = 2 == 2; | ||
a = 3 != 4; | ||
|
||
a = 3 > 2; | ||
a = 4 >= 3; | ||
a = 1 < 5; | ||
a = 2 <= 5; | ||
} |
3 changes: 3 additions & 0 deletions
3
SocietalConstructionToolTests/TestFiles/CompilerTests/ExpressionNot.sct
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,3 @@ | ||
function Setup() -> void { | ||
int a = !2; | ||
} |
4 changes: 4 additions & 0 deletions
4
SocietalConstructionToolTests/TestFiles/CompilerTests/ExpressionUnaryMinus.sct
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,4 @@ | ||
function Setup() -> void { | ||
int a = 4; | ||
a = -a; | ||
} |
4 changes: 4 additions & 0 deletions
4
SocietalConstructionToolTests/TestFiles/CompilerTests/IntTofloat.Sct
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,4 @@ | ||
function Setup() -> void { | ||
float x = 7; | ||
x = 9; | ||
} |
4 changes: 4 additions & 0 deletions
4
SocietalConstructionToolTests/TestFiles/CompilerTests/NoBreakReturn.sct
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,4 @@ | ||
function Setup() -> void { | ||
int x = 2; | ||
x = x + 2; | ||
} |
10 changes: 10 additions & 0 deletions
10
SocietalConstructionToolTests/TestFiles/CompilerTests/ParenthesisExpression.sct
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 @@ | ||
class Test(int id) { | ||
state Exiting { | ||
exit; | ||
} | ||
} | ||
|
||
function Setup() -> void { | ||
int a = (2-1); | ||
create Test::Exiting(id: a); | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/CompilerTests/PredefinedFunctions.sct
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,12 @@ | ||
class Citizen(int townId) { | ||
state Child { | ||
enter Child; | ||
} | ||
} | ||
|
||
function Setup() -> void { | ||
int x = count(Citizen::Child(townId: 5)); | ||
x = exists(Citizen::Child(townId: 5)); | ||
float y = rand(); | ||
seed(12345); | ||
} |
29 changes: 29 additions & 0 deletions
29
SocietalConstructionToolTests/TestFiles/CompilerTests/PredicateArgument.sct
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,29 @@ | ||
class Citizen(int townId) { | ||
state Child { | ||
enter Adult; | ||
} | ||
|
||
state Adult { | ||
enter Adult; | ||
} | ||
} | ||
|
||
function duplicate(Predicate p) -> int{ | ||
if (count(p) > 1) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
function Setup() -> void { | ||
Predicate x = Citizen::Child(townId:1); | ||
if (duplicate(x)) { | ||
create Exiter::Exiting(); | ||
} | ||
} | ||
|
||
class Exiter() { | ||
state Exiting { | ||
exit; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/CompilerTests/PredicateFunctions.sct
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,12 @@ | ||
function Setup() -> void { | ||
int a = count(TestAgent::A()); | ||
int b = count(TestAgent::?()); | ||
int c = exists(TestAgent::A()); | ||
int d = exists(TestAgent::?()); | ||
} | ||
|
||
class TestAgent() { | ||
state A { | ||
exit; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/CompilerTests/PredicateVariable.sct
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,12 @@ | ||
class Foo(int a, int b) { | ||
state Bar { | ||
enter Bar; | ||
} | ||
} | ||
|
||
function Setup() -> void { | ||
Predicate x = Foo::Bar(a:5); | ||
if(exists(x)){ | ||
int y = 5; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SocietalConstructionToolTests/TestFiles/CompilerTests/ReturnPredicate.sct
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,18 @@ | ||
class Citizen(int townId) { | ||
state Child { | ||
enter Adult; | ||
} | ||
|
||
state Adult { | ||
enter Adult; | ||
} | ||
} | ||
|
||
function getChildPredicate(int id) -> Predicate { | ||
return Citizen::Child(townId: id); | ||
} | ||
|
||
function Setup() -> void { | ||
int townId = 5; | ||
int childrenCount = count(getChildPredicate(townId)); | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementBreak.sct
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,5 @@ | ||
function Setup() -> void { | ||
while (1) { | ||
break; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementContinue.sct
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,5 @@ | ||
function Setup() -> void { | ||
while (1) { | ||
continue; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementIf.sct
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,5 @@ | ||
function Setup() -> void { | ||
if (1) { | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementIfElse.sct
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,7 @@ | ||
function Setup() -> void { | ||
if (1) { | ||
|
||
} else { | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementIfElseIf.sct
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 @@ | ||
function Setup() -> void { | ||
if (1) { | ||
|
||
} else if (3 < 2) { | ||
|
||
} | ||
|
||
if (1) { | ||
|
||
} else if (4 > 5) { | ||
|
||
} else { | ||
|
||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementReturn.sct
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,3 @@ | ||
function Setup() -> void { | ||
return; | ||
} |
5 changes: 5 additions & 0 deletions
5
SocietalConstructionToolTests/TestFiles/CompilerTests/StatementWhile.sct
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,5 @@ | ||
function Setup() -> void { | ||
while (1) { | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
SocietalConstructionToolTests/TestFiles/CompilerTests/TypeCast.sct
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,7 @@ | ||
function Setup() -> void { | ||
int x = (int) (2 / 2.0); | ||
float y = 2 / 2.0; | ||
int z = 1 / 2; | ||
float u = 1.0 / 2; | ||
int v = (int) (1.0 / 2); | ||
} |
3 changes: 3 additions & 0 deletions
3
SocietalConstructionToolTests/TestFiles/CompilerTests/WholeFloatLiteral.sct
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,3 @@ | ||
function Setup() -> void { | ||
float x = 2.0; | ||
} |