Enforce newline after assignment / clause.

This leads to more consistent formatting across entire Aiken programs.
  Before that commit, only long expressions would be formatted on a
  newline, causing non-consistent formatting and additional reading
  barrier when looking at source code.

  Programs also now take more vertical space, which is better for more
  friendly diffing in version control systems (especially git).
This commit is contained in:
KtorZ
2023-03-16 19:42:57 +01:00
parent bf9297efcf
commit 20f5baffa7
60 changed files with 998 additions and 548 deletions

View File

@@ -15,9 +15,12 @@ pub type MerkleTree {
pub fn root_hash(t: MerkleTree) -> Hash<Sha2_256, ByteArray> {
when t is {
Empty -> #""
Leaf { hash, .. } -> hash
Node { hash, .. } -> hash
Empty ->
#""
Leaf { hash, .. } ->
hash
Node { hash, .. } ->
hash
}
}
@@ -27,9 +30,12 @@ pub fn is_equal(a: MerkleTree, b: MerkleTree) -> Bool {
pub fn size(t: MerkleTree) -> Int {
when t is {
Empty -> 0
Leaf{..} -> 1
Node { left, right, .. } -> size(left) + size(right)
Empty ->
0
Leaf{..} ->
1
Node { left, right, .. } ->
size(left) + size(right)
}
}
@@ -43,27 +49,33 @@ pub fn from_list(items0: List<ByteArray>) -> MerkleTree {
fn do_from_list(items: List<ByteArray>, len: Int) -> MerkleTree {
when items is {
[] -> Empty
[value] -> Leaf { hash: sha2_256(value), value }
[] ->
Empty
[value] ->
Leaf { hash: sha2_256(value), value }
all -> {
let cutoff: Int = len / 2
let cutoff: Int =
len / 2
let left =
all
|> list.take(cutoff)
|> do_from_list(cutoff)
|> list.take(cutoff)
|> do_from_list(cutoff)
let right =
all
|> list.drop(cutoff)
|> do_from_list(len - cutoff)
let hash = combine_hash(root_hash(left), root_hash(right))
|> list.drop(cutoff)
|> do_from_list(len - cutoff)
let hash =
combine_hash(root_hash(left), root_hash(right))
Node { hash, left, right }
}
}
}
test foo() {
let items = [#"aa", #"bb", #"cc"]
let mt = from_list(items)
let items =
[#"aa", #"bb", #"cc"]
let mt =
from_list(items)
size(mt) == 3
}
@@ -72,20 +84,24 @@ test some_test1() {
}
test intersection_3() {
let iv1 = between(0, 1)
let iv2 = strictly_between(1, 2)
let iv1 =
between(0, 1)
let iv2 =
strictly_between(1, 2)
intersection(iv1, iv2)
|> is_empty
|> is_empty
}
const fooz = #"666f6f"
const fooz =
#"666f6f"
const bar = #"626172"
const bar =
#"626172"
fn fixture_1() {
dict.new()
|> dict.insert(fooz, 42, bytearray.compare)
|> dict.insert(bar, 14, bytearray.compare)
|> dict.insert(fooz, 42, bytearray.compare)
|> dict.insert(bar, 14, bytearray.compare)
}
test union_1() {