aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/gleam/any_test.gleam30
-rw-r--r--test/gleam/list_test.gleam42
-rw-r--r--test/gleam/map_test.gleam135
-rw-r--r--test/gleam/pair_test.gleam46
-rw-r--r--test/gleam/result_test.gleam5
-rw-r--r--test/gleam/triple_test.gleam32
6 files changed, 114 insertions, 176 deletions
diff --git a/test/gleam/any_test.gleam b/test/gleam/any_test.gleam
index 21a10b5..dc0c859 100644
--- a/test/gleam/any_test.gleam
+++ b/test/gleam/any_test.gleam
@@ -4,7 +4,6 @@ import gleam/list
import gleam/expect
import gleam/result
import gleam/map
-import gleam/pair.{Pair}
pub fn string_test() {
""
@@ -188,34 +187,7 @@ pub fn list_test() {
|> expect.is_error
}
-pub fn pair_test() {
- Pair(1, [])
- |> any.from
- |> any.pair
- |> expect.equal(_, Ok(Pair(any.from(1), any.from([]))))
-
- Pair("ok", "ok")
- |> any.from
- |> any.pair
- |> expect.equal(_, Ok(Pair(any.from("ok"), any.from("ok"))))
-
- Pair(1, 2.0)
- |> any.from
- |> any.pair
- |> result.then(_, fn(x) {
- x
- |> pair.first
- |> any.int
- |> result.map(_, fn(f) { Pair(f, pair.second(x)) })
- })
- |> result.then(_, fn(x) {
- x
- |> pair.second
- |> any.float
- |> result.map(_, fn(f) { Pair(pair.first(x), f) })
- })
- |> expect.equal(_, Ok(Pair(1, 2.0)))
-}
+// TODO: struct2
pub fn field_test() {
let Ok(ok_atom) = atom.from_string("ok")
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index fcab9ce..a24fe5b 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -3,7 +3,7 @@ import gleam/list
import gleam/int
import gleam/float
import gleam/string
-import gleam/pair.{Pair}
+import gleam/pair
pub fn length_test() {
list.length([])
@@ -222,13 +222,13 @@ pub fn zip_test() {
|> expect.equal(_, [])
list.zip([1, 2, 3], [4, 5, 6])
- |> expect.equal(_, [Pair(1, 4), Pair(2, 5), Pair(3, 6)])
+ |> expect.equal(_, [struct(1, 4), struct(2, 5), struct(3, 6)])
list.zip([5, 6], [1, 2, 3])
- |> expect.equal(_, [Pair(5, 1), Pair(6, 2)])
+ |> expect.equal(_, [struct(5, 1), struct(6, 2)])
list.zip([5, 6, 7], [1, 2])
- |> expect.equal(_, [Pair(5, 1), Pair(6, 2)])
+ |> expect.equal(_, [struct(5, 1), struct(6, 2)])
}
pub fn strict_zip_test() {
@@ -240,9 +240,9 @@ pub fn strict_zip_test() {
list.strict_zip([1, 2, 3], [4, 5, 6])
|> expect.equal(_, Ok([
- Pair(1, 4),
- Pair(2, 5),
- Pair(3, 6),
+ struct(1, 4),
+ struct(2, 5),
+ struct(3, 6),
]))
list.strict_zip([5, 6], [1, 2, 3])
@@ -307,8 +307,8 @@ pub fn sort_test() {
}
pub fn index_map_test() {
- list.index_map([3, 4, 5], fn(i, x) { Pair(i, x) })
- |> expect.equal(_, [Pair(0, 3), Pair(1, 4), Pair(2, 5)])
+ list.index_map([3, 4, 5], fn(i, x) { struct(i, x) })
+ |> expect.equal(_, [struct(0, 3), struct(1, 4), struct(2, 5)])
let f = fn(i, x) {
string.append(x, int.to_string(i))
@@ -353,44 +353,44 @@ pub fn repeat_test() {
pub fn split_test() {
list.split([], 0)
- |> expect.equal(_, Pair([], []))
+ |> expect.equal(_, struct([], []))
list.split([0, 1, 2, 3, 4], 0)
- |> expect.equal(_, Pair([], [0, 1, 2, 3, 4]))
+ |> expect.equal(_, struct([], [0, 1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], -2)
- |> expect.equal(_, Pair([], [0, 1, 2, 3, 4]))
+ |> expect.equal(_, struct([], [0, 1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], 1)
- |> expect.equal(_, Pair([0], [1, 2, 3, 4]))
+ |> expect.equal(_, struct([0], [1, 2, 3, 4]))
list.split([0, 1, 2, 3, 4], 3)
- |> expect.equal(_, Pair([0, 1, 2], [3, 4]))
+ |> expect.equal(_, struct([0, 1, 2], [3, 4]))
list.split([0, 1, 2, 3, 4], 9)
- |> expect.equal(_, Pair([0, 1, 2, 3, 4], []))
+ |> expect.equal(_, struct([0, 1, 2, 3, 4], []))
}
pub fn split_while_test() {
list.split_while([], fn(x) { x <= 5 })
- |> expect.equal(_, Pair([], []))
+ |> expect.equal(_, struct([], []))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 })
- |> expect.equal(_, Pair([1, 2, 3, 4, 5], []))
+ |> expect.equal(_, struct([1, 2, 3, 4, 5], []))
list.split_while([1, 2, 3, 4, 5], fn(x) { x == 2 })
- |> expect.equal(_, Pair([], [1, 2, 3, 4, 5]))
+ |> expect.equal(_, struct([], [1, 2, 3, 4, 5]))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 })
- |> expect.equal(_, Pair([1, 2, 3], [4, 5]))
+ |> expect.equal(_, struct([1, 2, 3], [4, 5]))
list.split_while([1, 2, 3, 4, 5], fn(x) { x <= -3 })
- |> expect.equal(_, Pair([], [1, 2, 3, 4, 5]))
+ |> expect.equal(_, struct([], [1, 2, 3, 4, 5]))
}
pub fn key_find_test() {
- let proplist = [Pair(0, "1"), Pair(1, "2")]
+ let proplist = [struct(0, "1"), struct(1, "2")]
proplist
|> list.key_find(_, 0)
diff --git a/test/gleam/map_test.gleam b/test/gleam/map_test.gleam
index 4c7b371..def91be 100644
--- a/test/gleam/map_test.gleam
+++ b/test/gleam/map_test.gleam
@@ -1,12 +1,11 @@
import gleam/string
import gleam/expect
import gleam/map
-import gleam/pair.{Pair}
pub fn from_list_test() {
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.size
@@ -20,23 +19,23 @@ pub fn has_key_test() {
|> expect.false
[
- Pair(1, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 1)
|> expect.true
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 1)
|> expect.true
[
- Pair(4, 0),
- Pair(1, 0),
+ struct(4, 0),
+ struct(1, 0),
]
|> map.from_list
|> map.has_key(_, 0)
@@ -55,8 +54,8 @@ pub fn new_test() {
pub fn get_test() {
let proplist = [
- Pair(4, 0),
- Pair(1, 1),
+ struct(4, 0),
+ struct(1, 1),
]
let m = map.from_list(proplist)
@@ -79,32 +78,32 @@ pub fn insert_test() {
|> map.insert(_, "b", 1)
|> map.insert(_, "c", 2)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]))
}
pub fn map_values_test() {
[
- Pair(1, 0),
- Pair(2, 1),
- Pair(3, 2),
+ struct(1, 0),
+ struct(2, 1),
+ struct(3, 2),
]
|> map.from_list
|> map.map_values(_, fn(k, v) { k + v })
|> expect.equal(_, map.from_list([
- Pair(1, 1),
- Pair(2, 3),
- Pair(3, 5),
+ struct(1, 1),
+ struct(2, 3),
+ struct(3, 5),
]))
}
pub fn keys_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.keys
@@ -113,9 +112,9 @@ pub fn keys_test() {
pub fn values_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.values
@@ -124,72 +123,72 @@ pub fn values_test() {
pub fn take_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.take(_, ["a", "b", "d"])
- |> expect.equal(_, map.from_list([Pair("a", 0), Pair("b", 1)]))
+ |> expect.equal(_, map.from_list([struct("a", 0), struct("b", 1)]))
}
pub fn drop_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.drop(_, ["a", "b", "d"])
- |> expect.equal(_, map.from_list([Pair("c", 2)]))
+ |> expect.equal(_, map.from_list([struct("c", 2)]))
}
pub fn merge_test() {
let a = map.from_list([
- Pair("a", 2),
- Pair("c", 4),
- Pair("d", 3),
+ struct("a", 2),
+ struct("c", 4),
+ struct("d", 3),
])
let b = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
map.merge(a, b)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("d", 3),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
]))
map.merge(b, a)
|> expect.equal(_, map.from_list([
- Pair("a", 2),
- Pair("b", 1),
- Pair("c", 4),
- Pair("d", 3),
+ struct("a", 2),
+ struct("b", 1),
+ struct("c", 4),
+ struct("d", 3),
]))
}
pub fn delete_test() {
[
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map.from_list
|> map.delete(_, "a")
|> map.delete(_, "d")
- |> expect.equal(_, map.from_list([Pair("b", 1), Pair("c", 2)]))
+ |> expect.equal(_, map.from_list([struct("b", 1), struct("c", 2)]))
}
pub fn update_test() {
let dict = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
let inc_or_zero = fn(x) {
@@ -202,35 +201,35 @@ pub fn update_test() {
dict
|> map.update(_, "a", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 1),
- Pair("b", 1),
- Pair("c", 2),
+ struct("a", 1),
+ struct("b", 1),
+ struct("c", 2),
]))
dict
|> map.update(_, "b", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 2),
- Pair("c", 2),
+ struct("a", 0),
+ struct("b", 2),
+ struct("c", 2),
]))
dict
|> map.update(_, "z", inc_or_zero)
|> expect.equal(_, map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("z", 0),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("z", 0),
]))
}
pub fn fold_test() {
let dict = map.from_list([
- Pair("a", 0),
- Pair("b", 1),
- Pair("c", 2),
- Pair("d", 3),
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
])
let add = fn(_, v, acc) {
diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam
index 4ec4f05..057c343 100644
--- a/test/gleam/pair_test.gleam
+++ b/test/gleam/pair_test.gleam
@@ -1,62 +1,62 @@
import gleam/expect
-import gleam/pair.{Pair}
+import gleam/pair
pub fn first_test() {
- Pair(1, 2)
+ struct(1, 2)
|> pair.first
|> expect.equal(_, 1)
- Pair("abc", [])
+ struct("abc", [])
|> pair.first
|> expect.equal(_, "abc")
}
pub fn second_test() {
- Pair(1, 2)
+ struct(1, 2)
|> pair.second
|> expect.equal(_, 2)
- Pair("abc", [])
+ struct("abc", [])
|> pair.second
|> expect.equal(_,[])
}
pub fn swap_test() {
- Pair(1, "2")
+ struct(1, "2")
|> pair.swap
- |> expect.equal(_, Pair("2", 1))
+ |> expect.equal(_, struct("2", 1))
}
pub fn map_first_test() {
let inc = fn(a) {
a + 1
}
- pair.map_first(Pair(1, 2), inc)
- |> expect.equal(_, Pair(2, 2))
+ pair.map_first(struct(1, 2), inc)
+ |> expect.equal(_, struct(2, 2))
- pair.map_first(Pair(8,2), inc)
- |> expect.equal(_, Pair(9, 2))
+ pair.map_first(struct(8,2), inc)
+ |> expect.equal(_, struct(9, 2))
- pair.map_first(Pair(0,-2), inc)
- |> expect.equal(_, Pair(1, -2))
+ pair.map_first(struct(0,-2), inc)
+ |> expect.equal(_, struct(1, -2))
- pair.map_first(Pair(-10, 20), inc)
- |> expect.equal(_, Pair(-9, 20))
+ pair.map_first(struct(-10, 20), inc)
+ |> expect.equal(_, struct(-9, 20))
}
pub fn map_second_test() {
let dec = fn(a) {
a - 1
}
- pair.map_second(Pair(1, 2), dec)
- |> expect.equal(_, Pair(1, 1))
+ pair.map_second(struct(1, 2), dec)
+ |> expect.equal(_, struct(1, 1))
- pair.map_second(Pair(8,2), dec)
- |> expect.equal(_, Pair(8, 1))
+ pair.map_second(struct(8,2), dec)
+ |> expect.equal(_, struct(8, 1))
- pair.map_second(Pair(0,-2), dec)
- |> expect.equal(_, Pair(0, -3))
+ pair.map_second(struct(0,-2), dec)
+ |> expect.equal(_, struct(0, -3))
- pair.map_second(Pair(-10, 20), dec)
- |> expect.equal(_, Pair(-10, 19))
+ pair.map_second(struct(-10, 20), dec)
+ |> expect.equal(_, struct(-10, 19))
}
diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam
index d28b622..10d2cf6 100644
--- a/test/gleam/result_test.gleam
+++ b/test/gleam/result_test.gleam
@@ -1,6 +1,5 @@
import gleam/expect
import gleam/result
-import gleam/pair.{Pair}
pub fn is_ok_test() {
result.is_ok(Ok(1))
@@ -38,8 +37,8 @@ pub fn map_error_test() {
|> expect.equal(_, Ok(1))
Error(1)
- |> result.map_error(_, fn(x) { Pair("ok", x + 1) })
- |> expect.equal(_, Error(Pair("ok", 2)))
+ |> result.map_error(_, fn(x) { struct("ok", x + 1) })
+ |> expect.equal(_, Error(struct("ok", 2)))
}
pub fn flatten_test() {
diff --git a/test/gleam/triple_test.gleam b/test/gleam/triple_test.gleam
deleted file mode 100644
index 53ac7d0..0000000
--- a/test/gleam/triple_test.gleam
+++ /dev/null
@@ -1,32 +0,0 @@
-import gleam/expect
-import gleam/triple.{Triple}
-
-pub fn first_test() {
- Triple(1, 2, 3)
- |> triple.first
- |> expect.equal(_, 1)
-
- Triple([], "abc", 3)
- |> triple.first
- |> expect.equal(_, [])
-}
-
-pub fn second_test() {
- Triple(1, 2, 3)
- |> triple.second
- |> expect.equal(_, 2)
-
- Triple([], "abc", 3)
- |> triple.second
- |> expect.equal(_, "abc")
-}
-
-pub fn third_test() {
- Triple(1, 2, 3)
- |> triple.third
- |> expect.equal(_, 3)
-
- Triple([], "abc", 3)
- |> triple.third
- |> expect.equal(_, 3)
-}