gluon 0.18.2

A static, type inferred programming language for application embedding
Documentation
let prelude @ { Eq, Show } = import! std.prelude
let { (<|) } = import! std.function
let int = import! std.int
let option @ { Option } = import! std.option
let string = import! std.string
let { (<>) } = import! std.prelude
let { Test, run, assert, assert_eq, test, group, ? }  = import! std.test
let map @ { empty, singleton, find, insert, to_list, keys, values, ? } = import! std.map
let { Applicative, (*>) } = import! std.applicative
let list @ { List, ? } = import! std.list

let { ? } = import! std.effect

let show_Entry : Show { key : String, value : Int } = {
    show = \e -> e.key <> int.show.show e.value
}

let eq_Entry : Eq { key : String, value : Int } = {
    (==) = \l r -> l.key == r.key && l.value == r.value
}

let basic_tests =
    let test_map = singleton "test" 1 <> singleton "asd" 2 <> singleton "a" 3

    [
        test "find" <| \_ -> (assert_eq (find "test" test_map) (Some 1)
            *> assert_eq (find "asd" test_map) (Some 2)
            *> assert_eq (find "b" test_map) None
            *> assert_eq (find "test" (insert "test" 10 test_map)) (Some 10)
            *> assert_eq (find "test" test_map) (Some 1)
        ),
        test "to_list" <| \_ -> (assert_eq (to_list test_map) (list.of [{ key = "a", value = 3 },
                                                       { key = "asd", value = 2 },
                                                       { key = "test", value = 1 }])),
        test "keys" <| \_ -> (assert_eq (keys test_map) (list.of ["a", "asd", "test"])),
        test "values" <| \_ -> (assert_eq (values test_map) (list.of [3, 2, 1])),
        test "append" <| \_ -> (assert_eq (to_list (test_map <> empty)) (to_list test_map)),
        test "append" <| \_ -> (assert_eq (to_list (empty <> test_map)) (to_list test_map)),
    ]

let append_tests =
    let test_map1 = singleton "a" 1 <> singleton "b" 2 <> singleton "c" 3
    let test_map2 = singleton "+" 1 <> (singleton "-" 2 <> singleton "*" 3)
    assert_eq (find "b" test_map1) (Some 2)
        *> assert_eq (find "*" test_map2) (Some 3)

group "map" [group "basic" basic_tests, test "append" <| \_ -> append_tests]