Skip to content

Commit

Permalink
Test bool property merge for Sequence.each
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Dec 15, 2024
1 parent cb57f26 commit 9b3b77b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/deemon/objects/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,12 @@ PRIVATE struct type_getset tpconst seq_getsets[] = {
"->?Dbool\n"
"Alias for ?#{op:bool}"),

/* TODO: flatten->?DSequence
* Flatten a sequence of sequences into a flat sequence:
* >> local x = { {0, 1, 2}, {5, 7, 9}, {1, 10, 1} };
* >> print repr x.flatten; // { 0, 1, 2, 5, 7, 9, 1, 10, 1 }
*/

/* TODO: itemtype->?DType
* Check if the type of @this overrides the ?#ItemType class attribute.
* If so, return its value; else, return the common base-class of all
Expand Down
2 changes: 1 addition & 1 deletion src/deemon/objects/seq/each-fastpass.c.inl
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ PRIVATE struct type_seq LOCAL_seX(seq) = {
/* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))&LOCAL_seX(setrange),
/* .tp_nsi = */ NULL,
/* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&LOCAL_seX(foreach),
/* .tp_foreach_pair = */ NULL, /* &DeeObject_DefaultForeachPairWithForeach */
/* .tp_foreach_pair = */ &DeeObject_DefaultForeachPairWithForeach,
/* .tp_enumerate = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_enumerate_t, void *))&LOCAL_seX(enumerate),
/* .tp_enumerate_index = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_enumerate_index_t, void *, size_t, size_t))&LOCAL_seX(enumerate_index),
#ifdef CONFIG_HAVE_SEQEACHOPERATOR_IS_SEQLIKE
Expand Down
2 changes: 1 addition & 1 deletion src/deemon/objects/seq/each.c
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ PRIVATE struct type_seq seo_seq = {
/* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))&seo_setrange,
/* .tp_nsi = */ NULL,
/* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&seo_foreach,
/* .tp_foreach_pair = */ NULL, /* &DeeObject_DefaultForeachPairWithForeachs */
/* .tp_foreach_pair = */ &DeeObject_DefaultForeachPairWithForeach,
/* .tp_enumerate = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_enumerate_t, void *))&seo_enumerate,
/* .tp_enumerate_index = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_enumerate_index_t, void *, size_t, size_t))&seo_enumerate_index,
#ifdef CONFIG_HAVE_SEQEACHOPERATOR_IS_SEQLIKE
Expand Down
32 changes: 25 additions & 7 deletions util/test/deemon-sequence-some.dee
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ assert !(x.some == 58);
assert x.some != 8, "Because there is some element that is non-equal to '8'";

/* Assert that non-equality of "some" element works properly */
assert ({0, 8}.some != 8);
assert ({8, 0}.some != 8);
assert (({0, 8}.some != 8));
assert (({8, 0}.some != 8));
assert !({8, 8}.some != 8);
assert !({8}.some != 8);
assert !({8 }.some != 8);

/* Assert that sequence operators work with ".some" */
assert ((10 in { {0, 1, 2}, {5, 7, 9}, {1, 10, 1} }.some));
Expand All @@ -54,7 +54,25 @@ assert ({ {0, 1, 2}, {5, 7, 9}, {1, 10, 1} }.some.contains(10));
assert !{ {0, 1, 2}, {5, 7, 9}, {1, 10, 1} }.some.contains(11);

/* Assert that attribute properties work with ".some" */
assert (({ {}, {1}, {1, 2} }.some.length == 0));
assert (({ {}, {1}, {1, 2} }.some.length == 1));
assert (({ {}, {1}, {1, 2} }.some.length == 2));
assert !({ {}, {1}, {1, 2} }.some.length == 3);
assert (({ {}, {42}, {42, 43} }.some.length == 0));
assert (({ {}, {42}, {42, 43} }.some.length == 1));
assert (({ {}, {42}, {42, 43} }.some.length == 2));
assert !({ {}, {42}, {42, 43} }.some.length == 3);

/* Assert that boolean property merging (via &&) works
* for ".each".
*
* Note that because "operator <=>" is implemented via
* sequence compare for anything but first-level each-
* wrappers, we have to write "x.__eq__(y)" instead of
* "x == y"
*
* s.a. `CONFIG_HAVE_SEQEACHOPERATOR_IS_SEQLIKE' */
assert !({ {}, {42}, {42, 43} }.each.length.__eq__(0));
assert !({ {}, {42}, {42, 43} }.each.length.__ne__(0));
assert !({ {}, {42}, {42, 43} }.each.length.__eq__(1));
assert !({ {}, {42}, {42, 43} }.each.length.__ne__(1));
assert !({ {}, {42}, {42, 43} }.each.length.__eq__(2));
assert !({ {}, {42}, {42, 43} }.each.length.__ne__(2));
assert !({ {}, {42}, {42, 43} }.each.length.__eq__(3));
assert (({ {}, {42}, {42, 43} }.each.length.__ne__(3)));

0 comments on commit 9b3b77b

Please sign in to comment.