mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
change headers
This commit is contained in:
parent
3e3fe4fc7a
commit
ef362ada26
11 changed files with 4402 additions and 4487 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,157 +1,146 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
#![cfg(test)]
|
||||
|
||||
extern crate bumpalo;
|
||||
extern crate inkwell;
|
||||
extern crate libc;
|
||||
extern crate roc_gen;
|
||||
use crate::assert_evals_to;
|
||||
use crate::assert_llvm_evals_to;
|
||||
use indoc::indoc;
|
||||
|
||||
#[macro_use]
|
||||
mod helpers;
|
||||
|
||||
#[cfg(test)]
|
||||
mod gen_hash {
|
||||
|
||||
#[test]
|
||||
fn basic_hash() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Dict.hashTestOnly 0 0
|
||||
"#
|
||||
),
|
||||
9718519427346233646,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_str_with_seed() {
|
||||
assert_evals_to!("Dict.hashTestOnly 1 \"a\"", 0xbed235177f41d328, u64);
|
||||
assert_evals_to!("Dict.hashTestOnly 2 \"abc\"", 0xbe348debe59b27c3, u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_record() {
|
||||
assert_evals_to!("Dict.hashTestOnly 1 { x: \"a\" } ", 0xbed235177f41d328, u64);
|
||||
assert_evals_to!(
|
||||
"Dict.hashTestOnly 1 { x: 42, y: 3.14 } ",
|
||||
5348189196103430707,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_result() {
|
||||
assert_evals_to!(
|
||||
"Dict.hashTestOnly 0 (List.get [ 0x1 ] 0) ",
|
||||
2878521786781103245,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_linked_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||
|
||||
input : LinkedList I64
|
||||
input = Nil
|
||||
|
||||
Dict.hashTestOnly 0 input
|
||||
"#
|
||||
),
|
||||
0,
|
||||
u64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||
|
||||
input : LinkedList I64
|
||||
input = Cons 4 (Cons 3 Nil)
|
||||
|
||||
Dict.hashTestOnly 0 input
|
||||
"#
|
||||
),
|
||||
8287696503006938486,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_expr() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Var I64 ]
|
||||
|
||||
x : Expr
|
||||
x = Val 1
|
||||
|
||||
Dict.hashTestOnly 0 (Add x x)
|
||||
"#
|
||||
),
|
||||
18264046914072177411,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_nullable_expr() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Empty ]
|
||||
|
||||
x : Expr
|
||||
x = Val 1
|
||||
|
||||
Dict.hashTestOnly 0 (Add x x)
|
||||
"#
|
||||
),
|
||||
11103255846683455235,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_rosetree() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Rose a : [ Rose (List (Rose a)) ]
|
||||
|
||||
x : Rose I64
|
||||
x = Rose []
|
||||
|
||||
Dict.hashTestOnly 0 x
|
||||
"#
|
||||
),
|
||||
0,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
x : List Str
|
||||
x = [ "foo", "bar", "baz" ]
|
||||
|
||||
Dict.hashTestOnly 0 x
|
||||
"#
|
||||
),
|
||||
10731521034618280801,
|
||||
u64
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn basic_hash() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Dict.hashTestOnly 0 0
|
||||
"#
|
||||
),
|
||||
9718519427346233646,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_str_with_seed() {
|
||||
assert_evals_to!("Dict.hashTestOnly 1 \"a\"", 0xbed235177f41d328, u64);
|
||||
assert_evals_to!("Dict.hashTestOnly 2 \"abc\"", 0xbe348debe59b27c3, u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_record() {
|
||||
assert_evals_to!("Dict.hashTestOnly 1 { x: \"a\" } ", 0xbed235177f41d328, u64);
|
||||
assert_evals_to!(
|
||||
"Dict.hashTestOnly 1 { x: 42, y: 3.14 } ",
|
||||
5348189196103430707,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_result() {
|
||||
assert_evals_to!(
|
||||
"Dict.hashTestOnly 0 (List.get [ 0x1 ] 0) ",
|
||||
2878521786781103245,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_linked_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||
|
||||
input : LinkedList I64
|
||||
input = Nil
|
||||
|
||||
Dict.hashTestOnly 0 input
|
||||
"#
|
||||
),
|
||||
0,
|
||||
u64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||
|
||||
input : LinkedList I64
|
||||
input = Cons 4 (Cons 3 Nil)
|
||||
|
||||
Dict.hashTestOnly 0 input
|
||||
"#
|
||||
),
|
||||
8287696503006938486,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_expr() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Var I64 ]
|
||||
|
||||
x : Expr
|
||||
x = Val 1
|
||||
|
||||
Dict.hashTestOnly 0 (Add x x)
|
||||
"#
|
||||
),
|
||||
18264046914072177411,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_nullable_expr() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Empty ]
|
||||
|
||||
x : Expr
|
||||
x = Val 1
|
||||
|
||||
Dict.hashTestOnly 0 (Add x x)
|
||||
"#
|
||||
),
|
||||
11103255846683455235,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_rosetree() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Rose a : [ Rose (List (Rose a)) ]
|
||||
|
||||
x : Rose I64
|
||||
x = Rose []
|
||||
|
||||
Dict.hashTestOnly 0 x
|
||||
"#
|
||||
),
|
||||
0,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
x : List Str
|
||||
x = [ "foo", "bar", "baz" ]
|
||||
|
||||
Dict.hashTestOnly 0 x
|
||||
"#
|
||||
),
|
||||
10731521034618280801,
|
||||
u64
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,18 +1,8 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
|
||||
extern crate bumpalo;
|
||||
extern crate inkwell;
|
||||
extern crate libc;
|
||||
extern crate roc_gen;
|
||||
|
||||
#[macro_use]
|
||||
mod helpers;
|
||||
|
||||
#[cfg(test)]
|
||||
mod gen_num {
|
||||
use crate::assert_evals_to;
|
||||
use crate::assert_llvm_evals_to;
|
||||
use indoc::indoc;
|
||||
use roc_std::RocOrder;
|
||||
|
||||
#[test]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,111 +1,100 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
#![cfg(test)]
|
||||
|
||||
extern crate bumpalo;
|
||||
extern crate inkwell;
|
||||
extern crate libc;
|
||||
extern crate roc_gen;
|
||||
use crate::assert_evals_to;
|
||||
use crate::assert_llvm_evals_to;
|
||||
use indoc::indoc;
|
||||
|
||||
#[macro_use]
|
||||
mod helpers;
|
||||
#[test]
|
||||
fn with_default() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
|
||||
#[cfg(test)]
|
||||
mod gen_result {
|
||||
Result.withDefault result 0
|
||||
"#
|
||||
),
|
||||
2,
|
||||
i64
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn with_default() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
Result.withDefault result 0
|
||||
"#
|
||||
),
|
||||
2,
|
||||
i64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
Result.withDefault result 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn result_map() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
"#
|
||||
),
|
||||
3,
|
||||
i64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn result_map_err() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result {} I64
|
||||
result = Err 2
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"#
|
||||
),
|
||||
3,
|
||||
i64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result {} I64
|
||||
result = Ok {}
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
Result.withDefault result 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn result_map() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Ok 2
|
||||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
"#
|
||||
),
|
||||
3,
|
||||
i64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result I64 {}
|
||||
result = Err {}
|
||||
|
||||
result
|
||||
|> Result.map (\x -> x + 1)
|
||||
|> Result.withDefault 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn result_map_err() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result {} I64
|
||||
result = Err 2
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"#
|
||||
),
|
||||
3,
|
||||
i64
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
result : Result {} I64
|
||||
result = Ok {}
|
||||
|
||||
when Result.mapErr result (\x -> x + 1) is
|
||||
Err n -> n
|
||||
Ok _ -> 0
|
||||
"#
|
||||
),
|
||||
0,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,248 +1,237 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
#![cfg(test)]
|
||||
|
||||
extern crate bumpalo;
|
||||
extern crate inkwell;
|
||||
extern crate libc;
|
||||
extern crate roc_gen;
|
||||
use crate::assert_evals_to;
|
||||
use crate::assert_llvm_evals_to;
|
||||
use indoc::indoc;
|
||||
|
||||
#[macro_use]
|
||||
mod helpers;
|
||||
|
||||
#[cfg(test)]
|
||||
mod gen_set {
|
||||
|
||||
#[test]
|
||||
fn empty_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.len Set.empty
|
||||
"#
|
||||
),
|
||||
0,
|
||||
usize
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.len (Set.singleton 42)
|
||||
"#
|
||||
),
|
||||
1,
|
||||
usize
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_to_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 42)
|
||||
"#
|
||||
),
|
||||
&[42],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 1)
|
||||
"#
|
||||
),
|
||||
&[1],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 1.0)
|
||||
"#
|
||||
),
|
||||
&[1.0],
|
||||
&[f64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.empty
|
||||
|> Set.insert 0
|
||||
|> Set.insert 1
|
||||
|> Set.insert 2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[0, 1, 2],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.empty
|
||||
|> Set.insert 0
|
||||
|> Set.insert 1
|
||||
|> Set.remove 1
|
||||
|> Set.remove 2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[0],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn union() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.union set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[4, 2, 3, 1],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn difference() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.difference set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[2],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersection() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.intersection set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[1],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn walk_sum() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.walk (Set.fromList [1,2,3]) (\x, y -> x + y) 0
|
||||
"#
|
||||
),
|
||||
6,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contains() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.contains (Set.fromList [1,3,4]) 4
|
||||
"#
|
||||
),
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.contains (Set.fromList [1,3,4]) 2
|
||||
"#
|
||||
),
|
||||
false,
|
||||
bool
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
[1,2,2,3,1,4]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[4, 2, 3, 1],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
[]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
empty : List I64
|
||||
empty = []
|
||||
|
||||
empty
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn empty_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.len Set.empty
|
||||
"#
|
||||
),
|
||||
0,
|
||||
usize
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.len (Set.singleton 42)
|
||||
"#
|
||||
),
|
||||
1,
|
||||
usize
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_to_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 42)
|
||||
"#
|
||||
),
|
||||
&[42],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 1)
|
||||
"#
|
||||
),
|
||||
&[1],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.toList (Set.singleton 1.0)
|
||||
"#
|
||||
),
|
||||
&[1.0],
|
||||
&[f64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.empty
|
||||
|> Set.insert 0
|
||||
|> Set.insert 1
|
||||
|> Set.insert 2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[0, 1, 2],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.empty
|
||||
|> Set.insert 0
|
||||
|> Set.insert 1
|
||||
|> Set.remove 1
|
||||
|> Set.remove 2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[0],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn union() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.union set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[4, 2, 3, 1],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn difference() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.difference set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[2],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersection() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
set1 : Set I64
|
||||
set1 = Set.fromList [1,2]
|
||||
|
||||
set2 : Set I64
|
||||
set2 = Set.fromList [1,3,4]
|
||||
|
||||
Set.intersection set1 set2
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[1],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn walk_sum() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.walk (Set.fromList [1,2,3]) (\x, y -> x + y) 0
|
||||
"#
|
||||
),
|
||||
6,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contains() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.contains (Set.fromList [1,3,4]) 4
|
||||
"#
|
||||
),
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Set.contains (Set.fromList [1,3,4]) 2
|
||||
"#
|
||||
),
|
||||
false,
|
||||
bool
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
[1,2,2,3,1,4]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[4, 2, 3, 1],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
[]
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[],
|
||||
&[i64]
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
empty : List I64
|
||||
empty = []
|
||||
|
||||
empty
|
||||
|> Set.fromList
|
||||
|> Set.toList
|
||||
"#
|
||||
),
|
||||
&[],
|
||||
&[i64]
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -29,6 +29,9 @@ pub fn test_builtin_defs(symbol: Symbol, var_store: &mut VarStore) -> Option<Def
|
|||
}
|
||||
}
|
||||
|
||||
// this is not actually dead code, but only used by cfg_test modules
|
||||
// so "normally" it is dead, only at testing time is it used
|
||||
#[allow(dead_code)]
|
||||
pub fn helper<'a>(
|
||||
arena: &'a bumpalo::Bump,
|
||||
src: &str,
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
// we actually want to compare against the literal float bits
|
||||
#![allow(clippy::clippy::float_cmp)]
|
||||
|
||||
pub mod gen_tags;
|
||||
pub mod gen_dict;
|
||||
pub mod gen_hash;
|
||||
pub mod gen_list;
|
||||
pub mod gen_num;
|
||||
pub mod gen_primitives;
|
||||
pub mod gen_records;
|
||||
pub mod gen_result;
|
||||
pub mod gen_set;
|
||||
pub mod gen_str;
|
||||
pub mod gen_tags;
|
||||
mod helpers;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue