From 7c8b5ade8b178d5a63443363db44eb60354ec56a Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Fri, 8 May 2026 14:56:03 +0200 Subject: [PATCH] test: add format test to all example files --- test/array/run.t | 91 ++++++++++++++++++++ test/char/run.t | 29 +++++++ test/component/run.t | 52 ++++++++++++ test/context/run.t | 63 ++++++++++++++ test/function/run.t | 102 +++++++++++++++++++++++ test/loop/run.t | 142 ++++++++++++++++++++++++++++++++ test/mutation/run.t | 27 ++++++ test/operators/run.t | 79 ++++++++++++++++++ test/optional_record_tags/run.t | 24 ++++++ test/portal/run.t | 40 +++++++++ test/record/run.t | 44 ++++++++++ test/slot/run.t | 116 ++++++++++++++++++++++++++ test/store/run.t | 64 ++++++++++++++ test/template/run.t | 46 +++++++++++ test/test/run.t | 21 +++++ 15 files changed, 940 insertions(+) diff --git a/test/array/run.t b/test/array/run.t index df9c83a..9904718 100644 --- a/test/array/run.t +++ b/test/array/run.t @@ -42,3 +42,94 @@ 12347 + + $ pincfmt ./data.pi + component C() { + use Base; + + let array = 0...3; + let new_array = array @ 4; + let new_array_2 = array @ 4 @ 5 @ 6; + + let merged_array = new_array @@ 5...7; + let merged_array_2 = new_array @@ 5...7 @@ [8, 9]; + + let merged_record = { + a: 1, + b: 2, + } @@ { + c: 3, + }; + let merged_record_2 = { + a: 1, + b: 2, + } @@ { + b: 3, + } @@ { + y: 8, + }; + + let nested_array = new_array @ (merged_array @ merged_record_2); + let index = 8; + + let partitioned = merged_array_2 |> Array.partition(fn (item) -> { item % 2 == 0 }); + let even = partitioned[0]; + let odd = partitioned[1]; + +
+ {array} + + {new_array} + + {new_array_2} + + {merged_array} + + {merged_array_2} + + {merged_record} + {merged_record_2} + + {nested_array[2 + 3 * 1][index]["y"]} + {nested_array[2 + 3 * 1][index].y} + + {even} + + {odd} + + {merged_array_2 |> Array.keep(fn (item) -> { item % 2 == 0 })} + + {if (merged_array_2 |> Array.find(fn (item) -> { item == 3 })) { + "FOUND" + } else { + "NOT FOUND" + }} + + {if (merged_array_2 |> Array.find(fn (item) -> { item == -10 })) { + "FOUND" + } else { + "NOT FOUND" + }} + + {even |> Array.every(fn (item) -> { item % 2 == 0 })} + {merged_array_2 |> Array.some(fn (item) -> { item % 2 == 0 })} + {merged_array_2 |> Array.every(fn (item) -> { item % 2 == 0 })} + {merged_array_2 |> Array.some(fn (item) -> { item < 0 })} + {Array.make(6) |> Array.map(fn (item) -> item + 1) |> Array.reduce( + 0, + fn (acc, item) -> item + acc, + )} + + {merged_array_2 |> Array.take_until(fn (item) -> item == 5)} + + {1...10 |> Array.slice(2, 5)} + + {["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] |> Array.chunk(3) |> Array.map( + fn (chunk) -> Array.join(chunk, ","), + ) |> Array.map(fn (item) ->
{item}
)} + + {[5, 1, 2, 3, 6, 3, 4, 7] |> Array.sort(fn (a, b) -> a - b)} + + {[1, 1, 2, 3, 4, 3, 4, 7] |> Array.unique} +
+ } diff --git a/test/char/run.t b/test/char/run.t index 246169f..78a3697 100644 --- a/test/char/run.t +++ b/test/char/run.t @@ -22,3 +22,32 @@ 😡 + $ pincfmt ./data.pi + component C() { + use Base; + + let char = 'c'; + +
+ String.uppercase_ascii("abcàäöüß"): {String.uppercase_ascii("abcàäöüß")} + String.lowercase_ascii("ABCÁÄÖÜß"): {String.lowercase_ascii("ABCÁÄÖÜß")} + String.capitalize_ascii("abc"): {String.capitalize_ascii("abc")} + String.capitalize_ascii("äöü"): {String.capitalize_ascii("äöü")} + + char: {char} + char + 1: {char + 1} + char < 32: {char < 32} + char > 32: {char > 32} + + {' ' + 1} + {' ' + 1} + {'\'} + {' + '} + {'''} + {' '} + {'©'} + {'ǿ'} + {'!' + 128512} +
+ } diff --git a/test/component/run.t b/test/component/run.t index 9811ed5..3da0628 100644 --- a/test/component/run.t +++ b/test/component/run.t @@ -55,3 +55,55 @@ } + + $ pincfmt ./Matrix.pi + component Matrix() { + let matrix = #Array(of: #Array(of: #Int)); + +
+ {for (row in matrix) { +
    + {for (col in row) { +
  • {col}
  • + }} +
+ }} +
+ } + + $ pincfmt ./Sub/SubComponent.pi + component HeadlineSecondary() { + let class? = #String; + + let tag? = #String :: fn (value) -> value |> Base.Fn.default("h3"); + + let data = #Record( + of: { + text: if (tag == "h2") #String else "No no no ... make h2 when you want text", + subheadline?: if (tag == "h2") #String, + }, + ); + + let class = "HeadlineSecondary $(class)"; + + let content = <> + {if (data.subheadline) } + {data.text} + ; + + if (tag == "h1") { +

{content}

+ } else if (tag == "h2") { +

{content}

+ } else if (tag == "h3") { +

{content}

+ } else if (tag == "h4") { +

{content}

+ } else if (tag == "h5") { +
{content}
+ } else if (tag == "h6") { +
{content}
+ } else { + "INVALID TAG!" + } + } diff --git a/test/context/run.t b/test/context/run.t index 6066aad..5c6cd3d 100644 --- a/test/context/run.t +++ b/test/context/run.t @@ -8,3 +8,66 @@

