Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Nov 30, 2023
1 parent 38122ae commit 76cf4bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
47 changes: 18 additions & 29 deletions src/grammar/test_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn test_parse_program() {
y: Int;
}
fn identity(p: owned Point) -> owned Point {
fn identity(p: given Point) -> given Point {
p.give;
}
",
Expand All @@ -27,7 +27,7 @@ fn test_parse_program() {
FnDecl(
FnDecl {
name: identity,
binder: (p : owned Point) -> owned Point { p . give ; },
binder: (p : given Point) -> given Point { p . give ; },
},
),
],
Expand Down Expand Up @@ -60,7 +60,7 @@ fn test_parse_shared_perm() {
let p: Perm = crate::dada_lang::term("shared(a.b.c)");
expect_test::expect![[r#"
Shared(
[
{
Place {
var: a,
projections: [
Expand All @@ -72,29 +72,18 @@ fn test_parse_shared_perm() {
),
],
},
],
Owned,
},
)
"#]]
.assert_debug_eq(&p);
}

#[test]
fn test_parse_shared_var() {
let p: Binder<Perm> = crate::dada_lang::term("[perm P] shared(a.b.c) P");
expect_test::expect![[r#"
[perm] shared (a . b . c) ^perm0_0
"#]]
.assert_debug_eq(&p);
}

#[test]
fn test_parse_our_perm_without_parens() {
let p: Perm = crate::dada_lang::term("shared");
expect_test::expect![[r#"
Shared(
[],
Owned,
{},
)
"#]]
.assert_debug_eq(&p);
Expand All @@ -105,8 +94,7 @@ fn test_parse_our_perm_with_parens() {
let p: Perm = crate::dada_lang::term("shared()");
expect_test::expect![[r#"
Shared(
[],
Owned,
{},
)
"#]]
.assert_debug_eq(&p);
Expand All @@ -117,7 +105,7 @@ fn test_parse_shared_perm_2() {
let p: Perm = crate::dada_lang::term("shared(a,b)");
expect_test::expect![[r#"
Shared(
[
{
Place {
var: a,
projections: [],
Expand All @@ -126,18 +114,19 @@ fn test_parse_shared_perm_2() {
var: b,
projections: [],
},
],
Owned,
},
)
"#]]
.assert_debug_eq(&p);
}

#[test]
fn test_parse_my_perm() {
let p: Perm = crate::dada_lang::term("owned");
let p: Perm = crate::dada_lang::term("given");
expect_test::expect![[r#"
Owned
Given(
{},
)
"#]]
.assert_debug_eq(&p);
}
Expand All @@ -149,8 +138,7 @@ fn test_parse_String_ty() {
expect_test::expect![[r#"
ApplyPerm(
Shared(
[],
Owned,
{},
),
ClassTy(
ClassTy {
Expand All @@ -168,12 +156,11 @@ fn test_parse_String_ty() {
#[test]
#[allow(non_snake_case)]
fn test_parse_Vec_ty() {
let p: Ty = crate::dada_lang::term("shared Vec[owned U32]");
let p: Ty = crate::dada_lang::term("shared Vec[given U32]");
expect_test::expect![[r#"
ApplyPerm(
Shared(
[],
Owned,
{},
),
ClassTy(
ClassTy {
Expand All @@ -183,7 +170,9 @@ fn test_parse_Vec_ty() {
parameters: [
Ty(
ApplyPerm(
Owned,
Given(
{},
),
ClassTy(
ClassTy {
name: Id(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ formality_core::declare_language! {
const KEYWORDS = [
"class",
"struct",
"owned",
"given",
"shared",
"leased",
"await",
Expand Down
10 changes: 5 additions & 5 deletions src/type_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fn bad_class_name_in_fn_parameter() {
expect_test::expect![[r#"
Err(
Error {
context: "check program `fn no_such_class (c : owned ClassName) -> () { }`",
context: "check program `fn no_such_class (c : given ClassName) -> () { }`",
source: Error {
context: "check function named `no_such_class`",
source: Error {
context: "check type `owned ClassName`",
context: "check type `given ClassName`",
source: Error {
context: "check type `ClassName`",
source: Error {
Expand Down Expand Up @@ -44,7 +44,7 @@ fn ok_field_name_in_fn_parameter() {
.assert_debug_eq(&check_program(&term(
"
class Point { x: shared Int; y: shared Int; }
fn no_such_class(c: owned Point, x: shared(c.x) Int, y: shared(c.y) Int) -> () {}
fn no_such_class(c: given Point, x: shared(c.x) Int, y: shared(c.y) Int) -> () {}
",
)));
}
Expand All @@ -55,7 +55,7 @@ fn bad_field_name_in_fn_parameter() {
expect_test::expect![[r#"
Err(
Error {
context: "check program `class Point { x : shared Int ; y : shared Int ; } fn no_such_class (c : owned Point, x : shared (c . z) Int) -> () { }`",
context: "check program `class Point { x : shared Int ; y : shared Int ; } fn no_such_class (c : given Point, x : shared (c . z) Int) -> () { }`",
source: Error {
context: "check function named `no_such_class`",
source: Error {
Expand All @@ -75,7 +75,7 @@ fn bad_field_name_in_fn_parameter() {
.assert_debug_eq(&check_program(&term(
"
class Point { x: shared Int; y: shared Int; }
fn no_such_class(c: owned Point, x: shared(c.z) Int) -> () {}
fn no_such_class(c: given Point, x: shared(c.z) Int) -> () {}
",
)));
}

0 comments on commit 76cf4bb

Please sign in to comment.