test: update tests
This commit is contained in:
@@ -74,19 +74,21 @@ void test_btree_iterate(CuTest *tc)
|
||||
}
|
||||
|
||||
int prev = -1;
|
||||
b_btree_iterator it;
|
||||
b_btree_foreach (&it, &tree) {
|
||||
b_btree_node *bnode = b_btree_first(&tree);
|
||||
while (bnode) {
|
||||
struct test_tree_node *node
|
||||
= b_unbox(struct test_tree_node, it.node, node);
|
||||
= b_unbox(struct test_tree_node, bnode, node);
|
||||
CuAssertPtrNotNull(tc, node);
|
||||
|
||||
if (prev == -1) {
|
||||
prev = node->value;
|
||||
bnode = b_btree_next(bnode);
|
||||
continue;
|
||||
}
|
||||
|
||||
CuAssertTrue(tc, prev <= node->value);
|
||||
prev = node->value;
|
||||
bnode = b_btree_next(bnode);
|
||||
}
|
||||
|
||||
free(nodes);
|
||||
@@ -134,19 +136,21 @@ void test_queue_iterate(CuTest *tc)
|
||||
}
|
||||
|
||||
int prev = -1;
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &q) {
|
||||
struct b_queue_entry *entry = b_queue_first(&q);
|
||||
while (entry) {
|
||||
struct test_queue_entry *e
|
||||
= b_unbox(struct test_queue_entry, it.entry, entry);
|
||||
= b_unbox(struct test_queue_entry, entry, entry);
|
||||
CuAssertPtrNotNull(tc, e);
|
||||
|
||||
if (prev == -1) {
|
||||
prev = e->value;
|
||||
continue;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
CuAssertTrue(tc, prev < e->value);
|
||||
prev = e->value;
|
||||
skip:
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,12 @@ int main(void)
|
||||
b_array_append(array, B_RV_INT(64));
|
||||
b_array_append(array, B_RV_INT(128));
|
||||
|
||||
b_array_iterator it;
|
||||
b_array_foreach(&it, array)
|
||||
b_iterator *it = b_iterator_begin(array);
|
||||
b_foreach_ptr(b_object, obj, it)
|
||||
{
|
||||
printf("object %p\n", it.value);
|
||||
printf("object %p\n", obj);
|
||||
}
|
||||
b_iterator_unref(it);
|
||||
|
||||
b_array_unref(array);
|
||||
return 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/ds/dict.h>
|
||||
#include <blue/ds/number.h>
|
||||
#include <blue/ds/tree.h>
|
||||
@@ -21,21 +22,23 @@ B_BTREE_DEFINE_SIMPLE_INSERT(struct btree_item, node, value, put_node)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
b_dict_item items[]
|
||||
= {B_DICT_ITEM("hello", B_RV_INT(32)),
|
||||
B_DICT_ITEM("world", B_RV_INT(64)),
|
||||
B_DICT_ITEM("more", B_RV_INT(128)),
|
||||
B_DICT_ITEM("other", B_RV_INT(256)), B_DICT_ITEM_END};
|
||||
b_dict *dict = b_dict_create();
|
||||
b_dict_put(dict, "hello", B_RV_INT(32));
|
||||
b_dict_put(dict, "world", B_RV_INT(64));
|
||||
b_dict_put(dict, "more", B_RV_INT(128));
|
||||
b_dict_put(dict, "other", B_RV_INT(256));
|
||||
|
||||
b_dict *dict = b_dict_create_with_items(items);
|
||||
b_iterator *it = b_iterator_begin(dict);
|
||||
|
||||
b_dict_iterator it;
|
||||
b_dict_foreach(&it, dict)
|
||||
size_t i = 0;
|
||||
b_foreach(b_dict_item *, item, it)
|
||||
{
|
||||
printf("item %zu: %s=%d\n", it.i, b_string_ptr(it.key),
|
||||
b_number_get_int(it.value));
|
||||
printf("item %zu: %s=%d\n", i++, b_string_ptr(item->key),
|
||||
b_number_get_int(item->value));
|
||||
}
|
||||
|
||||
b_iterator_unref(it);
|
||||
|
||||
b_tree *tree = b_tree_create();
|
||||
struct tree_item items2[NITEMS];
|
||||
|
||||
@@ -54,6 +57,8 @@ int main(void)
|
||||
b_tree_node_add_child(&items2[1].node, &items2[5].node);
|
||||
b_tree_node_add_child(&items2[4].node, &items2[6].node);
|
||||
|
||||
#if 0
|
||||
it = b_iterator_begin(tree);
|
||||
b_tree_iterator it2;
|
||||
b_tree_foreach(&it2, tree)
|
||||
{
|
||||
@@ -113,6 +118,7 @@ int main(void)
|
||||
}
|
||||
|
||||
b_tree_unref(tree);
|
||||
#endif
|
||||
b_dict_unref(dict);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -12,15 +12,15 @@ int main(void)
|
||||
printf("len: %zu\n", b_string_get_size(str, B_STRLEN_NORMAL));
|
||||
printf("codepoints: %zu\n", b_string_get_size(str, B_STRLEN_CODEPOINTS));
|
||||
|
||||
b_string_iterator it;
|
||||
const char *delims[] = {"в"};
|
||||
size_t nr_delims = sizeof delims / sizeof delims[0];
|
||||
|
||||
b_string_tokenise(str, delims, nr_delims, 0, &it);
|
||||
while (b_string_iterator_is_valid(&it)) {
|
||||
printf("%s\n", it.string_value);
|
||||
b_string_iterator_next(&it);
|
||||
b_iterator *it = b_string_tokenise(str, delims, nr_delims, 0);
|
||||
b_foreach(const char *, tok, it)
|
||||
{
|
||||
printf("%s\n", tok);
|
||||
}
|
||||
b_iterator_unref(it);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_directory_iterator it = {0};
|
||||
b_directory_iterator_begin(dir, &it, B_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
while (b_directory_iterator_is_valid(&it)) {
|
||||
printf("%s\n", b_path_ptr(it.filepath));
|
||||
b_directory_iterator_next(&it);
|
||||
b_iterator *it = b_directory_begin(dir, B_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
b_foreach(b_directory_entry *, entry, it)
|
||||
{
|
||||
printf("%s\n", b_path_ptr(entry->filepath));
|
||||
}
|
||||
|
||||
b_iterator_unref(it);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,9 @@ void write_raw_string(const b_string *data)
|
||||
{
|
||||
b_stream_write_string(b_stdout, "\"", NULL);
|
||||
|
||||
b_string_iterator it;
|
||||
b_string_foreach(&it, data)
|
||||
const b_iterator *it = b_iterator_cbegin(data);
|
||||
b_foreach_c(b_wchar, c, it)
|
||||
{
|
||||
b_wchar c = it.char_value;
|
||||
|
||||
if (c >= 0x10000) {
|
||||
c -= 0x10000;
|
||||
long hi = 0xD800 | ((c >> 10) & 0x3FF);
|
||||
@@ -30,6 +28,7 @@ void write_raw_string(const b_string *data)
|
||||
b_stream_write_char(b_stdout, c);
|
||||
}
|
||||
}
|
||||
b_iterator_unref(it);
|
||||
|
||||
b_stream_write_string(b_stdout, "\"", NULL);
|
||||
}
|
||||
@@ -134,17 +133,18 @@ void write_tagged_dict(b_dict *data)
|
||||
|
||||
int i = 0;
|
||||
|
||||
b_dict_iterator it;
|
||||
b_dict_foreach(&it, data)
|
||||
b_iterator *it = b_iterator_begin(data);
|
||||
b_foreach(b_dict_item *, item, it)
|
||||
{
|
||||
if (i++ > 0) {
|
||||
b_stream_write_string(b_stdout, ", ", NULL);
|
||||
}
|
||||
|
||||
write_raw_string(it.key);
|
||||
write_raw_string(item->key);
|
||||
b_stream_write_string(b_stdout, ": ", NULL);
|
||||
write_tagged_value(it.value);
|
||||
write_tagged_value(item->value);
|
||||
}
|
||||
b_iterator_unref(it);
|
||||
|
||||
b_stream_write_string(b_stdout, " }", NULL);
|
||||
}
|
||||
@@ -154,15 +154,16 @@ void write_tagged_array(b_array *data)
|
||||
b_stream_write_string(b_stdout, "[ ", NULL);
|
||||
|
||||
int i = 0;
|
||||
b_array_iterator it;
|
||||
b_array_foreach(&it, data)
|
||||
b_iterator *it = b_iterator_begin(data);
|
||||
b_foreach(b_object *, obj, it)
|
||||
{
|
||||
if (i++ > 0) {
|
||||
b_stream_write_string(b_stdout, ", ", NULL);
|
||||
}
|
||||
|
||||
write_tagged_value(it.value);
|
||||
write_tagged_value(obj);
|
||||
}
|
||||
b_iterator_unref(it);
|
||||
|
||||
b_stream_write_string(b_stdout, " ]", NULL);
|
||||
}
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
k = "v"
|
||||
# "No newlines are allowed between the curly braces unless they are valid within
|
||||
# a value"
|
||||
|
||||
a = []
|
||||
|
||||
Reference in New Issue
Block a user