make types more explicit

This commit is contained in:
Tom Dohrmann 2022-02-25 13:02:11 +01:00
parent 23f2976411
commit 868316abb8
2 changed files with 113 additions and 44 deletions

View file

@ -28,7 +28,7 @@ fn roc_list_construction() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn empty_list_literal() { fn empty_list_literal() {
assert_evals_to!("[]", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!("[]", RocList::<i64>::from_slice(&[]), RocList<i64>);
} }
#[test] #[test]
@ -136,7 +136,7 @@ fn bool_list_literal() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn variously_sized_list_literals() { fn variously_sized_list_literals() {
assert_evals_to!("[]", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!("[]", RocList::<i64>::from_slice(&[]), RocList<i64>);
assert_evals_to!("[1]", RocList::from_slice(&[1]), RocList<i64>); assert_evals_to!("[1]", RocList::from_slice(&[1]), RocList<i64>);
assert_evals_to!("[1, 2]", RocList::from_slice(&[1, 2]), RocList<i64>); assert_evals_to!("[1, 2]", RocList::from_slice(&[1, 2]), RocList<i64>);
assert_evals_to!("[1, 2, 3]", RocList::from_slice(&[1, 2, 3]), RocList<i64>); assert_evals_to!("[1, 2, 3]", RocList::from_slice(&[1, 2, 3]), RocList<i64>);
@ -177,12 +177,12 @@ fn list_take_first() {
); );
assert_evals_to!( assert_evals_to!(
"List.takeFirst [1, 2, 3] 0", "List.takeFirst [1, 2, 3] 0",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
"List.takeFirst [] 1", "List.takeFirst [] 1",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
@ -202,7 +202,7 @@ fn list_take_last() {
); );
assert_evals_to!( assert_evals_to!(
"List.takeLast [1, 2, 3] 0", "List.takeLast [1, 2, 3] 0",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!("List.takeLast [] 1", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!("List.takeLast [] 1", RocList::from_slice(&[]), RocList<i64>);
@ -233,17 +233,17 @@ fn list_sublist() {
); );
assert_evals_to!( assert_evals_to!(
"List.sublist [1, 2, 3] { start: 3 , len: 2 } ", "List.sublist [1, 2, 3] { start: 3 , len: 2 } ",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
"List.sublist [] { start: 1 , len: 1 } ", "List.sublist [] { start: 1 , len: 1 } ",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
"List.sublist [1, 2, 3] { start: 1 , len: 0 } ", "List.sublist [1, 2, 3] { start: 1 , len: 0 } ",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
@ -261,7 +261,7 @@ fn list_split() {
list = List.split [1, 2, 3] 0 list = List.split [1, 2, 3] 0
list.before list.before
"#, "#,
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
@ -280,17 +280,26 @@ fn list_split() {
); );
assert_evals_to!( assert_evals_to!(
"List.split [1, 2, 3] 3", "List.split [1, 2, 3] 3",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),), (
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,) (RocList<i64>, RocList<i64>,)
); );
assert_evals_to!( assert_evals_to!(
"List.split [1, 2, 3] 4", "List.split [1, 2, 3] 4",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),), (
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,) (RocList<i64>, RocList<i64>,)
); );
assert_evals_to!( assert_evals_to!(
"List.split [] 1", "List.split [] 1",
(RocList::from_slice(&[]), RocList::from_slice(&[]),), (
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
),
(RocList<i64>, RocList<i64>,) (RocList<i64>, RocList<i64>,)
); );
} }
@ -302,8 +311,16 @@ fn list_drop() {
RocList::from_slice(&[3]), RocList::from_slice(&[3]),
RocList<i64> RocList<i64>
); );
assert_evals_to!("List.drop [] 1", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
assert_evals_to!("List.drop [1,2] 5", RocList::from_slice(&[]), RocList<i64>); "List.drop [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.drop [1,2] 5",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -319,8 +336,16 @@ fn list_drop_at() {
RocList::from_slice(&[0, 0, 0]), RocList::from_slice(&[0, 0, 0]),
RocList<i64> RocList<i64>
); );
assert_evals_to!("List.dropAt [] 1", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
assert_evals_to!("List.dropAt [0] 0", RocList::from_slice(&[]), RocList<i64>); "List.dropAt [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropAt [0] 0",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -341,7 +366,7 @@ fn list_intersperse() {
List.intersperse [] 1 List.intersperse [] 1
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -380,7 +405,7 @@ fn list_drop_if_empty_list_of_int() {
List.dropIf empty \_ -> True List.dropIf empty \_ -> True
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -397,7 +422,7 @@ fn list_drop_if_empty_list() {
List.dropIf [] alwaysTrue List.dropIf [] alwaysTrue
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -425,7 +450,7 @@ fn list_drop_if_always_true_for_non_empty_list() {
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> True) List.dropIf [1,2,3,4,5,6,7,8] (\_ -> True)
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -466,8 +491,16 @@ fn list_drop_last() {
RocList::from_slice(&[1, 2]), RocList::from_slice(&[1, 2]),
RocList<i64> RocList<i64>
); );
assert_evals_to!("List.dropLast []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
assert_evals_to!("List.dropLast [0]", RocList::from_slice(&[]), RocList<i64>); "List.dropLast []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropLast [0]",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -500,14 +533,26 @@ fn list_drop_first() {
RocList::from_slice(&[2, 3]), RocList::from_slice(&[2, 3]),
RocList<i64> RocList<i64>
); );
assert_evals_to!("List.dropFirst []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
assert_evals_to!("List.dropFirst [0]", RocList::from_slice(&[]), RocList<i64>); "List.dropFirst []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropFirst [0]",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_swap() { fn list_swap() {
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.swap [] 0 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!( assert_evals_to!(
"List.swap [ 0 ] 1 2", "List.swap [ 0 ] 1 2",
RocList::from_slice(&[0]), RocList::from_slice(&[0]),
@ -780,7 +825,7 @@ fn list_keep_if_empty_list_of_int() {
List.keepIf empty \_ -> True List.keepIf empty \_ -> True
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -799,7 +844,7 @@ fn list_keep_if_empty_list() {
List.keepIf [] alwaysTrue List.keepIf [] alwaysTrue
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -839,7 +884,7 @@ fn list_keep_if_always_false_for_non_empty_list() {
List.keepIf [1,2,3,4,5,6,7,8] alwaysFalse List.keepIf [1,2,3,4,5,6,7,8] alwaysFalse
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -889,7 +934,7 @@ fn list_map_on_empty_list_with_int_layout() {
List.map empty (\x -> x) List.map empty (\x -> x)
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -1000,7 +1045,7 @@ fn list_map_all_inline() {
List.map [] (\x -> x > 0) List.map [] (\x -> x > 0)
"# "#
), ),
RocList::from_slice(&[]), RocList::<bool>::from_slice(&[]),
RocList<bool> RocList<bool>
); );
} }
@ -1126,7 +1171,11 @@ fn list_map2_different_lengths() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_join_empty_list() { fn list_join_empty_list() {
assert_evals_to!("List.join []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.join []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -1208,7 +1257,7 @@ fn list_join_defined_empty_list() {
fn list_join_all_empty_lists() { fn list_join_all_empty_lists() {
assert_evals_to!( assert_evals_to!(
"List.join [ [], [], [] ]", "List.join [ [], [], [] ]",
RocList::from_slice(&[]), RocList::<f64>::from_slice(&[]),
RocList<f64> RocList<f64>
); );
} }
@ -1246,7 +1295,7 @@ fn list_repeat() {
assert_evals_to!( assert_evals_to!(
"List.repeat [] 2", "List.repeat [] 2",
RocList::from_slice(&[RocList::default(), RocList::default()]), RocList::from_slice(&[RocList::<i64>::default(), RocList::default()]),
RocList<RocList<i64>> RocList<RocList<i64>>
); );
@ -1300,7 +1349,7 @@ fn list_reverse_empty_list_of_int() {
List.reverse emptyList List.reverse emptyList
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -1308,7 +1357,11 @@ fn list_reverse_empty_list_of_int() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_reverse_empty_list() { fn list_reverse_empty_list() {
assert_evals_to!("List.reverse []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.reverse []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -1328,7 +1381,7 @@ fn list_concat() {
List.concat firstList secondList List.concat firstList secondList
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -1336,7 +1389,11 @@ fn list_concat() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_concat_two_empty_lists() { fn list_concat_two_empty_lists() {
assert_evals_to!("List.concat [] []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.concat [] []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
} }
#[test] #[test]
@ -1356,7 +1413,7 @@ fn list_concat_two_empty_lists_of_int() {
List.concat firstList secondList List.concat firstList secondList
"# "#
), ),
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
} }
@ -2386,7 +2443,11 @@ fn cleanup_because_exception() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_range() { fn list_range() {
assert_evals_to!("List.range 0 -1", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.range 0 -1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!("List.range 0 0", RocList::from_slice(&[0]), RocList<i64>); assert_evals_to!("List.range 0 0", RocList::from_slice(&[0]), RocList<i64>);
assert_evals_to!( assert_evals_to!(
"List.range 0 5", "List.range 0 5",
@ -2400,7 +2461,7 @@ fn list_range() {
fn list_sort_with() { fn list_sort_with() {
assert_evals_to!( assert_evals_to!(
"List.sortWith [] Num.compare", "List.sortWith [] Num.compare",
RocList::from_slice(&[]), RocList::<i64>::from_slice(&[]),
RocList<i64> RocList<i64>
); );
assert_evals_to!( assert_evals_to!(
@ -2418,7 +2479,11 @@ fn list_sort_with() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_sort_asc() { fn list_sort_asc() {
assert_evals_to!("List.sortAsc []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.sortAsc []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!( assert_evals_to!(
"List.sortAsc [ 4,3,2,1 ]", "List.sortAsc [ 4,3,2,1 ]",
RocList::from_slice(&[1, 2, 3, 4]), RocList::from_slice(&[1, 2, 3, 4]),
@ -2429,7 +2494,11 @@ fn list_sort_asc() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_sort_desc() { fn list_sort_desc() {
assert_evals_to!("List.sortDesc []", RocList::from_slice(&[]), RocList<i64>); assert_evals_to!(
"List.sortDesc []",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!( assert_evals_to!(
"List.sortDesc [ 1,2,3,4 ]", "List.sortDesc [ 1,2,3,4 ]",
RocList::from_slice(&[4, 3, 2, 1]), RocList::from_slice(&[4, 3, 2, 1]),

View file

@ -238,7 +238,7 @@ fn from_list() {
|> Set.toList |> Set.toList
"# "#
), ),
RocList::default(), RocList::<i64>::default(),
RocList<i64> RocList<i64>
); );
} }
@ -254,7 +254,7 @@ fn from_list_void() {
|> Set.toList |> Set.toList
"# "#
), ),
RocList::default(), RocList::<i64>::default(),
RocList<i64> RocList<i64>
); );
} }