infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
004_signatures.c File Reference

Unit test for the signature string parser. More...

#include "common/double_tap.h"
#include <ctype.h>
#include <infix/infix.h>
#include <string.h>
Include dependency graph for 004_signatures.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

static void test_type_ok (const char *signature, infix_type_category expected_cat, const char *name)
 
static void test_type_fail (const char *signature, const char *name)
 
void dummy_handler ()
 
static void normalize_string (char *s)
 
static void test_print_roundtrip (const char *signature, const char *expected_output)
 
 subtest ("Valid Single Types")
 
 subtest ("Valid Edge Cases (Whitespace, Nesting, Empty)")
 
 subtest ("Valid Full Function Signatures")
 
 subtest ("Invalid Syntax and Logic")
 
 subtest ("Registry Type Introspection")
 
 subtest ("Round trip")
 
 subtest ("Round trip with named fields")
 

Variables

 TEST
 

Detailed Description

Unit test for the signature string parser.

This is one of the most important test files, as it exhaustively validates the correctness and robustness of the infix signature parser. It is divided into several subtests:

  • Valid Single Types: Checks that a wide variety of correct, individual type signatures (primitives, pointers, arrays, aggregates) parse successfully and result in the expected infix_type_category.
  • Valid Edge Cases: Tests the parser's handling of non-standard but valid syntax, such as extra whitespace, comments, empty aggregates ({}), and deeply nested pointer/function types.
  • Valid Full Function Signatures: Uses infix_signature_parse to test the parsing of complete function signatures, including variadic functions (with ;) and named arguments.
  • Invalid Syntax and Logic: A large set of negative test cases that feed the parser deliberately malformed or logically invalid signatures (e.g., [10:void]). It verifies that the parser correctly fails for each case.
  • Round Trip: A critical test that parses a signature, then uses infix_type_print to serialize the resulting type object back into a string. It then verifies that the output string matches the canonical representation of the input, ensuring that parsing and printing are inverse operations.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ dummy_handler()

void dummy_handler ( )

◆ normalize_string()

static void normalize_string ( char *  s)
static

◆ subtest() [1/7]

subtest ( "Invalid Syntax and Logic"  )

◆ subtest() [2/7]

subtest ( "Registry Type Introspection"  )

◆ subtest() [3/7]

subtest ( "Round trip with named fields"  )

◆ subtest() [4/7]

subtest ( "Round trip"  )

◆ subtest() [5/7]

subtest ( "Valid Edge Cases (Whitespace, Nesting, Empty)"  )

◆ subtest() [6/7]

subtest ( "Valid Full Function Signatures"  )

◆ subtest() [7/7]

subtest ( "Valid Single Types"  )

◆ test_print_roundtrip()

static void test_print_roundtrip ( const char *  signature,
const char *  expected_output 
)
static

◆ test_type_fail()

static void test_type_fail ( const char *  signature,
const char *  name 
)
static

◆ test_type_ok()

static void test_type_ok ( const char *  signature,
infix_type_category  expected_cat,
const char *  name 
)
static

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(7)
#define plan(count)
Definition double_tap.h:163