Skip to content

Commit 97acc47

Browse files
committed
#124 query improvements
1 parent d49c3f1 commit 97acc47

File tree

3 files changed

+196
-2
lines changed

3 files changed

+196
-2
lines changed

test/api/project.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,11 @@
972972
"query_iter_frame_offset",
973973
"add_singleton_after_query",
974974
"query_w_component_from_parent_from_non_this",
975-
"create_query_while_pending"
975+
"create_query_while_pending",
976+
"not_pair_relation_wildcard",
977+
"not_pair_object_wildcard",
978+
"two_pair_wildcards_one_not",
979+
"two_pair_wildcards_one_not_any"
976980
]
977981
}, {
978982
"id": "Iter",

test/api/src/Query.c

+170
Original file line numberDiff line numberDiff line change
@@ -2924,3 +2924,173 @@ void Query_create_query_while_pending() {
29242924

29252925
ecs_fini(world);
29262926
}
2927+
2928+
void Query_not_pair_relation_wildcard() {
2929+
ecs_world_t *world = ecs_init();
2930+
2931+
ECS_TAG(world, Foo);
2932+
ECS_TAG(world, RelA);
2933+
ECS_TAG(world, RelB);
2934+
ECS_TAG(world, ObjA);
2935+
ECS_TAG(world, ObjB);
2936+
2937+
ecs_query_t *q = ecs_query_new(world, "Foo, !(*, ObjA)");
2938+
test_assert(q != NULL);
2939+
2940+
ecs_entity_t e1 = ecs_new(world, Foo);
2941+
ecs_entity_t e2 = ecs_new(world, Foo);
2942+
ecs_entity_t e3 = ecs_new(world, Foo);
2943+
ecs_entity_t e4 = ecs_new(world, Foo);
2944+
2945+
ecs_add_pair(world, e1, RelA, ObjA);
2946+
ecs_add_pair(world, e2, RelA, ObjB);
2947+
ecs_add_pair(world, e3, RelB, ObjA);
2948+
ecs_add_pair(world, e4, RelB, ObjB);
2949+
2950+
ecs_iter_t it = ecs_query_iter(world, q);
2951+
test_bool(true, ecs_query_next(&it));
2952+
test_int(it.count, 1);
2953+
test_uint(it.entities[0], e2);
2954+
test_uint(ecs_term_id(&it, 2), ecs_pair(EcsWildcard, ObjA));
2955+
2956+
test_bool(true, ecs_query_next(&it));
2957+
test_int(it.count, 1);
2958+
test_uint(it.entities[0], e4);
2959+
test_uint(ecs_term_id(&it, 2), ecs_pair(EcsWildcard, ObjA));
2960+
2961+
test_bool(false, ecs_query_next(&it));
2962+
2963+
ecs_fini(world);
2964+
}
2965+
2966+
void Query_not_pair_object_wildcard() {
2967+
ecs_world_t *world = ecs_init();
2968+
2969+
ECS_TAG(world, Foo);
2970+
ECS_TAG(world, RelA);
2971+
ECS_TAG(world, RelB);
2972+
ECS_TAG(world, ObjA);
2973+
ECS_TAG(world, ObjB);
2974+
2975+
ecs_query_t *q = ecs_query_new(world, "Foo, !(RelA, *)");
2976+
test_assert(q != NULL);
2977+
2978+
ecs_entity_t e1 = ecs_new(world, Foo);
2979+
ecs_entity_t e2 = ecs_new(world, Foo);
2980+
ecs_entity_t e3 = ecs_new(world, Foo);
2981+
ecs_entity_t e4 = ecs_new(world, Foo);
2982+
2983+
ecs_add_pair(world, e1, RelA, ObjA);
2984+
ecs_add_pair(world, e2, RelA, ObjB);
2985+
ecs_add_pair(world, e3, RelB, ObjA);
2986+
ecs_add_pair(world, e4, RelB, ObjB);
2987+
2988+
ecs_iter_t it = ecs_query_iter(world, q);
2989+
test_bool(true, ecs_query_next(&it));
2990+
test_int(it.count, 1);
2991+
test_uint(it.entities[0], e3);
2992+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, EcsWildcard));
2993+
2994+
test_bool(true, ecs_query_next(&it));
2995+
test_int(it.count, 1);
2996+
test_uint(it.entities[0], e4);
2997+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, EcsWildcard));
2998+
2999+
test_bool(false, ecs_query_next(&it));
3000+
3001+
ecs_fini(world);
3002+
}
3003+
3004+
void Query_two_pair_wildcards_one_not() {
3005+
ecs_world_t *world = ecs_init();
3006+
3007+
ECS_TAG(world, Foo);
3008+
ECS_TAG(world, RelA);
3009+
ECS_TAG(world, RelB);
3010+
ECS_TAG(world, ObjA);
3011+
ECS_TAG(world, ObjB);
3012+
3013+
ecs_query_t *q = ecs_query_new(world, "Foo, (RelA, *), !(RelB, *)");
3014+
test_assert(q != NULL);
3015+
3016+
ecs_entity_t e1 = ecs_new(world, Foo);
3017+
ecs_entity_t e2 = ecs_new(world, Foo);
3018+
ecs_entity_t e3 = ecs_new(world, Foo);
3019+
ecs_entity_t e4 = ecs_new(world, Foo);
3020+
3021+
ecs_add_pair(world, e1, RelA, ObjA);
3022+
ecs_add_pair(world, e1, RelB, ObjA);
3023+
3024+
ecs_add_pair(world, e2, RelA, ObjA);
3025+
3026+
ecs_add_pair(world, e3, RelA, ObjB);
3027+
ecs_add_pair(world, e3, RelB, ObjB);
3028+
3029+
ecs_add_pair(world, e4, RelA, ObjB);
3030+
3031+
ecs_iter_t it = ecs_query_iter(world, q);
3032+
test_bool(true, ecs_query_next(&it));
3033+
test_int(it.count, 1);
3034+
test_uint(it.entities[0], e2);
3035+
test_uint(ecs_term_id(&it, 1), Foo);
3036+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, ObjA));
3037+
test_uint(ecs_term_id(&it, 3), ecs_pair(RelB, EcsWildcard));
3038+
3039+
test_bool(true, ecs_query_next(&it));
3040+
test_int(it.count, 1);
3041+
test_uint(it.entities[0], e4);
3042+
test_uint(ecs_term_id(&it, 1), Foo);
3043+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, ObjB));
3044+
test_uint(ecs_term_id(&it, 3), ecs_pair(RelB, EcsWildcard));
3045+
3046+
test_bool(false, ecs_query_next(&it));
3047+
3048+
ecs_fini(world);
3049+
}
3050+
3051+
void Query_two_pair_wildcards_one_not_any() {
3052+
ecs_world_t *world = ecs_init();
3053+
3054+
ECS_TAG(world, Foo);
3055+
ECS_TAG(world, RelA);
3056+
ECS_TAG(world, RelB);
3057+
ECS_TAG(world, ObjA);
3058+
ECS_TAG(world, ObjB);
3059+
3060+
ecs_query_t *q = ecs_query_new(world, "Foo, (RelA, *), !(RelB, _)");
3061+
test_assert(q != NULL);
3062+
3063+
ecs_entity_t e1 = ecs_new(world, Foo);
3064+
ecs_entity_t e2 = ecs_new(world, Foo);
3065+
ecs_entity_t e3 = ecs_new(world, Foo);
3066+
ecs_entity_t e4 = ecs_new(world, Foo);
3067+
3068+
ecs_add_pair(world, e1, RelA, ObjA);
3069+
ecs_add_pair(world, e1, RelB, ObjA);
3070+
3071+
ecs_add_pair(world, e2, RelA, ObjA);
3072+
3073+
ecs_add_pair(world, e3, RelA, ObjB);
3074+
ecs_add_pair(world, e3, RelB, ObjB);
3075+
3076+
ecs_add_pair(world, e4, RelA, ObjB);
3077+
3078+
ecs_iter_t it = ecs_query_iter(world, q);
3079+
test_bool(true, ecs_query_next(&it));
3080+
test_int(it.count, 1);
3081+
test_uint(it.entities[0], e2);
3082+
test_uint(ecs_term_id(&it, 1), Foo);
3083+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, ObjA));
3084+
test_uint(ecs_term_id(&it, 3), ecs_pair(RelB, EcsWildcard));
3085+
3086+
test_bool(true, ecs_query_next(&it));
3087+
test_int(it.count, 1);
3088+
test_uint(it.entities[0], e4);
3089+
test_uint(ecs_term_id(&it, 1), Foo);
3090+
test_uint(ecs_term_id(&it, 2), ecs_pair(RelA, ObjB));
3091+
test_uint(ecs_term_id(&it, 3), ecs_pair(RelB, EcsWildcard));
3092+
3093+
test_bool(false, ecs_query_next(&it));
3094+
3095+
ecs_fini(world);
3096+
}

