Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of all options in jfmt #769

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Release 1.0.32 2023-07-16

Add **TEMPORARY PLACEHOLDER** source and header files for `jfmt`, `jval` and
Add initial code for `jfmt`: completely parses options and will dump JSON to
output file if it is not the same as the input file and the file does not
already exist. If not specified it will be stdout.

Add **TEMPORARY PLACEHOLDER** source and header files for `jval` and
`jnamval` tools. The key term that is important is _TEMPORARY PLACEHOLDER_. The
files are actually copies of what were once jprint related but for each tool
jprint / JPRINT were changed to their new tool counterparts. This is done this
Expand Down
487 changes: 66 additions & 421 deletions jparse/jfmt.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jparse/jfmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#include "jparse.h"

/* jfmt version string */
#define JFMT_VERSION "0.0.0 2023-07-16" /* format: major.minor YYYY-MM-DD */
#define JFMT_VERSION "0.0.1 2023-07-16" /* format: major.minor YYYY-MM-DD */

/* jfmt functions - see jfmt_util.h for most */

Expand Down
192 changes: 0 additions & 192 deletions jparse/jfmt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jfmt_run_tests(void)
struct jfmt_number number; /* number range */
bool test = false; /* whether current test passes or fails */
bool okay = true; /* if any test fails set to true, is return value */
uintmax_t bits = 0; /* for bits tests */

/* set up exact match of 5 */
jfmt_parse_number_range("-l", "5", false, &number);
Expand Down Expand Up @@ -140,197 +139,6 @@ jfmt_run_tests(void)
okay = false;
}

/* now check bits */

/* set bits to JFMT_PRINT_BOTH */
bits = jfmt_parse_print_option("both");

/* check that JFMT_PRINT_BOTH is equal to bits */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_print_name_value, "JFMT_PRINT_BOTH");
if (!test) {
okay = false;
}

/* set bits to JFMT_PRINT_NAME */
bits = jfmt_parse_print_option("name");
/* check that only JFMT_PRINT_NAME is set: both and value are not set */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_print_name, "JFMT_PRINT_NAME") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_print_value, "JFMT_PRINT_VALUE") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_print_name_value, "JFMT_PRINT_BOTH");

if (!test) {
okay = false;
}
/* set bits to JFMT_PRINT_VALUE */
bits = jfmt_parse_print_option("v");
/* check that only JFMT_PRINT_VALUE is set: both and name are not set */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_print_value, "JFMT_PRINT_VALUE") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_print_name, "JFMT_PRINT_NAME") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_print_name_value, "JFMT_PRINT_BOTH");

if (!test) {
okay = false;
}

/* test -t option bits */

/* first int,float,exp */
bits = jfmt_parse_types_option("int,float,exp");
/* check that any number will match */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_float, "JFMT_TYPE_FLOAT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_exp, "JFMT_TYPE_EXP");
if (!test) {
okay = false;
}

/* just exponents */
bits = jfmt_parse_types_option("exp");
/* check that int and float will fail but exp will succeed */
test = jfmt_test_bits(false, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_float, "JFMT_TYPE_FLOAT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_exp, "JFMT_TYPE_EXP");
if (!test) {
okay = false;
}

/* test all types */
bits = jfmt_parse_types_option("any");
/* verify that it is the any bit */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_any, "JFMT_TYPE_ANY");
if (!test) {
okay = false;
}

/* test compound */
bits = jfmt_parse_types_option("compound");
/* verify that the compound type is set by compound match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_compound, "JFMT_TYPE_COMPOUND");
if (!test) {
okay = false;
}
/* verify that the compound type is set by matching all types */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_object, "JFMT_TYPE_OBJECT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_array, "JFMT_TYPE_ARRAY");
if (!test) {
okay = false;
}

/* test simple */
bits = jfmt_parse_types_option("simple");
/* verify that the simple type is set by simple match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_simple, "JFMT_TYPE_SIMPLE");
if (!test) {
okay = false;
}
/* verify that the simple type is set by matching each type */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_num, "JFMT_TYPE_NUM") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_bool, "JFMT_TYPE_BOOL") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_string, "JFMT_TYPE_STR") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_null, "JFMT_TYPE_NULL");
if (!test) {
okay = false;
}

/* test int */
bits = jfmt_parse_types_option("int");
/* verify that the int type is set by int match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT");
if (!test) {
okay = false;
}

/* test float */
bits = jfmt_parse_types_option("float");
/* verify that the float type is set by float match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_float, "JFMT_TYPE_FLOAT");
if (!test) {
okay = false;
}

/* test exp */
bits = jfmt_parse_types_option("exp");
/* verify that the exp type is set by exp match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_exp, "JFMT_TYPE_EXP");
if (!test) {
okay = false;
}

/* test bool */
bits = jfmt_parse_types_option("bool");
/* verify that the bool type is set by bool match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_bool, "JFMT_TYPE_BOOL");
if (!test) {
okay = false;
}

/* test string */
bits = jfmt_parse_types_option("str");
/* verify that the string type is set by string match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_string, "JFMT_TYPE_STR");
if (!test) {
okay = false;
}

/* test null */
bits = jfmt_parse_types_option("null");
/* verify that the null type is set by null match function */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_null, "JFMT_TYPE_NULL");
if (!test) {
okay = false;
}

/* test int,str,null */
bits = jfmt_parse_types_option("int,str,null");
/* verify that the int,str,null types are set by match functions */
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_string, "JFMT_TYPE_STR") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_null, "JFMT_TYPE_NULL");
if (!test) {
okay = false;
}

/*
* test that none of the bits are set not via the match none function but by
* each match function
*/
bits = JFMT_TYPE_NONE;
test = jfmt_test_bits(false, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_float, "JFMT_TYPE_FLOAT") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_exp, "JFMT_TYPE_EXP") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_num, "JFMT_TYPE_NUM") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_bool, "JFMT_TYPE_BOOL") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_string, "JFMT_TYPE_STR") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_null, "JFMT_TYPE_NULL") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_object, "JFMT_TYPE_OBJECT") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_array, "JFMT_TYPE_ARRAY") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_any, "JFMT_TYPE_ANY") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_simple, "JFMT_TYPE_SIMPLE") &&
jfmt_test_bits(false, bits, __LINE__, jfmt_match_compound, "JFMT_TYPE_COMPOUND");
if (!test) {
okay = false;
}

/* check all types */
bits = jfmt_parse_types_option("int,float,exp,num,bool,str,null,object,array,any,simple,compound");
test = jfmt_test_bits(true, bits, __LINE__, jfmt_match_int, "JFMT_TYPE_INT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_float, "JFMT_TYPE_FLOAT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_exp, "JFMT_TYPE_EXP") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_num, "JFMT_TYPE_NUM") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_bool, "JFMT_TYPE_BOOL") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_string, "JFMT_TYPE_STR") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_null, "JFMT_TYPE_NULL") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_object, "JFMT_TYPE_OBJECT") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_array, "JFMT_TYPE_ARRAY") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_any, "JFMT_TYPE_ANY") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_simple, "JFMT_TYPE_SIMPLE") &&
jfmt_test_bits(true, bits, __LINE__, jfmt_match_compound, "JFMT_TYPE_COMPOUND");
if (!test) {
okay = false;
}



return okay;
}

Expand Down
Loading