Project

General

Profile

Revision 550e6a83

View differences:

data-test/simple-var-1.json
1
{
2
    "data": [
3
        {
4
            "datatype": "bool",
5
            "initial_value": "false",
6
            "name": "x",
7
            "scope": "Output"
8
        }
9
    ],
10
    "junctions": [],
11
    "name": "simple-var-1",
12
    "origin_path": "simple-var-1",
13
    "sffunctions": [],
14
    "states": []
15
}
src/tools/stateflow/json-parser/test_json_parser_variables.ml
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_1 tests_ctxt =
50
  let prog = Parse.parse_prog
51
      (Yojson.Basic.from_file "../data-test/simple-var-1.json") in
52
  match prog with
53
  | Program ("simple-var-1", [ ], [ 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-1 is not correct")
57

  
58
let var_suite =
59
  "suite for variables" >:::
60
  [ "simple test for variable 1" >:: test_simple_var_1 ]
61

  
62
let _ =
63
  run_test_tt_main var_suite

Also available in: Unified diff