1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "miniunit.h"
#include "json.h"
// okay to copy/adapt
int _test_two_digits_with_trailing_characters() {
mu_start();
//────────────────────
int value;
char const* input = "52aaaaaaaaaaaaaaa";
char const* pos = input;
bool is_success = parse_int(&value, &pos);
mu_check(is_success);
mu_check(value == 52);
mu_check(*pos == 'a');
mu_check(pos == input + 2);
//────────────────────
mu_end();
}
int _test_invalid_leading_negative() {
mu_start();
//────────────────────
// dummy value to ensure its not modified
int value = 127;
char const* input = "-B";
char const* pos = input;
bool is_success = parse_int(&value, &pos);
mu_check(!is_success);
mu_check(value == 127); // still dummy value
mu_check(*pos == 'B');
mu_check(pos == input + 1);
//────────────────────
mu_end();
}
int main(int argc, char* argv[]) {
mu_run(_test_invalid_leading_negative);
mu_run(_test_two_digits_with_trailing_characters);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2024 Alexander J. Quinn & David Burnett This content is protected and may not be shared, uploaded, or distributed.