Esempio n. 1
0
static void
test_string_parser_without_parameter_parses_a_word(void)
{
  assert_parser_success(r_parser_string, "foo", NULL, NULL, "foo");
  assert_parser_success(r_parser_string, "foo bar", NULL, NULL, "foo");
  assert_parser_success(r_parser_string, "foo123 bar", NULL, NULL, "foo123");
  assert_parser_success(r_parser_string, "foo{}", NULL, NULL, "foo");
  assert_parser_success(r_parser_string, "foo[]", NULL, NULL, "foo");
  assert_parser_failure(r_parser_string, "", NULL, NULL);
}
Esempio n. 2
0
END_TEST

START_TEST (zero_length)
{
    char *expression = "";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 0);
    assert_not_null(context);
    assert_errno(EINVAL);

    assert_parser_failure(expression, context, NULL, ERR_ZERO_LENGTH, 0);
    parser_free(context);
}
Esempio n. 3
0
END_TEST

START_TEST (empty_type_test_name)
{
    char *expression = "$.foo.()";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NODE_TYPE_TEST, 6);
    parser_free(context);
    path_free(path);
}
Esempio n. 4
0
END_TEST

START_TEST (bogus_predicate)
{
    char *expression = "$.foo[asdf].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_UNSUPPORTED_PRED_TYPE, 6);
    parser_free(context);
    path_free(path);
}
Esempio n. 5
0
END_TEST

START_TEST (whitespace_predicate)
{
    char *expression = "$.foo[ \t ].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EMPTY_PREDICATE, 9);
    parser_free(context);
    path_free(path);
}
Esempio n. 6
0
END_TEST

START_TEST (extra_junk_in_predicate)
{
    char *expression = "$.foo[ * quux].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXTRA_JUNK_AFTER_PREDICATE, 9);
    parser_free(context);
    path_free(path);
}
Esempio n. 7
0
END_TEST

START_TEST (relative_path_begins_with_dot)
{
    char *expression = ".x";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 2);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NAME_CHAR, 0);
    parser_free(context);
    path_free(path);
}
Esempio n. 8
0
END_TEST

START_TEST (missing_dot)
{
    char *expression = "$x";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 2);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_UNEXPECTED_VALUE, 1);
    parser_free(context);
    path_free(path);
}
Esempio n. 9
0
END_TEST

START_TEST (missing_recursive_step_test)
{
    char *expression = "$..";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 3);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_PREMATURE_END_OF_INPUT, 3);
    parser_free(context);
    path_free(path);
}
Esempio n. 10
0
END_TEST

START_TEST (quoted_empty_step)
{
    char *expression = "$.foo.''.bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NAME_CHAR, 7);
    
    parser_free(context);
    path_free(path);
}
Esempio n. 11
0
END_TEST

START_TEST (negative_subscript_predicate)
{
    char *expression = "$.foo[ -3].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    // xxx - fixme! this should be ERR_EXPECTED_INTEGER instead!
    assert_parser_failure(expression, context, path, ERR_UNSUPPORTED_PRED_TYPE, 7);
    path_free(path);
    parser_free(context);
}
Esempio n. 12
0
END_TEST

START_TEST (zero_step_slice_predicate)
{
    char *expression = "$.foo[::0].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    // xxx - fix me! this should be ERR_STEP_CANNOT_BE_ZERO instead
    // xxx - fix me! this should be position 8 instead, need a non-zero signed int parser
    assert_parser_failure(expression, context, path, ERR_UNSUPPORTED_PRED_TYPE, 9);

    path_free(path);
    parser_free(context);
}