aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-08-17 10:35:47 +0100
committerLouis Pilfold <louis@lpil.uk>2019-08-17 10:43:15 +0100
commitf90bd89adba09502b5a7ff188a910750257ef1b0 (patch)
tree10887e506df6ee671b41c2760c55cb14f72ddba4 /test
parent46ae58fb4bf6c3229ee96c842aff66087ba1aa26 (diff)
downloadgleam_stdlib-f90bd89adba09502b5a7ff188a910750257ef1b0.tar.gz
gleam_stdlib-f90bd89adba09502b5a7ff188a910750257ef1b0.zip
Update stdlib for new struct syntax
Diffstat (limited to 'test')
-rw-r--r--test/gleam/any_test.gleam32
-rw-r--r--test/gleam/list_test.gleam34
-rw-r--r--test/gleam/map_dict_test.gleam133
-rw-r--r--test/gleam/result_test.gleam4
-rw-r--r--test/gleam/tuple_test.gleam14
5 files changed, 119 insertions, 98 deletions
diff --git a/test/gleam/any_test.gleam b/test/gleam/any_test.gleam
index 7a968c2..5dda768 100644
--- a/test/gleam/any_test.gleam
+++ b/test/gleam/any_test.gleam
@@ -209,43 +209,43 @@ pub fn list_test() {
|> expect:is_error
}
-pub fn tuple_test() {
- {1, []}
+pub fn struct2_test() {
+ struct(1, [])
|> any:from
- |> any:tuple
- |> expect:equal(_, Ok({any:from(1), any:from([])}))
+ |> any:struct2
+ |> expect:equal(_, Ok(struct(any:from(1), any:from([]))))
- {"ok", "ok"}
+ struct("ok", "ok")
|> any:from
- |> any:tuple
- |> expect:equal(_, Ok({any:from("ok"), any:from("ok")}))
+ |> any:struct2
+ |> expect:equal(_, Ok(struct(any:from("ok"), any:from("ok"))))
- {1}
+ struct(1)
|> any:from
- |> any:tuple
+ |> any:struct2
|> expect:is_error
- {1, 2, 3}
+ struct(1, 2, 3)
|> any:from
- |> any:tuple
+ |> any:struct2
|> expect:is_error
- {1, 2.0}
+ struct(1, 2.0)
|> any:from
- |> any:tuple
+ |> any:struct2
|> result:then(_, fn(x) {
x
|> tuple:first
|> any:int
- |> result:map(_, fn(f) { {f, tuple:second(x)} })
+ |> result:map(_, fn(f) { struct(f, tuple:second(x)) })
})
|> result:then(_, fn(x) {
x
|> tuple:second
|> any:float
- |> result:map(_, fn(f) { {tuple:first(x), f} })
+ |> result:map(_, fn(f) { struct(tuple:first(x), f) })
})
- |> expect:equal(_, Ok({1, 2.0}))
+ |> expect:equal(_, Ok(struct(1, 2.0)))
}
pub fn field_test() {
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index bb9168a..9710574 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -196,13 +196,13 @@ pub fn zip_test() {
|> expect:equal(_, [])
list:zip([1, 2, 3], [4, 5, 6])
- |> expect:equal(_, [{1, 4}, {2, 5}, {3, 6}])
+ |> expect:equal(_, [struct(1, 4), struct(2, 5), struct(3, 6)])
list:zip([5, 6], [1, 2, 3])
- |> expect:equal(_, [{5, 1}, {6, 2}])
+ |> expect:equal(_, [struct(5, 1), struct(6, 2)])
list:zip([5, 6, 7], [1, 2])
- |> expect:equal(_, [{5, 1}, {6, 2}])
+ |> expect:equal(_, [struct(5, 1), struct(6, 2)])
}
pub fn strict_zip_test() {
@@ -213,7 +213,7 @@ pub fn strict_zip_test() {
|> expect:is_error
list:strict_zip([1, 2, 3], [4, 5, 6])
- |> expect:equal(_, Ok([{1, 4}, {2, 5}, {3, 6}]))
+ |> expect:equal(_, Ok([struct(1, 4), struct(2, 5), struct(3, 6)]))
list:strict_zip([5, 6], [1, 2, 3])
|> expect:is_error
@@ -277,8 +277,8 @@ pub fn sort_test() {
}
pub fn index_map_test() {
- list:index_map([3, 4, 5], fn(i, x) { {i, x} })
- |> expect:equal(_, [{0, 3}, {1, 4}, {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))
@@ -323,37 +323,37 @@ pub fn repeat_test() {
pub fn split_test() {
list:split([], 0)
- |> expect:equal(_, {[], []})
+ |> expect:equal(_, struct([], []))
list:split([0, 1, 2, 3, 4], 0)
- |> expect:equal(_, {[], [0, 1, 2, 3, 4]})
+ |> expect:equal(_, struct([], [0, 1, 2, 3, 4]))
list:split([0, 1, 2, 3, 4], -2)
- |> expect:equal(_, {[], [0, 1, 2, 3, 4]})
+ |> expect:equal(_, struct([], [0, 1, 2, 3, 4]))
list:split([0, 1, 2, 3, 4], 1)
- |> expect:equal(_, {[0], [1, 2, 3, 4]})
+ |> expect:equal(_, struct([0], [1, 2, 3, 4]))
list:split([0, 1, 2, 3, 4], 3)
- |> expect:equal(_, {[0, 1, 2], [3, 4]})
+ |> expect:equal(_, struct([0, 1, 2], [3, 4]))
list:split([0, 1, 2, 3, 4], 9)
- |> expect:equal(_, {[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(_, {[], []})
+ |> expect:equal(_, struct([], []))
list:split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 })
- |> expect:equal(_, {[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(_, {[], [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(_, {[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(_, {[], [1, 2, 3, 4, 5]})
+ |> expect:equal(_, struct([], [1, 2, 3, 4, 5]))
}
diff --git a/test/gleam/map_dict_test.gleam b/test/gleam/map_dict_test.gleam
index 778838c..2b7dbdb 100644
--- a/test/gleam/map_dict_test.gleam
+++ b/test/gleam/map_dict_test.gleam
@@ -4,8 +4,8 @@ import gleam/map_dict
pub fn from_list_test() {
[
- {4, 0},
- {1, 0},
+ struct(4, 0),
+ struct(1, 0),
]
|> map_dict:from_list
|> map_dict:size
@@ -19,23 +19,23 @@ pub fn has_key_test() {
|> expect:false
[
- {1, 0},
+ struct(1, 0),
]
|> map_dict:from_list
|> map_dict:has_key(_, 1)
|> expect:true
[
- {4, 0},
- {1, 0},
+ struct(4, 0),
+ struct(1, 0),
]
|> map_dict:from_list
|> map_dict:has_key(_, 1)
|> expect:true
[
- {4, 0},
- {1, 0},
+ struct(4, 0),
+ struct(1, 0),
]
|> map_dict:from_list
|> map_dict:has_key(_, 0)
@@ -54,8 +54,8 @@ pub fn new_test() {
pub fn fetch_test() {
let proplist = [
- {4, 0},
- {1, 1},
+ struct(4, 0),
+ struct(1, 1),
]
let m = map_dict:from_list(proplist)
@@ -77,25 +77,33 @@ pub fn put_test() {
|> map_dict:put(_, "a", 0)
|> map_dict:put(_, "b", 1)
|> map_dict:put(_, "c", 2)
- |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}]))
+ |> expect:equal(_, map_dict:from_list([
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ ]))
}
pub fn map_values_test() {
[
- {1, 0},
- {2, 1},
- {3, 2},
+ struct(1, 0),
+ struct(2, 1),
+ struct(3, 2),
]
|> map_dict:from_list
|> map_dict:map_values(_, fn(k, v) { k + v })
- |> expect:equal(_, map_dict:from_list([{1, 1}, {2, 3}, {3, 5}]))
+ |> expect:equal(_, map_dict:from_list([
+ struct(1, 1),
+ struct(2, 3),
+ struct(3, 5),
+ ]))
}
pub fn keys_test() {
[
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map_dict:from_list
|> map_dict:keys
@@ -104,9 +112,9 @@ pub fn keys_test() {
pub fn values_test() {
[
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map_dict:from_list
|> map_dict:values
@@ -115,72 +123,72 @@ pub fn values_test() {
pub fn take_test() {
[
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map_dict:from_list
|> map_dict:take(_, ["a", "b", "d"])
- |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}]))
+ |> expect:equal(_, map_dict:from_list([struct("a", 0), struct("b", 1)]))
}
pub fn drop_test() {
[
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map_dict:from_list
|> map_dict:drop(_, ["a", "b", "d"])
- |> expect:equal(_, map_dict:from_list([{"c", 2}]))
+ |> expect:equal(_, map_dict:from_list([struct("c", 2)]))
}
pub fn merge_test() {
let a = map_dict:from_list([
- {"a", 2},
- {"c", 4},
- {"d", 3},
+ struct("a", 2),
+ struct("c", 4),
+ struct("d", 3),
])
let b = map_dict:from_list([
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
map_dict:merge(a, b)
|> expect:equal(_, map_dict:from_list([
- {"a", 0},
- {"b", 1},
- {"c", 2},
- {"d", 3},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
]))
map_dict:merge(b, a)
|> expect:equal(_, map_dict:from_list([
- {"a", 2},
- {"b", 1},
- {"c", 4},
- {"d", 3},
+ struct("a", 2),
+ struct("b", 1),
+ struct("c", 4),
+ struct("d", 3),
]))
}
pub fn delete_test() {
[
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
]
|> map_dict:from_list
|> map_dict:delete(_, "a")
|> map_dict:delete(_, "d")
- |> expect:equal(_, map_dict:from_list([{"b", 1}, {"c", 2}]))
+ |> expect:equal(_, map_dict:from_list([struct("b", 1), struct("c", 2)]))
}
pub fn update_test() {
let dict = map_dict:from_list([
- {"a", 0},
- {"b", 1},
- {"c", 2},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
])
let inc_or_zero = fn(x) {
@@ -192,23 +200,36 @@ pub fn update_test() {
dict
|> map_dict:update(_, "a", inc_or_zero)
- |> expect:equal(_, map_dict:from_list([{"a", 1}, {"b", 1}, {"c", 2}]))
+ |> expect:equal(_, map_dict:from_list([
+ struct("a", 1),
+ struct("b", 1),
+ struct("c", 2),
+ ]))
dict
|> map_dict:update(_, "b", inc_or_zero)
- |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 2}, {"c", 2}]))
+ |> expect:equal(_, map_dict:from_list([
+ struct("a", 0),
+ struct("b", 2),
+ struct("c", 2),
+ ]))
dict
|> map_dict:update(_, "z", inc_or_zero)
- |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}, {"z", 0}]))
+ |> expect:equal(_, map_dict:from_list([
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("z", 0),
+ ]))
}
pub fn fold_test() {
let dict = map_dict:from_list([
- {"a", 0},
- {"b", 1},
- {"c", 2},
- {"d", 3},
+ struct("a", 0),
+ struct("b", 1),
+ struct("c", 2),
+ struct("d", 3),
])
let add = fn(_, v, acc) {
diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam
index 1eb241f..c513665 100644
--- a/test/gleam/result_test.gleam
+++ b/test/gleam/result_test.gleam
@@ -37,8 +37,8 @@ pub fn map_error_test() {
|> expect:equal(_, Ok(1))
Error(1)
- |> result:map_error(_, fn(x) { {"ok", x + 1} })
- |> expect:equal(_, Error({"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/tuple_test.gleam b/test/gleam/tuple_test.gleam
index a5530e7..398967b 100644
--- a/test/gleam/tuple_test.gleam
+++ b/test/gleam/tuple_test.gleam
@@ -3,32 +3,32 @@ import gleam/tuple
pub fn new_test() {
tuple:new(1, 2)
- |> expect:equal(_, {1, 2})
+ |> expect:equal(_, struct(1, 2))
tuple:new(2, "3")
- |> expect:equal(_, {2, "3"})
+ |> expect:equal(_, struct(2, "3"))
}
pub fn first_test() {
- {1, 2}
+ struct(1, 2)
|> tuple:first
|> expect:equal(_, 1)
}
pub fn second_test() {
- {1, 2}
+ struct(1, 2)
|> tuple:second
|> expect:equal(_, 2)
}
pub fn swap_test() {
- {1, "2"}
+ struct(1, "2")
|> tuple:swap
- |> expect:equal(_, {"2", 1})
+ |> expect:equal(_, struct("2", 1))
}
pub fn fetch_test() {
- let proplist = [{0, "1"}, {1, "2"}]
+ let proplist = [struct(0, "1"), struct(1, "2")]
proplist
|> tuple:fetch(_, 0)