1 #include "phase.h"
2 #include "util.h"
3 #include "common.h"
4 #include "test_util.h"
5 #include "json.h"
6
7 #include <check.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11
12 JsonNode *trees_to_json(tree_t *elements, unsigned int n_elements);
13
START_TEST(test_pragma)14 START_TEST(test_pragma)
15 {
16 opt_set_int("parse-pragmas", 1);
17
18 input_from_file(TESTDIR "/json/pragma.vhd");
19
20 tree_t arch = parse_check_and_simplify(T_ENTITY, T_ARCH);
21 ck_assert_ptr_nonnull(arch);
22
23 JsonNode *json = trees_to_json(&arch, 1);
24 ck_assert_ptr_nonnull(json);
25
26 JsonNode *jarch = json_find_element(json, 0);
27 ck_assert_ptr_nonnull(jarch);
28
29 JsonNode *jarch_cls = json_find_member(jarch, "cls");
30 ck_assert_ptr_nonnull(jarch_cls);
31 ck_assert_int_eq(JSON_STRING, jarch_cls->tag);
32 ck_assert_str_eq("architecture", jarch_cls->string_);
33
34 JsonNode *jproc = json_find_element(json_find_member(jarch, "stmts"), 0);
35 ck_assert_ptr_nonnull(jproc);
36
37 JsonNode *jpragma = json_find_element(json_find_member(jproc, "stmts"), 0);
38 ck_assert_ptr_nonnull(jpragma);
39
40 JsonNode *jcomment = json_find_member(jpragma, "comment");
41 ck_assert_ptr_nonnull(jcomment);
42 ck_assert_int_eq(JSON_STRING, jcomment->tag);
43 //ck_assert_str_eq("-- lint_off foo bar", jcomment->string_);
44
45 json_delete(json);
46 }
47 END_TEST
48
get_json_tests(void)49 Suite *get_json_tests(void)
50 {
51 Suite *s = suite_create("json");
52
53 TCase *tc_core = nvc_unit_test();
54 tcase_add_test(tc_core, test_pragma);
55 suite_add_tcase(s, tc_core);
56
57 return s;
58 }
59