+ + $ pincfmt ./data.pi + component Component( + label: "Section", + icon: "/images/icons/group.svg", + group: "Structure", + ) { + #SetContext(key: "background", value: "grey") + +
+ + +
+ } + + $ pincfmt ./HeadlineSecondary.pi + component HeadlineSecondary() { + #SetContext(key: "test", value: "should never be displayed!") + + let class? = #String :: fn (value) -> if (!value) ""; + + let tag? = #String :: fn (value) -> if (!value) "h3"; + let data = { + text: #String, + subheadline?: #String, + }; + + let class = "HeadlineSecondary $(class)"; + + let content = <> + {if (data.subheadline) } + {data.text} + ; + + if (tag == "h1") { +

{content}

+ } else if (tag == "h2") { +

{content}

+ } else if (tag == "h3") { +

{content}

+ } else if (tag == "h4") { +

{content}

+ } else if (tag == "h5") { +
{content}
+ } else if (tag == "h6") { +
{content}
+ } else { + "INVALID TAG!" + } + } + + $ pincfmt ./SubComponent.pi + component SubComponent() { + let background = #GetContext; + let test? = #GetContext; + + let backgroundClass = if (background == "grey") "Sub--grey" else ""; + +
+

Faucibus mus velit ut iaculis cubilia taciti conubia, ad magna sem mattis tincidunt eleifend, egestas eget neque curae molestie donec. Magna ipsum netus euismod vitae justo dictum adipiscing lobortis, posuere tortor penatibus tempus laoreet habitant orci, turpis blandit nullam ornare fames nostra sed.

+

{test}

+
+ } diff --git a/test/function/run.t b/test/function/run.t index 42082e0..0be0cf2 100644 --- a/test/function/run.t +++ b/test/function/run.t @@ -21,3 +21,105 @@ Map Pipe: 14916 + + $ pincfmt ./data.pi + component Component() { + use C = Math.Constants; + + let max = fn (a, b) -> { + if (a > b) { + a + } else { + b + } + }; + + let min = fn (a, b) -> { + if (a < b) { + a + } else { + b + } + }; + + let until = 5; + let map = fn (array, f) -> { + for (el in array) { + if (min(el, until) == until) { + continue; + } + + f(el) + } + }; + + let add_curry = fn (a) -> { + fn (b) -> { + a + b + } + }; + + let is_even = fn (i) -> { + if (i == 0) { + true + } else { + is_odd(i - 1) + } + }; + + let is_odd = fn (i) -> { + if (i == 0) { + false + } else { + is_even(i - 1) + } + }; + +
+ max(1, 5) = {max(1, 5)} + min(1, 5) = {min(1, 5)} + add_curry(1)(5) = {add_curry(1)(5)} + Math.fibonacci(9) = {Math.fibonacci(9)} + Math.factorial(5) = {Math.factorial(5)} + is_even(10) = {is_even(10)} + is_odd(10) = {is_odd(10)} + + 1 |> max(5) |> Math.factorial = {1 |> max(5) |> Math.factorial} + 1 |> add_curry(5)() = {1 |> add_curry(5)()} + 5 |> Math.factorial = {5 |> Math.factorial} + + Math.Constants.pi = {Math.Constants.pi} + C.pi = {C.pi} + + Map: + {map(1...10, fn (item) -> item ** 2)} + + Map Pipe: + {1...10 |> map(fn (item) -> item ** 2)} +
+ } + + $ pincfmt ./library.pi + library Math() { + use Constants = Math__Constants; + + let fibonacci = fn (n) -> { + if (n <= 1) { + n + } else { + fibonacci(n - 1) + fibonacci(n - 2) + } + }; + + let factorial = fn (n) -> { + if (n <= 1) { + 1 + } else { + n * factorial(n - 1) + } + }; + } + + library Math__Constants() { + let pi = 3.1415; + } diff --git a/test/loop/run.t b/test/loop/run.t index e0d153e..f322d04 100644 --- a/test/loop/run.t +++ b/test/loop/run.t @@ -76,3 +76,145 @@ 012 + + $ pincfmt ./data.pi + component Component() { + + let max = 10; + + let array = 0..max; + + let string_array = ["one", "two", "three", "!"]; + + let null_value? = if (false) "something"; + +
+

EXCLUSIVE RANGES

+ + 0..10 + {for (i in 0..10) { +
{i}
+ }} + + 0..0 + {for (i in 0..0) { +
{i}
+ }} + + 0..1 + {for (i in 0..1) { +
{i}
+ }} + + 0..-1 + {for (i in 0..-1) { +
{i}
+ }} + + -10..10 + {for (i in -10..10) { +
{i}
+ }} + + 10..0 + {for (i in 10..0) { +
{i}
+ }} + + 0..10 reverse + {for (i in reverse 0..10) { +
{i}
+ }} + + +

INCLUSIVE RANGES

+ + 0...10 + {for (i in 0...10) { +
{i}
+ }} + + 0...0 + {for (i in 0...0) { +
{i}
+ }} + + 0...1 + {for (i in 0...1) { +
{i}
+ }} + + 0...-1 + {for (i in 0...-1) { +
{i}
+ }} + + -10...10 + {for (i in -10...10) { +
{i}
+ }} + + 10...0 + {for (i in 10...0) { +
{i}
+ }} + + 0...10 reverse + {for (i in reverse 0...10) { +
{i}
+ }} + + +

ITERABLES

+ + array + {for (i in array) { +
{i}
+ }} + + array reverse + {for (i in reverse array) { +
{i}
+ }} + + string + {for (c in "String!") { +
{c}
+ }} + + string reverse + {for (c in reverse "Sträinèg!") { +
{c}
+ }} + + string array + {for (index, s in string_array) { +
{index} {s}
+ }} + + null value + {for (s in null_value) { +
{s}
+ }} + + +

BREAK / CONTINUE

+ + {for (c in "String!") { + if (c == 'i') { + continue; + } + + c + }} + + {for (i in 0..5) { + if (i == 3) { + break; + } + + i + }} + +
+ } diff --git a/test/mutation/run.t b/test/mutation/run.t index 374ea51..049a6f3 100644 --- a/test/mutation/run.t +++ b/test/mutation/run.t @@ -5,3 +5,30 @@ print_c(): mutated print_d(): initial + + $ pincfmt ./data.pi + component Component() { + let mutable a = "initial"; + a := "mutated"; + + let mutable b = "initial"; + if (a == "mutated") { + b := "mutated"; + } + + let mutable c = "initial"; + let print_c = fn () -> c; + c := "mutated"; + + let mutable d = "initial"; + let print_d = fn () -> d; + let mutable d = "initial2"; + d := "mutated"; + +
+ a: {a} + b: {b} + print_c(): {print_c()} + print_d(): {print_d()} +
+ } diff --git a/test/operators/run.t b/test/operators/run.t index d572c1e..dcba770 100644 --- a/test/operators/run.t +++ b/test/operators/run.t @@ -75,3 +75,82 @@ (5 * 3) + 2 / 6 + 4 * 8 ** 10 = 4294967311.33 + + $ pincfmt ./data.pi + component Component() { +
+ ![1] = {![1]} + ![] = {![]} + !!"" = {!!""} + !true = {!true} + -1 = {-1} + -2.5 = {-2.5} + + true == true = {true == true} + true != true = {true != true} + true && true = {true && true} + true && false = {true && false} + true || false = {true || false} + false || false = {false || false} + true || true && false = {true || true && false} + false && true || true = {false && true || true} + + 1 == 1 = {1 == 1} + 1 == 2 = {1 == 2} + 1 > 2 = {1 > 2} + 1 < 2 = {1 < 2} + 1 <= 1 = {1 <= 1} + 2 <= 1 = {2 <= 1} + 1 >= 1 = {1 >= 1} + + [1] == [1] = {[1] == [1]} + [1] == [2] = {[1] == [2]} + [1, 2] >= [5] = {[1, 2] >= [5]} + [1] >= [1,2,3] = {[1] >= [1, 2, 3]} + + 1 + 1 = {1 + 1} + 1.3 + 1.5 = {1.3 + 1.5} + 1 + 1.2 = {1 + 1.2} + 2.73 + 3 = {2.73 + 3} + + 1 - 1 = {1 - 1} + 1.3 - 1.5 = {1.3 - 1.5} + 1 - 1.2 = {1 - 1.2} + 2.73 - 3 = {2.73 - 3} + + 1 * 1 = {1 * 1} + 1.3 * 1.5 = {1.3 * 1.5} + 1 * 1.2 = {1 * 1.2} + 2.73 * 3 = {2.73 * 3} + 10 * -1 = {10 * -1} + + 1 / 1 = {1 / 1} + 1.3 / 1.5 = {1.3 / 1.5} + 1 / 1.2 = {1 / 1.2} + 2.73 / 3 = {2.73 / 3} + + 3 ** 1 = {3 ** 1} + 3 ** 2 = {3 ** 2} + 3 ** 3 = {3 ** 3} + 2.73 ** 3 = {2.73 ** 3} + + "a" ++ "b" = {"a" ++ "b"} + "a" ++ "b" ++ "c" = {"a" ++ "b" ++ "c"} + + 5 % 2 = {5 % 2} + 5 % 3 = {5 % 3} + + 3 - 2 + 4 * -5 = {3 - 2 + 4 * -5} + 3 - -5 + 4 * 2 = {3 - -5 + 4 * 2} + -5 * 3 + 4 * 2 = {-5 * 3 + 4 * 2} + 2 + 3 * 5 = {2 + 3 * 5} + 5 * 3 + 2 = {5 * 3 + 2} + 2 ** 3 ** 2 = {2 ** 3 ** 2} + 2 ** 3 * 5 = {2 ** 3 * 5} + 3 * 5 ** 2 = {3 * 5 ** 2} + 5 * 3 + 2 / 6 + 4 * 8 ** 10 = {5 * 3 + 2 / 6 + 4 * 8 ** 10} + 5 * 3 + 2 / (6 + 4) * 8 ** 10 = {5 * 3 + 2 / (6 + 4) * 8 ** 10} + 5 * 3 + 2 / (6 + 4 * 8) ** 10 = {5 * 3 + 2 / (6 + 4 * 8) ** 10} + (5 * 3) + 2 / 6 + 4 * 8 ** 10 = {(5 * 3) + 2 / 6 + 4 * 8 ** 10} +
+ } diff --git a/test/optional_record_tags/run.t b/test/optional_record_tags/run.t index 1a6051e..5d11ca6 100644 --- a/test/optional_record_tags/run.t +++ b/test/optional_record_tags/run.t @@ -2,3 +2,27 @@
"lorem" & ""
+ $ pincfmt ./data.pi + page Docs() { + <> + + + } + + component Sub() { + let attributes = #Record( + of: { + bar: #String, + lorem?: #String(key: "foo"), + }, + ); + +
"{attributes.bar}" & "{attributes.lorem}"
+ } diff --git a/test/portal/run.t b/test/portal/run.t index 9f89e39..4f7f82d 100644 --- a/test/portal/run.t +++ b/test/portal/run.t @@ -7,3 +7,43 @@

