Skip to content

Commit

Permalink
Merge branch 'main' into issue-#228-refactor-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tot0p committed Feb 26, 2024
2 parents 029a8a8 + 9a7e232 commit 6d2642f
Show file tree
Hide file tree
Showing 24 changed files with 579 additions and 647 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test and coverage

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Run coverage
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Eclalang/Ecla
3 changes: 1 addition & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ on:
push:
branches:
- 'main'

jobs:
pre-build:
api:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
34 changes: 15 additions & 19 deletions DEMO/Release/brainfuck.ecla
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function interpret(code : string, debug : bool) {
var memory []int = [0,0,0,0,0];
var memoryPointer int = 0;
var codePointer int = 0;
var instruction string;
var instruction char;
var codeLen int = strLen(code);
while (codePointer < codeLen){
instruction = code[codePointer];
Expand All @@ -16,52 +16,52 @@ function interpret(code : string, debug : bool) {
console.println(" "+" "*memoryPointer+"^");
console.input("press enter to continue");
}
if (instruction == "+"){
if (instruction == '+'){
if (memory[memoryPointer] == 255){
memory[memoryPointer] = 0;
} else {
memory[memoryPointer] = memory[memoryPointer] + 1;
}
} else if (instruction == "-"){
} else if (instruction == '-'){
if (memory[memoryPointer] == 0){
memory[memoryPointer] = 255;
} else {
memory[memoryPointer] = memory[memoryPointer] - 1;
}
} else if (instruction == ">"){
} else if (instruction == '>'){
memoryPointer++;
if (memoryPointer >= intArrLen(memory)){
memory = memory + [0];
}
} else if (instruction == "<"){
} else if (instruction == '<'){
memoryPointer--;
} else if (instruction == "."){
} else if (instruction == '.'){
console.print(encoding.asciiToString([memory[memoryPointer]]));
} else if (instruction == ","){
} else if (instruction == ','){
var temp string = console.input("input: ");
var fChar string = temp[0];
var encoded []int = encoding.stringToAscii(fChar);
memory[memoryPointer] = encoded[0];
} else if (instruction == "["){
} else if (instruction == '['){
if (memory[memoryPointer] == 0){
var depth int = 1;
while (depth > 0){
codePointer++;
if (code[codePointer] == "["){
if (code[codePointer] == '['){
depth++;
} else if (code[codePointer] == "]"){
} else if (code[codePointer] == ']'){
depth--;
}
}
}
} else if (instruction == "]"){
} else if (instruction == ']'){
if (memory[memoryPointer] != 0){
var depth int = 1;
while (depth > 0){
codePointer--;
if (code[codePointer] == "]"){
if (code[codePointer] == ']'){
depth++;
} else if (code[codePointer] == "["){
} else if (code[codePointer] == '['){
depth--;
}
}
Expand Down Expand Up @@ -97,16 +97,12 @@ var NoDebug bool = false;
var Debug bool = true;

console.println(
"this is a the first program wrote using the ECLA programming language
it is a brainfuck interpreter
The next line should be HelloWorld!"
"this is a the first program wrote using the ECLA programming language\nit is a brainfuck interpreter\nThe next line should be HelloWorld!"
);
interpret("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++<<+++++++++++++++.>.+++.------.--------.>+.>.",NoDebug);

console.println(
"this is a the second program wrote using the ECLA programming language
it is a brainfuck interpreter
The next should outputs square numbers from 0 to 10000"
"this is a the second program wrote using the ECLA programming language\nit is a brainfuck interpreter\nThe next should outputs square numbers from 0 to 10000"
);

interpret("++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+>>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]<<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]",NoDebug);
Expand Down
2 changes: 1 addition & 1 deletion DEMO/Release/fibonacci.ecla
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ function Fibonacci(n : int) (int) {
console.print("Here is the 10th number in the Fibonacci sequence : ");
console.println(Fibonacci(10));
console.print("Here is the 20th number in the Fibonacci sequence : ");
console.println(Fibonacci(40));
console.println(Fibonacci(20));
2 changes: 1 addition & 1 deletion DEMO/Release/hangman.ecla
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "console";
var Game bool = true;

function PickRandomWord() (string) {
var Word string = "";F
var Word string = "";
var words []string = ["clavier","table"];
Word = words[1];
return Word;
Expand Down
1 change: 0 additions & 1 deletion DEMO/libDoc/json.ecla
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import "console";
import "json";
import "strings";

# Test function Marshal
function testMarshal() {
Expand Down
67 changes: 12 additions & 55 deletions docs/FR/Library/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ La librairie console est utilisée pour gérer ce qui est lié à la console.
## Index

- [Clear()](#clear)
- [Confirm(prompt string) bool](#confirm)
- [Input(args ...interface{})](#input)
- [InputFloat(prompt string)](#inputfloat)
- [InputInt(prompt string)](#inputint)
- [Input() string](#input)
- [InputFloat() float](#inputfloat)
- [InputInt() int](#inputint)
- [Print(args ...interface{})](#print)
- [Printf(format string, args ...interface{})](#printf)
- [PrintInColor(color string, args ...interface{})](#printincolor)
- [Println(args ...interface{})](#println)
- [ProgressBar(percent int)](#progressbar)

## Clear
```
Expand All @@ -32,28 +30,6 @@ function testClear() {
}
```

## Confirm
```
function confirm(prompt string) bool
```
> Obsolète
Récupère la confirmation de l'utilisateur

### Exemple :
```ecla
import "console";
function testConfirm() {
var check bool = console.confirm("Do you want to continue :");
if (check) {
console.println("You have confirmed.");
} else {
console.println("You have not confirmed.");
}
}
```

## Input
```
function input(args ...interface{})
Expand All @@ -65,14 +41,15 @@ Récupère l'entrée de l'utilisateur depuis la console
import "console";
function testInput() {
var input string = console.input("Enter your name : ");
console.print("Enter your name : ");
var input string = console.input();
console.println("Hello " + input + "!");
}
```

## InputFloat
```
function inputFloat(prompt string)
function inputFloat() float
```
Lit les floats en entrée

Expand All @@ -81,14 +58,15 @@ Lit les floats en entrée
import "console";
function testInputFloat() {
var input float = console.inputFloat("Enter a float : ");
console.print("Enter a float : ");
var input float = console.inputFloat();
console.println("You entered " + input + ".");
}
```

## InputInt
```
function inputInt(prompt string)
function inputInt() int
```
Lit les int en entrée

Expand All @@ -97,7 +75,8 @@ Lit les int en entrée
import "console";
function testInputInt() {
var input int = console.inputInt("Enter an int : ");
console.print("Enter an int : ");
var input int = console.inputInt();
console.println("You entered " + input + ".");
}
```
Expand Down Expand Up @@ -144,7 +123,7 @@ function printInColor(color string, args ...interface{})
import "console";
function testPrintInColor() {
console.printInColor("red", "Hello World!");
console.printInColor("\033[0;31m", "Hello World!");
}
```

Expand All @@ -163,25 +142,3 @@ function testPrintln() {
console.println("Hello", "user", "?");
}
```

## ProgressBar
```
function progressBar(percent int)
```
> Obsolète
Affiche une barre de progression

### Exemple :
```ecla
import "console";
import "time";
function testProgressBar() {
for (var i int = 0, i <= 100, i+= 10) {
console.progressBar(i);
time.sleep(1);
console.clear();
}
}
```
20 changes: 14 additions & 6 deletions docs/FR/Library/Json.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ La librairie Json implémente l'encodage et le décodage en JSON.

## Index

- [Marshal(content any) string](#marshal)
- [Unmarshal(content string) any](#unmarshal)
- [Marshal(content map[string]string | []map[string]string) string](#marshal)
- [Unmarshal(content string) map[string]string | []map[string]string](#unmarshal)

## Marshal
```
function marshal(content any) string
function marshal(content map[string]string | []map[string]string) string
```
Convertit n'importe quel type en JSON string
Convertit une map en JSON string

### Exemple :
```ecla
Expand All @@ -22,12 +22,16 @@ function testMarshal() {
var mapStr map[string]string = {"name": "Ecla", "members": "7", "language": "Golang"};
var str string = json.marshal(mapStr);
console.println(str);
var arrMap []map[string]string = [{"name": "Ecla", "members": "7", "language": "Golang"}, {"name": "Ecla", "members": "7", "language": "Golang"}];
str = json.marshal(arrMap);
console.println(str);
}
```

## Unmarshal
```
function unmarshal(content string) any
function unmarshal(content string) map[string]string | []map[string]string
```
Convertit un string JSON en n'importe quel type

Expand All @@ -37,8 +41,12 @@ import "console";
import "json";
function testUnmarshal() {
var str string = "{'name': 'Ecla', 'members': '7', 'language': 'Golang'}";
var str string = "{\"name\": \"Ecla\", \"members\": \"7\", \"language\": \"Golang\"}";
var obj map[string]string = json.unmarshal(str);
console.println(obj);
var strArr string = "[{\"name\": \"Ecla\", \"members\": \"7\", \"language\": \"Golang\"}, {\"name\": \"Test\", \"members\": \"12\", \"language\": \"Python\"}]";
var objArr []map[string]string = json.unmarshal(strArr);
console.println(objArr);
}
```
Loading

0 comments on commit 6d2642f

Please sign in to comment.