there must be at least one predicate in a rule

This commit is contained in:
Rijnard van Tonder 2019-04-18 01:26:39 -04:00
parent 4f9180a5ff
commit 90cd6f5e5c
3 changed files with 24 additions and 3 deletions

View File

@ -223,7 +223,7 @@ let create rule =
(spaces
>> string Syntax.rule_prefix
>> spaces
>> comma_sep expression_parser
>> comma_sep1 expression_parser
<< eof)
s
in

View File

@ -101,7 +101,8 @@ let perform_rewrite request =
>>| Yojson.Safe.from_string
>>| rewrite_request_of_yojson
>>| function
| Ok { source; match_template; rewrite_template; rule; language; substitution_kind } ->
| Ok ({ source; match_template; rewrite_template; rule; language; substitution_kind } as request) ->
if debug then Format.printf "Received %s@." (Yojson.Safe.pretty_to_string (rewrite_request_to_yojson request));
let matcher = matcher_of_language language in
let source_substitution =
match substitution_kind with
@ -120,8 +121,10 @@ let perform_rewrite request =
| Some Ok rule -> `Code 200, run ~rule ()
| Some Error error -> `Code 400, Error.to_string_hum error
in
if debug then Format.printf "Result (200 or 400) %s@." result;
respond ~code (`String result)
| Error error ->
if debug then Format.printf "Result (400) %s@." error;
respond ~code:(`Code 400) (`String error)
let add_cors_headers (headers: Cohttp.Header.t): Cohttp.Header.t =

View File

@ -118,7 +118,7 @@ let%expect_test "post_request" =
Error in line 1, column 7:
where :[1] = "world"
^
Expecting "false", "match", "rewrite", "true", end of input or string literal
Expecting "false", "match", "rewrite", "true" or string literal
Backtracking occurred after:
Error in line 1, column 12:
where :[1] = "world"
@ -181,4 +181,22 @@ let%expect_test "post_request" =
"in_place_substitutions": []
} |}];
(* test there must be at least one predicate in a rule *)
let source = "hello world" in
let match_template = "hello :[1]" in
let rule = Some {|where |} in
let language = "generic" in
let request = { source; match_template; rule; language } in
let json = match_request_to_yojson request |> Yojson.Safe.to_string in
let result = post `Match json in
print_string result;
[%expect {|
Error in line 1, column 7:
where
^
Expecting ":[", "false", "match", "rewrite", "true" or string literal |}];
kill ()