Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file test_schema_stmts.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for YANG (YIN) statements in (sub)modules |
| 5 | * |
| 6 | * Copyright (c) 2018-2020 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <stdio.h> |
| 18 | #include <setjmp.h> |
| 19 | #include <cmocka.h> |
| 20 | |
| 21 | #include <string.h> |
| 22 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 23 | #include "log.h" |
| 24 | #include "context.h" |
| 25 | #include "test_schema.h" |
| 26 | #include "tree_schema.h" |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 27 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 28 | #include "test_schema.h" |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 29 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 30 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 31 | test_identity(void **state) |
| 32 | { |
| 33 | *state = test_identity; |
| 34 | |
| 35 | struct ly_ctx *ctx; |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 36 | const struct lys_module *mod, *mod_imp; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 37 | |
| 38 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 39 | |
| 40 | /* |
| 41 | * parsing YANG |
| 42 | */ |
| 43 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "description", "a", "b", "1"); |
| 44 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "reference", "a", "b", "1"); |
| 45 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "status", "current", "obsolete", "1"); |
| 46 | |
| 47 | /* full content */ |
| 48 | TEST_SCHEMA_OK(ctx, 1, 0, "identityone", |
| 49 | "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}" |
| 50 | "identity a; identity b; extension ext; feature x; feature y;", mod); |
| 51 | assert_non_null(mod->parsed->identities); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 52 | assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 53 | |
| 54 | /* invalid substatement */ |
| 55 | TEST_STMT_SUBSTM_ERR(ctx, 0, "identity", "organization", "XXX"); |
| 56 | |
| 57 | /* |
| 58 | * parsing YIN |
| 59 | */ |
| 60 | /* max subelems */ |
| 61 | TEST_SCHEMA_OK(ctx, 1, 1, "identityone-yin", "<identity name=\"ident-name\">" |
| 62 | "<if-feature name=\"iff\"/>" |
| 63 | "<base name=\"base-name\"/>" |
| 64 | "<status value=\"deprecated\"/>" |
| 65 | "<description><text>desc</text></description>" |
| 66 | "<reference><text>ref</text></reference>" |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 67 | /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:identityone-yin\"/>" */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 68 | "</identity><extension name=\"ext\"/><identity name=\"base-name\"/><feature name=\"iff\"/>", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 69 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 70 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 71 | assert_string_equal(mod->parsed->identities[0].bases[0], "base-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 72 | assert_string_equal(mod->parsed->identities[0].iffeatures[0].str, "iff"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 73 | assert_string_equal(mod->parsed->identities[0].dsc, "desc"); |
| 74 | assert_string_equal(mod->parsed->identities[0].ref, "ref"); |
| 75 | assert_true(mod->parsed->identities[0].flags & LYS_STATUS_DEPRC); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 76 | /*assert_string_equal(mod->parsed->identities[0].exts[0].name, "ext"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 77 | assert_non_null(mod->parsed->identities[0].exts[0].compiled); |
| 78 | assert_int_equal(mod->parsed->identities[0].exts[0].yin, 1); |
| 79 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt_index, 0); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 80 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 81 | |
| 82 | /* min subelems */ |
| 83 | TEST_SCHEMA_OK(ctx, 1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 84 | assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 85 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 86 | |
| 87 | /* invalid substatement */ |
| 88 | TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>", |
| 89 | "Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1."); |
| 90 | |
| 91 | /* |
| 92 | * compiling |
| 93 | */ |
| 94 | TEST_SCHEMA_OK(ctx, 0, 0, "a", "identity a1;", mod_imp); |
| 95 | TEST_SCHEMA_OK(ctx, 1, 0, "b", "import a {prefix a;}" |
| 96 | "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}" |
| 97 | "identity b4 {base b:b1; base b3;}", mod); |
| 98 | assert_non_null(mod_imp->compiled); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 99 | assert_non_null(mod_imp->identities); |
| 100 | assert_non_null(mod->identities); |
| 101 | assert_non_null(mod_imp->identities[0].derived); |
| 102 | assert_int_equal(1, LY_ARRAY_COUNT(mod_imp->identities[0].derived)); |
| 103 | assert_ptr_equal(mod_imp->identities[0].derived[0], &mod->identities[2]); |
| 104 | assert_non_null(mod->identities[0].derived); |
| 105 | assert_int_equal(2, LY_ARRAY_COUNT(mod->identities[0].derived)); |
| 106 | assert_ptr_equal(mod->identities[0].derived[0], &mod->identities[2]); |
| 107 | assert_ptr_equal(mod->identities[0].derived[1], &mod->identities[3]); |
| 108 | assert_non_null(mod->identities[1].derived); |
| 109 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived)); |
| 110 | assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[2]); |
| 111 | assert_non_null(mod->identities[2].derived); |
| 112 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived)); |
| 113 | assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 114 | |
| 115 | TEST_SCHEMA_OK(ctx, 1, 0, "c", "identity c2 {base c1;} identity c1;", mod); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 116 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived)); |
| 117 | assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 118 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 119 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 120 | |
| 121 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}"); |
| 122 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;identity i1;", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 123 | "Duplicate identifier \"i1\" of identity statement. Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 124 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\". /inv:{identity='i1'}"); |
| 125 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself. /inv:{identity='i1'}"); |
| 126 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}", |
| 127 | "Identity \"i1\" is indirectly derived from itself. /inv:{identity='i3'}"); |
| 128 | |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 129 | /* base in non-implemented module */ |
| 130 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, |
| 131 | "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}"); |
| 132 | TEST_SCHEMA_OK(ctx, 0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod); |
| 133 | |
| 134 | /* default value from non-implemented module */ |
| 135 | TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}", |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 136 | "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value" |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 137 | " - identity found in non-implemented module \"base\".). /ident2:l"); |
| 138 | |
| 139 | /* default value in typedef from non-implemented module */ |
| 140 | TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}" |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 141 | "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid" |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 142 | " identityref \"b:i2\" value - identity found in non-implemented module \"base\".). /ident2:l"); |
| 143 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 144 | /* |
| 145 | * printing |
| 146 | */ |
| 147 | |
| 148 | /* |
| 149 | * cleanup |
| 150 | */ |
| 151 | |
| 152 | *state = NULL; |
| 153 | ly_ctx_destroy(ctx, NULL); |
| 154 | } |
| 155 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 156 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 157 | test_feature(void **state) |
| 158 | { |
| 159 | *state = test_feature; |
| 160 | |
| 161 | struct ly_ctx *ctx; |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 162 | const struct lys_module *mod; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 163 | const struct lysp_feature *f; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 164 | |
| 165 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 166 | |
| 167 | /* |
| 168 | * parsing YANG |
| 169 | */ |
| 170 | |
| 171 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "description", "a", "b", "1"); |
| 172 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "reference", "a", "b", "1"); |
| 173 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "status", "current", "obsolete", "1"); |
| 174 | |
| 175 | /* full content */ |
| 176 | TEST_SCHEMA_OK(ctx, 1, 0, "featureone", |
| 177 | "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}" |
| 178 | "extension ext; feature x; feature y;", mod); |
| 179 | assert_non_null(mod->parsed->features); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 180 | assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 181 | |
| 182 | /* invalid substatement */ |
| 183 | TEST_STMT_SUBSTM_ERR(ctx, 0, "feature", "organization", "XXX"); |
| 184 | |
| 185 | /* |
| 186 | * parsing YIN |
| 187 | */ |
| 188 | /* max subelems */ |
| 189 | TEST_SCHEMA_OK(ctx, 0, 1, "featureone-yin", "<feature name=\"feature-name\">" |
| 190 | "<if-feature name=\"iff\"/>" |
| 191 | "<status value=\"deprecated\"/>" |
| 192 | "<description><text>desc</text></description>" |
| 193 | "<reference><text>ref</text></reference>" |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 194 | /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>" */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 195 | "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 196 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 197 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 198 | assert_string_equal(mod->parsed->features[0].dsc, "desc"); |
| 199 | assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 200 | assert_string_equal(mod->parsed->features[0].iffeatures[0].str, "iff"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 201 | assert_string_equal(mod->parsed->features[0].ref, "ref"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 202 | /*assert_string_equal(mod->parsed->features[0].exts[0].name, "ext"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 203 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 204 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 205 | |
| 206 | /* min subelems */ |
| 207 | TEST_SCHEMA_OK(ctx, 0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod) |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 208 | assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 209 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 210 | |
| 211 | /* invalid substatement */ |
| 212 | TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>", |
| 213 | "Unexpected sub-element \"organization\" of \"feature\" element. Line number 1."); |
| 214 | |
| 215 | /* |
| 216 | * compiling |
| 217 | */ |
| 218 | |
| 219 | TEST_SCHEMA_OK(ctx, 1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n" |
| 220 | "feature orfeature {if-feature \"f1 or f2\";}\n" |
| 221 | "feature andfeature {if-feature \"f1 and f2\";}\n" |
| 222 | "feature f6 {if-feature \"not f1\";}\n" |
| 223 | "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n" |
| 224 | "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n" |
| 225 | "feature f9 {if-feature \"not not f1\";}", mod); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 226 | assert_non_null(mod->parsed->features); |
| 227 | assert_int_equal(9, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 228 | |
| 229 | /* all features are disabled by default */ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 230 | LY_ARRAY_FOR(mod->parsed->features, struct lysp_feature, f) { |
| 231 | assert_false(f->flags & LYS_FENABLED); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 232 | } |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 233 | |
| 234 | /* some invalid expressions */ |
| 235 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 236 | "Invalid value \"f1\" of if-feature - unable to find feature \"f1\"."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 237 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 238 | "Invalid value \"f and\" of if-feature - unexpected end of expression."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 239 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 240 | "Invalid value \"or\" of if-feature - unexpected end of expression."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 241 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 242 | "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 243 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 244 | "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 245 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 246 | "Invalid value \"---\" of if-feature - unable to find feature \"---\"."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 247 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 248 | "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 249 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 250 | "Duplicate identifier \"f1\" of feature statement. Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 251 | |
| 252 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}"); |
| 253 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 254 | "Duplicate identifier \"f1\" of feature statement. Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 255 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 256 | "Feature \"f1\" is indirectly referenced from itself."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 257 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 258 | "Feature \"f1\" is referenced from itself."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 259 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 260 | "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 261 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 262 | "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 263 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 264 | "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 265 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 266 | "Invalid value \"f1 not \" of if-feature - unexpected end of expression."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 267 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 268 | "Invalid value \"f1 not not \" of if-feature - unexpected end of expression."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 269 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}", |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 270 | "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * printing |
| 274 | */ |
| 275 | |
| 276 | /* |
| 277 | * cleanup |
| 278 | */ |
| 279 | |
| 280 | *state = NULL; |
| 281 | ly_ctx_destroy(ctx, NULL); |
| 282 | } |