test/api/src/main.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,10 @@ void Query_query_iter_frame_offset(void);
919919
void Query_add_singleton_after_query(void);
920920
void Query_query_w_component_from_parent_from_non_this(void);
921921
void Query_create_query_while_pending(void);
922+
void Query_not_pair_relation_wildcard(void);
923+
void Query_not_pair_object_wildcard(void);
924+
void Query_two_pair_wildcards_one_not(void);
925+
void Query_two_pair_wildcards_one_not_any(void);
922926

923927
// Testsuite 'Iter'
924928
void Iter_page_iter_0_0(void);
@@ -5168,6 +5172,22 @@ bake_test_case Query_testcases[] = {
51685172
{
51695173
"create_query_while_pending",
51705174
Query_create_query_while_pending
5175+
},
5176+
{
5177+
"not_pair_relation_wildcard",
5178+
Query_not_pair_relation_wildcard
5179+
},
5180+
{
5181+
"not_pair_object_wildcard",
5182+
Query_not_pair_object_wildcard
5183+
},
5184+
{
5185+
"two_pair_wildcards_one_not",
5186+
Query_two_pair_wildcards_one_not
5187+
},
5188+
{
5189+
"two_pair_wildcards_one_not_any",
5190+
Query_two_pair_wildcards_one_not_any
51715191
}
51725192
};
51735193

@@ -8246,7 +8266,7 @@ static bake_test_suite suites[] = {
82468266
"Query",
82478267
NULL,
82488268
NULL,
8249-
65,
8269+
69,
82508270
Query_testcases
82518271
},
82528272
{

0 commit comments

Comments
 (0)