59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
/* Copyright (c) 2023 Peter McGoron <code@mcgoron.com>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
#include "greatest.h"
|
|
GREATEST_MAIN_DEFS();
|
|
#include "../creole.c"
|
|
|
|
/**************************************************************************
|
|
* Reader
|
|
*************************************************************************/
|
|
#define reader_lit(r, s) do { \
|
|
r.p = (unsigned char *)s; \
|
|
r.left = sizeof(s) - 1; \
|
|
} while(0)
|
|
|
|
TEST reader_test_basic(struct creole_reader *r) {
|
|
size_t i = 0;
|
|
unsigned char *s = r->p;
|
|
size_t len = r->left;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
ASSERT_EQ(read_eof(r), 0);
|
|
ASSERT_EQ(read(r), s[i]);
|
|
}
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
ASSERT_EQ(read_eof(r), 1);
|
|
ASSERT_EQ(read(r), -1);
|
|
}
|
|
PASS();
|
|
}
|
|
|
|
SUITE(reader) {
|
|
struct creole_reader r = {0};
|
|
|
|
reader_lit(r, "abcdefg");
|
|
RUN_TEST1(reader_test_basic, &r);
|
|
|
|
reader_lit(r, "");
|
|
RUN_TEST1(reader_test_basic, &r);
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
GREATEST_MAIN_BEGIN();
|
|
RUN_SUITE(reader);
|
|
GREATEST_MAIN_END();
|
|
}
|