Пример #1
0
char *test_array_shift()
{
    test_assert(a->length == 0, "Array is not empty");

    Array_shift(a, one);
    test_assert(a->length == 1, "Array length is not 1");
    test_assert_streq(Array_first(a), one, "Wrong first element: one");

    Array_shift(a, two);
    test_assert(a->length == 2, "Array length is not 2");
    test_assert_streq(Array_first(a), two, "Wrong second element: two");

    Array_shift(a, three);
    test_assert(a->length == 3, "Array length is not 3");
    test_assert_streq(Array_first(a), three, "Wrong second element: three");

    test_assert_streq(a->elements[0], three, "Wrong element: three");
    test_assert_streq(a->elements[1], two, "Wrong element: two");
    test_assert_streq(a->elements[2], one, "Wrong element: one");

    return NULL;
}
Пример #2
0
int main(void) {
    // static string
    Value a;
    Value_type(&a, StaticString);
    Value_set_str(&a, "a");
    Value_get_str(&a);

    // string
    void * b = new(String, "b");

    // hash
    void * hash = new(Hash);
    Hash_set(hash, &a, b);
    void * c = Hash_get(hash, &a);
    puts(Object_inspect(c));
    delete(hash);

    // array
    void * ary = new(Array);
    Array_push(ary, &a);
    Array_unshift(ary, b);
    void * d = Array_shift(ary);
    puts(Object_inspect(d));
    delete(ary);

    delete(b);

    // file
    void * file = new(File, "libooc/example");
    void * content = File_read(file);
    puts(Object_inspect(content));
    delete(file);

    void write_file(void * file) {
        File_puts(file, "hello");
        File_printf(file, " w%drld", 0);
    }