Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / stateflow / json-parser / test_json_parser_variables.ml @ 0291fcfd

History | View | Annotate | Download (2.27 KB)

1
open Basetypes
2
open Corelang
3
open Datatype
4
open Json_parser
5
open LustreSpec
6
open OUnit2
7

    
8
module ParseExt =
9
struct
10
  let parse_condition _ = Condition.tru
11
  let parse_action    _ = Action.nil
12
  let parse_event json  = Some Yojson.Basic.(json |> to_string)
13
end
14

    
15
module Parse = Parser (ParseExt)
16

    
17
let location = Location.dummy_loc
18

    
19
let test_var_skeleton var id var_type value =
20
  begin
21
    assert_bool
22
      "orig for user variables should be true"
23
      var.var_orig;
24
    assert_bool
25
      "user variables are considered as constants"
26
      var.var_dec_const;
27
    assert_equal
28
      ~msg:("problem with variable " ^ var.var_id ^ " clock type")
29
      var.var_dec_clock.ck_dec_desc
30
      Ckdec_any;
31
    assert_equal
32
      ~msg:("problem with variable " ^ var.var_id ^ " ident")
33
      var.var_id
34
      id;
35
    assert_equal
36
      ~msg:("problem with variable " ^ var.var_id ^ " type")
37
      var.var_dec_type.ty_dec_desc
38
      var_type;
39
    match var.var_dec_value with
40
    | Some { expr_desc = d } ->
41
      assert_equal
42
        ~msg:("problem with variable " ^ var.var_id ^ " value")
43
        d
44
        value
45
    | _       -> raise (OUnitTest.OUnit_failure
46
                          "User variables should have an initial value")
47
  end
48

    
49
let test_simple_var_bool_false tests_ctxt =
50
  let prog = Parse.parse_prog
51
      (Yojson.Basic.from_file "../data-test/simple-var-bool-false.json") in
52
  match prog with
53
  | Program ("simple_var_bool_false", [ ], [ x ]) ->
54
    test_var_skeleton x "x" Tydec_bool (Expr_const (Const_tag tag_false))
55
  | _ -> raise (OUnitTest.OUnit_failure
56
                  "Program obtained from simple-var-bool-false.json is not correct")
57

    
58
let test_simple_var_bool_true tests_ctxt =
59
  let prog = Parse.parse_prog
60
      (Yojson.Basic.from_file "../data-test/simple-var-bool-true.json") in
61
  match prog with
62
  | Program ("simple_var_bool_true", [ ], [ x ]) ->
63
    test_var_skeleton x "my_var" Tydec_bool (Expr_const (Const_tag tag_true))
64
  | _ -> raise (OUnitTest.OUnit_failure
65
                  "Program obtained from simple-var-bool-true.json is not correct")
66

    
67
let var_suite =
68
  "suite for variables" >:::
69
  [ "simple test for variable (boolean, false)" >::
70
    test_simple_var_bool_false;
71
    "simple test for variable (boolean, true)"  >::
72
    test_simple_var_bool_true
73
  ]
74

    
75
let _ =
76
  run_test_tt_main var_suite