commit
984fd1c4f7
13 changed files with 176 additions and 6 deletions
26
.github/workflows/job_junit_test.yml
vendored
Normal file
26
.github/workflows/job_junit_test.yml
vendored
Normal file
|
@ -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
|
0
.github/workflows/job_test_on_pr.yml
vendored
Normal file
0
.github/workflows/job_test_on_pr.yml
vendored
Normal file
|
@ -26,7 +26,7 @@ public class Froj {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runFile(String path) throws IOException {
|
public void runFile(String path) throws IOException {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Files.readAllBytes(Paths.get(path));
|
byte[] bytes = Files.readAllBytes(Paths.get(path));
|
||||||
run(new String(bytes, Charset.defaultCharset()));
|
run(new String(bytes, Charset.defaultCharset()));
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class Parser {
|
||||||
private final List<Token> tokens;
|
private final List<Token> tokens;
|
||||||
private int current = 0;
|
private int current = 0;
|
||||||
|
|
||||||
Parser(List<Token> tokens) {
|
public Parser(List<Token> tokens) {
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.jsaasta.froj;
|
package com.jsaasta.froj;
|
||||||
|
|
||||||
public class RuntimeError extends RuntimeException {
|
public class RuntimeError extends RuntimeException {
|
||||||
final Token token;
|
public final Token token;
|
||||||
|
|
||||||
public RuntimeError(Token token, String message) {
|
public RuntimeError(Token token, String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class Scanner {
|
||||||
private int line = 1;
|
private int line = 1;
|
||||||
|
|
||||||
|
|
||||||
Scanner(String source) {
|
public Scanner(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jsaasta.froj;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
abstract class Stmt {
|
public abstract class Stmt {
|
||||||
interface Visitor<R> {
|
interface Visitor<R> {
|
||||||
R visitBlockStmt(Block stmt);
|
R visitBlockStmt(Block stmt);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ public class Token {
|
||||||
public final TokenType type;
|
public final TokenType type;
|
||||||
public final String lexeme;
|
public final String lexeme;
|
||||||
public final Object literal;
|
public final Object literal;
|
||||||
final int line;
|
public final int line;
|
||||||
|
|
||||||
public Token(TokenType type, String lexeme, Object literal, int line) {
|
public Token(TokenType type, String lexeme, Object literal, int line) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
15
src/test/com/saasta/froj/FrojTest.java
Normal file
15
src/test/com/saasta/froj/FrojTest.java
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
109
src/test/com/saasta/froj/froj_test.froj
Normal file
109
src/test/com/saasta/froj/froj_test.froj
Normal file
|
@ -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;
|
||||||
|
|
||||||
|
// ---------------------------------------
|
18
src/test/com/saasta/froj/stdlib/FrojStdlibTest.java
Normal file
18
src/test/com/saasta/froj/stdlib/FrojStdlibTest.java
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj
Normal file
1
src/test/com/saasta/froj/stdlib/froj_stdlib_clock.froj
Normal file
|
@ -0,0 +1 @@
|
||||||
|
clock();
|
1
src/test/com/saasta/froj/stdlib/froj_stdlib_input.froj
Normal file
1
src/test/com/saasta/froj/stdlib/froj_stdlib_input.froj
Normal file
|
@ -0,0 +1 @@
|
||||||
|
input();
|
Loading…
Reference in a new issue