diff --git a/.github/workflows/job_junit_test.yml b/.github/workflows/job_junit_test.yml new file mode 100644 index 0000000..315c08c --- /dev/null +++ b/.github/workflows/job_junit_test.yml @@ -0,0 +1,26 @@ +name: Test debug + +on: + workflow_call: + +jobs: + run_tests: + name: Testing debug variant + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Make gradlew executable + run: chmod +x ./gradlew + + - name: Execute Gradle command - testDebugUnitTest + run: ./gradlew testDebugUnitTest \ No newline at end of file diff --git a/.github/workflows/job_test_on_pr.yml b/.github/workflows/job_test_on_pr.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/com/jsaasta/froj/Froj.java b/src/com/jsaasta/froj/Froj.java index 9fe9614..223e3f3 100644 --- a/src/com/jsaasta/froj/Froj.java +++ b/src/com/jsaasta/froj/Froj.java @@ -26,7 +26,7 @@ public class Froj { } - private void runFile(String path) throws IOException { + public void runFile(String path) throws IOException { try { byte[] bytes = Files.readAllBytes(Paths.get(path)); run(new String(bytes, Charset.defaultCharset())); diff --git a/src/com/jsaasta/froj/Parser.java b/src/com/jsaasta/froj/Parser.java index 58f63fe..6d1642c 100644 --- a/src/com/jsaasta/froj/Parser.java +++ b/src/com/jsaasta/froj/Parser.java @@ -14,7 +14,7 @@ public class Parser { private final List tokens; private int current = 0; - Parser(List tokens) { + public Parser(List tokens) { this.tokens = tokens; } diff --git a/src/com/jsaasta/froj/RuntimeError.java b/src/com/jsaasta/froj/RuntimeError.java index ae86839..7c65d1c 100644 --- a/src/com/jsaasta/froj/RuntimeError.java +++ b/src/com/jsaasta/froj/RuntimeError.java @@ -1,7 +1,7 @@ package com.jsaasta.froj; public class RuntimeError extends RuntimeException { - final Token token; + public final Token token; public RuntimeError(Token token, String message) { super(message); diff --git a/src/com/jsaasta/froj/Scanner.java b/src/com/jsaasta/froj/Scanner.java index 0c2de93..6b80175 100644 --- a/src/com/jsaasta/froj/Scanner.java +++ b/src/com/jsaasta/froj/Scanner.java @@ -37,7 +37,7 @@ public class Scanner { private int line = 1; - Scanner(String source) { + public Scanner(String source) { this.source = source; } diff --git a/src/com/jsaasta/froj/Stmt.java b/src/com/jsaasta/froj/Stmt.java index b24cda2..366d17a 100644 --- a/src/com/jsaasta/froj/Stmt.java +++ b/src/com/jsaasta/froj/Stmt.java @@ -2,7 +2,7 @@ package com.jsaasta.froj; import java.util.List; -abstract class Stmt { +public abstract class Stmt { interface Visitor { R visitBlockStmt(Block stmt); diff --git a/src/com/jsaasta/froj/Token.java b/src/com/jsaasta/froj/Token.java index 296f2c6..eee146e 100644 --- a/src/com/jsaasta/froj/Token.java +++ b/src/com/jsaasta/froj/Token.java @@ -4,7 +4,7 @@ public class Token { public final TokenType type; public final String lexeme; public final Object literal; - final int line; + public final int line; public Token(TokenType type, String lexeme, Object literal, int line) { this.type = type; diff --git a/src/test/com/saasta/froj/FrojTest.java b/src/test/com/saasta/froj/FrojTest.java new file mode 100644 index 0000000..e4b0d78 --- /dev/null +++ b/src/test/com/saasta/froj/FrojTest.java @@ -0,0 +1,15 @@ +package test.com.saasta.froj; + +import com.jsaasta.froj.*; +import org.junit.Test; + +import java.io.IOException; + +public class FrojTest { + + @Test + public void testHelloWorld() throws IOException { + Froj froj = new Froj(); + froj.runFile("src/test/com/saasta/froj/froj_test.froj"); + } +} \ No newline at end of file diff --git a/src/test/com/saasta/froj/froj_test.froj b/src/test/com/saasta/froj/froj_test.froj new file mode 100644 index 0000000..320fdef --- /dev/null +++ b/src/test/com/saasta/froj/froj_test.froj @@ -0,0 +1,109 @@ +class HelloParent { + welcome(){ + print "Hello from Parent"; + } +} + +class HelloWorld < HelloParent { + init(helloString){ + this.helloString = helloString; + } + + welcome(){ + super.welcome(); + print this.helloString; + } +} + +var hello = "Hello World!"; +var helloWorldObject = HelloWorld(hello); +helloWorldObject.welcome(); + +// Or just a simple: +print "Hello World"; + +// ----------------------------------------- +class Test { + + init(aBoolean){ + if(aBoolean){ + print "in true"; + } else { + print "in false"; + } + } +} + +Test(false); +// ---------------------------------------- + +function controlFlowTest(someValue){ + if(someValue == "if"){ + print "in " + someValue; + } else if(someValue == "else if") { + print "in " + someValue; + } else { + print "in 'else', because the value was: " + someValue; + } +} + +controlFlowTest("if"); +controlFlowTest("else if"); +controlFlowTest("something else entirely"); + + +// ---------------------------------------- +function testWhile(){ + var a = 0; + while(a < 10){ + a = a+1; + } + return a; +} + +function testFor() { + var a = ""; + for(var i = 0; i < 10; i = i + 1){ + a = a + "a"; + } + return a; +} +print testWhile(); +print testFor(); + +// --------------------------------------- +function addTwoNumbers(a, b) { + return a + b; +} + +function testCallBack(aFunction){ + var a = 1; + var b = 2; + + return aFunction(a, b); +} + +print addTwoNumbers(4,5); +print testCallBack(addTwoNumbers); + +// --------------------------------------- + +class Person { + + init(name){ + this.name = name; + } + + myNameIs() { + print this.name; + } + +} +var janne = Person("Janne"); +janne.name = "Janne"; +janne.otherName = "Totally Not Janne"; +janne.myNameIs(); + +print janne.otherName; + +// --------------------------------------- \ No newline at end of file diff --git a/src/test/com/saasta/froj/stdlib/FrojStdlibTest.java b/src/test/com/saasta/froj/stdlib/FrojStdlibTest.java new file mode 100644 index 0000000..c094d1c --- /dev/null +++ b/src/test/com/saasta/froj/stdlib/FrojStdlibTest.java @@ -0,0 +1,18 @@ +package test.com.saasta.froj.stdlib; + +import com.jsaasta.froj.Froj; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +public class FrojStdlibTest { + + @Test + public void test_Stdlib_Clock() throws IOException { + Froj froj = new Froj(); + froj.runFile("src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj"); + } + +} diff --git a/src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj b/src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj new file mode 100644 index 0000000..2330bab --- /dev/null +++ b/src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj @@ -0,0 +1 @@ +clock(); \ No newline at end of file diff --git a/src/test/com/saasta/froj/stdlib/froj_stdlib_input.froj b/src/test/com/saasta/froj/stdlib/froj_stdlib_input.froj new file mode 100644 index 0000000..edf9c3d --- /dev/null +++ b/src/test/com/saasta/froj/stdlib/froj_stdlib_input.froj @@ -0,0 +1 @@ +input(); \ No newline at end of file