Skip to content

Commit

Permalink
Add tests for Sort/compare ability
Browse files Browse the repository at this point in the history
We had a single test before, but it was failing due to a typo. This
fixes the test, plus adds some more for the new sortable types we've
added since.
  • Loading branch information
jwoudenberg authored and benplotke committed Jul 14, 2024
1 parent 6a10d8a commit 75f091d
Showing 1 changed file with 216 additions and 3 deletions.
219 changes: 216 additions & 3 deletions crates/compiler/test_gen/src/gen_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,238 @@ use crate::helpers::wasm::assert_evals_to;

use indoc::indoc;

#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn compare_u64() {
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
j : U64
j = 2
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
2,
u8
);
assert_evals_to!(
indoc!(
r#"
i : U64
i = 2
j : U64
j = 1
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
1,
u8
);
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
j : U64
j = 1
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
0,
u8
);
}

#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn compare_i64() {
assert_evals_to!(
indoc!(
r#"
i : I64
i = -1
j : I64
j = 1
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
2,
u8
);
assert_evals_to!(
indoc!(
r#"
i : I64
i = 1
j : I64
j = 2
j = -1
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
1,
u8
);
assert_evals_to!(
indoc!(
r#"
i : I64
i = -1
j : I64
j = -1
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
0,
u8
);
}

#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn compare_f64() {
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1.2
j : F64
j = 1.3
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
2,
u8
);
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1.3
j : F64
j = 1.2
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
1,
u8
);
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1.2
j : F64
j = 1.2
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
0,
u8
);
}

#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn compare_bool() {
assert_evals_to!(
indoc!(
r#"
i : Bool
i = Bool.false
j : Bool
j = Bool.true
when List.compare i j is
Equals -> 0
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
2,
i64
u8
);
assert_evals_to!(
indoc!(
r#"
i : Bool
i = Bool.true
j : Bool
j = Bool.false
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
1,
u8
);
assert_evals_to!(
indoc!(
r#"
i : Bool
i = Bool.false
j : Bool
j = Bool.false
when List.compare i j is
Equal -> 0
GreaterThan -> 1
LessThan -> 2
"#
),
0,
u8
);
}

0 comments on commit 75f091d

Please sign in to comment.