diff --git a/muscript/src/test/java/io/gitlab/jfronny/muscript/test/ValidExampleTest.java b/muscript/src/test/java/io/gitlab/jfronny/muscript/test/ValidExampleTest.java index f06f6e5..3945bfe 100644 --- a/muscript/src/test/java/io/gitlab/jfronny/muscript/test/ValidExampleTest.java +++ b/muscript/src/test/java/io/gitlab/jfronny/muscript/test/ValidExampleTest.java @@ -28,17 +28,13 @@ class ValidExampleTest { blockBuilder.append('\n').append(split[i]); } assertEquals("```", split[i++]); - assertEquals("
", split[i++]); - assertEquals("Result", split[i++]); - assertEquals("
", split[i++]); - assertEquals("", split[i++]); + assertEquals("Result:", split[i++]); assertEquals("```", split[i]); StringBuilder resultBuilder = new StringBuilder(); while (!split[++i].equals("```")) { resultBuilder.append('\n').append(split[i]); } i++; - assertEquals("
", split[i++]); final String block = blockBuilder.substring(1); final String expectedResult = resultBuilder.substring(1); String result = null; diff --git a/muscript/src/test/resources/example.md b/muscript/src/test/resources/example.md index 94a2ee9..cdc4447 100644 --- a/muscript/src/test/resources/example.md +++ b/muscript/src/test/resources/example.md @@ -24,7 +24,9 @@ Order of operation is also supported. The StdLib comes with additional constants and functions, namely: `PI`, `E`, `round`, `floor`, `ceil`, `abs`, `random` -For example: +
+Example +
```mu listOf( @@ -44,10 +46,7 @@ listOf( round(PI, 2) + floor(E) // round also accepts a second argument: precision, but it can be ommitted to round to a whole number ) ``` -
-Result -
- +Result: ``` [7, -3, 2, 8, 12, 2, 2, 1024, true, false, true, true, true, 5.1400] ``` @@ -60,6 +59,10 @@ XOR/XNOR are just your normal `!=`/`==` operators. Make sure not to use `||`, as that is the string concatenation operator, not OR. You can also use ternary conditional operators as you would in java. +
+Example +
+ ```mu listOf( 1 < 3 ? "this is correct" : "it is not", // if the condition is true, do the first thing. Else, do the second @@ -70,10 +73,7 @@ listOf( false | false ) ``` -
-Result -
- +Result: ``` [this is correct, false, false, true, true, false] ``` @@ -89,13 +89,14 @@ Equality operations are supported. The StdLib comes with some additional functions, namely: `toUpper`, `toLower`, `contains` and `replace` +
+Example +
+ ```mu 15 || "string one"::toUpper() || 'string Two'::toLower() || "example"::contains("thing") || "yxamply"::replace("y", "e") ``` -
-Result -
- +Result: ``` 15STRING ONEstring twofalseexample ``` @@ -111,6 +112,10 @@ In the following example, the objects `object` and `object2` is passed to the sc The StdLib also contains two objects, namely `date` and `time` which allow reading the current date and time. They also allow creating date/time objects and comparing them. +
+Example +
+ ```mu listOf( object2.valuename, // This is how you would normally do this @@ -126,10 +131,7 @@ listOf( date(2020, 5, 10) > date.today ) ``` -
-Result -
- +Result: ``` [subvalue, subvalue, subvalue, subvalue, One, 20, 64, some parameter, 2023-05-13, 23:55:10, false] ``` @@ -142,6 +144,10 @@ You can access their entries with `[]`, just like you would access fields for ob In function calls, you can use the spread operator (`...`) to use all elements of the list as parameters. The StdLib also comes with some additional functions, namely `len`, `isEmpty`, `concat`, `filter`, `map`, `flatMap`, `fold` and `forEach`. +
+Example +
+ ```mu listOf( len(listOf(1, 2, 3)), @@ -153,10 +159,7 @@ listOf( listOf(1, 2, 3, 4)::filter({n->n%2==0})::map({n->n/2}) // you can chain the additional functions for proper functional programming ) ``` -
-Result -
- +Result: ``` [3, true, [1, 2, 3, 4], 4, 23:55:10, 2, [1, 2]] ``` @@ -168,6 +171,10 @@ listOf( This means you can pass them to methods as arguments, store them in variables or do whatever else you feel like. A closure consists of a list of arguments (of which the last may be variadic) and some instructions. +
+Example +
+ ```mu someFunction = {n -> n * 2} // By assigning a closure to a variable, you get an equivalent to a normal java function @@ -208,10 +215,7 @@ listOf( someFunction2(1, 2, 3, 4) ) ``` -
-Result -
- +Result: ``` [2, some expression(s), 10, 7, 7, 2, 1, 1, 12, 24] ```