LOREM!

Ipsum!

+ + $ pincfmt ./main.pi + component Main() { + #Portal(key: "stylesheets", push: ) + + + + +
+ + +
+ + + } + + component Head() { + let stylesheets = #CreatePortal :: Base.Array.unique; + + + {stylesheets} + + } + + component Section() { + #Portal(key: "stylesheets", push: ) + + let foo = #String; + let content = #Slot(key: ""); + +
{content}
+ } + + component Text() { + #Portal(key: "stylesheets", push: ) + + let text = #String; + +

{text}

+ } diff --git a/test/record/run.t b/test/record/run.t index 23530ab..6210867 100644 --- a/test/record/run.t +++ b/test/record/run.t @@ -9,3 +9,47 @@ 0149162536496481100 + $ pincfmt ./data.pi + component Component() { + + let record = { + a: 1, + b: "foo", + c: true, + d: 3.1415, + }; + + let record_dangling = { + a: 1, + b: "foo", + c: true, + d: 3.1415, + }; + + let record_nested = { + a: 1, + b: "foo", + c: true, + d: { + e: "123", + f: 321, + g: for (i in 0...10) { + i + }, + }, + }; + + let empty_record = {}; + +
+ {empty_record} + {record} + {record_nested.a} + {record_nested.d.f} + {record_nested.d.h.y} + + {for (el in record_nested.d.g) { + el ** 2 + }} +
+ } diff --git a/test/slot/run.t b/test/slot/run.t index bf274f6..2d39ba0 100644 --- a/test/slot/run.t +++ b/test/slot/run.t @@ -29,3 +29,119 @@ Child with tag `div` may not be used inside this #Slot. It has an empty array set as constrints, which leads to nothing being allowed to be placed inside. [1] + + $ pincfmt ./data.pi + component Component( + label: "Section", + icon: "/images/icons/group.svg", + group: "Structure", + ) { + let array = for (i in 0..10) { + { + i: i, + } + }; + let record = { + a: 10, + c: "Something", + }; + + +
Hello Default
+ +
I am not rendered!
+ + + + {if (record.a > 9) { + Yaaay! + }} + + {for (i in 0..record.a) { + Yaaay! {i} + }} +
+ } + + component ErrorComponent( + label: "Section", + icon: "/images/icons/group.svg", + group: "Structure", + ) { + +
Hello Default
+
+ } + + $ pincfmt ./SlotProvider.pi + component SlotProvider() { + let slot_default = #Slot(key: ""); + + let restricted = #Slot(max: 1, constraints: [SubComponent]); + + let multi = #Slot :: fn (els) -> for (el in els) { +
{el @@ { + class: "item", + }}
+ }; + + let slot_nothing = #Slot(key: "nothing", constraints: []); + +
+ {slot_default} + {restricted} + {multi} + {slot_nothing} +
+ } + + $ pincfmt ./SubComponent.pi + component SubComponent() { + let content = #String; + + let shouter = #String :: fn (val) -> if (val) val ++ "!!" else "NOTHING!!!"; + + let num = #Int :: fn (val) -> val ** 2; + + let array_things = #Array( + of: #Record( + of: { + i: #Int :: fn (i) -> i + 2, + }, + ), + ); + + let record = #Record( + of: { + a: #Int(default: 12) :: fn (val) -> if (val == 12) "NEEEEIN" else "JAP", + b?: #Boolean, + c: #String, + d: "Some Constant", + }, + ); + +
+ {content} + + {array_things |> Base.Array.map(fn (r) -> r.i)} + + {record.a} + {record.b} + {record.c} + {record.d} + + {shouter} +
+ } diff --git a/test/store/run.t b/test/store/run.t index 8b2e9a8..0463aa8 100644 --- a/test/store/run.t +++ b/test/store/run.t @@ -5,3 +5,67 @@ 42008Product A22130Product B + $ pincfmt ./stores.pi + store Settings(single: true) { + footerLinks: #Array( + of: #Record( + of: { + title: #String, + url: #String, + }, + ), + ), + contact: #Record( + of: { + phone: #String, + email: #String, + address: #String :: fn (v) -> v ++ " ... or am I??", + }, + ), + } + + store Products() { + title: #String, + code: #Int :: fn (v) -> v * 2, + } + + $ pincfmt ./StoreValueProvider.pi + component StoreValueProvider() { + let settings = { + footerLinks: [ + { + title: "Imprint", + url: "/imprint", + }, + ], + contact: { + phone: "+1 111 000 111", + email: "some@email.invalid", + address: "Somewhere in the World", + }, + }; + + let products = [ + { + title: "Product A", + code: 21004, + }, + { + title: "Product B", + code: 11065, + }, + ]; + + + } + + component StoreConsumer() { + let settings = #Store(id: Settings); + let products = #Store(id: Products); + +
+ {settings} + + {products} +
+ } diff --git a/test/template/run.t b/test/template/run.t index e4ab09c..6ab8758 100644 --- a/test/template/run.t +++ b/test/template/run.t @@ -26,3 +26,49 @@ + $ pincfmt ./data.pi + page Template( + label: "Page", + icon: "/images/icons/page.svg", + group: "pages", + ) { + let intro = true; + let name = if (intro) "String Template" else "World"; + let content = "Hello, $(name)!"; + + <> + + + + + + FOO + + + + + + + +
+
+ {if (intro) { + let foobar = "foo"; + if (foobar) { +
+ } else { + let barfoo = "3"; + + } + }} +
+ {content} +
+ +
+ + + + } diff --git a/test/test/run.t b/test/test/run.t index 3cbd3f7..24fe288 100644 --- a/test/test/run.t +++ b/test/test/run.t @@ -12,3 +12,24 @@

+ $ pincfmt ./data.pi + page Docs(label: "Docs", icon: "/images/icons/page-docs.svg") { + let fruits = ["apples", "oranges", "bannanas", "melons"]; + + <> + + <> +
+ +
    + {for (fruit in fruits) { +
  • {fruit}
  • + }} +
+

+ Aliqua in elit sunt in anim culpa nostrud elit. + Elit voluptate nisi laborum est eu esse non exercitation minim. + Nisi ea enim minim quis. +

+ + } -- 2.51.2