Skip to content

Commit

Permalink
Merge pull request #425 from hferee/master
Browse files Browse the repository at this point in the history
Make find_binding match annotated declarations
  • Loading branch information
erikmd committed Sep 28, 2021
2 parents e10975f + c26f814 commit b277b38
Show file tree
Hide file tree
Showing 21 changed files with 259 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/grader/test_lib.ml
Expand Up @@ -803,6 +803,8 @@ module Make
| { pstr_desc = Pstr_value (_, bds); _ } :: rest ->
let rec findvar = function
| [] -> findlet rest
| { pvb_pat = { ppat_desc = Ppat_constraint ({
ppat_desc = Ppat_var { Location.txt; _ }; _} , _) ; _ } ; pvb_expr; _ } :: _
| { pvb_pat = { ppat_desc = Ppat_var { Location.txt; _ }; _ } ; pvb_expr; _ } :: _ when txt = name ->
Message ([ Text "Found a toplevel definition for " ; Code name ; Text "."], Informative)
:: cb pvb_expr
Expand Down
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/annot_all.ml
@@ -0,0 +1 @@
let foo (x : int) : int = x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/annot_all.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/annot_arg.ml
@@ -0,0 +1 @@
let foo (x : int) = x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/annot_arg.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/annot_ret.ml
@@ -0,0 +1 @@
let foo x : int = x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/annot_ret.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/function.ml
@@ -0,0 +1 @@
let foo = function | x -> x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/function.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/simple.ml
@@ -0,0 +1 @@
let foo x = x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/simple.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
1 change: 1 addition & 0 deletions tests/test_find_binding/find_binding/simple2.ml
@@ -0,0 +1 @@
let foo = fun x -> x + 1
38 changes: 38 additions & 0 deletions tests/test_find_binding/find_binding/simple2.ml.json
@@ -0,0 +1,38 @@
[
{
"section": [
{
"text": "Function:"
},
{
"text": "foo",
"display": "code"
}
],
"contents": [
{
"message": [
{
"text": "Found a toplevel definition for "
},
{
"text": "foo",
"display": "code"
},
{
"text": "."
}
],
"result": "informative"
},
{
"message": [
{
"text": "Found"
}
],
"result": 1
}
]
}
]
@@ -0,0 +1,3 @@
<p>
This exercise is just a test for the <code>find_binding</code> function.
</p>
2 changes: 2 additions & 0 deletions tests/test_find_binding/repo/exercises/find_binding/meta.json
@@ -0,0 +1,2 @@
{"learnocaml_version":"1","kind":"exercise","stars":0,
"title":"Demo of the exercise environment"}
@@ -0,0 +1 @@

Empty file.
@@ -0,0 +1 @@
let foo x = x + 1
@@ -0,0 +1 @@
let foo x = x + 1
10 changes: 10 additions & 0 deletions tests/test_find_binding/repo/exercises/find_binding/test.ml
@@ -0,0 +1,10 @@
open Test_lib
open Report

let () =
set_result @@
ast_sanity_check code_ast @@ fun () ->
[ Section
([ Text "Function:" ; Code "foo" ],
find_binding code_ast "foo" (fun _ -> [Message ([Text "Found"], Success 1)]));
]
5 changes: 5 additions & 0 deletions tests/test_find_binding/repo/exercises/index.json
@@ -0,0 +1,5 @@
{ "learnocaml_version": "1",
"groups":
{ "demo":
{ "title": "Test find_binding",
"exercises": [ "find_binding" ] } } }

0 comments on commit b277b38

Please sign in to comment.