static int failures = 0;

void expect_string(string label, PhpefRuntimeCore.Zval actual, string expected) {
    string actual_text = actual.to_php_string();
    if (actual_text != expected) {
        stderr.printf("%s: expected '%s', got '%s'\n", label, expected, actual_text);
        failures++;
    }
}

void expect_int(string label, PhpefRuntimeCore.Zval actual, int64 expected) {
    int64 actual_value = (int64) actual.to_float_zval().as_float();
    if (actual_value != expected) {
        stderr.printf("%s: expected %" + int64.FORMAT + ", got %" + int64.FORMAT + "\n", label, expected, actual_value);
        failures++;
    }
}

int main(string[] args) {
    PhpefRuntimeCore.init(args);

    expect_string("PHP_EOL", PhpefRuntimeNativeStandard.phpfunc_constant(PhpefRuntimeCore.Zval.from_string("PHP_EOL")), "\n");
    expect_string("PHP_VERSION", PhpefRuntimeNativeStandard.phpfunc_constant(PhpefRuntimeCore.Zval.from_string("PHP_VERSION")), "8.3.29");
    expect_int("PHP_VERSION_ID", PhpefRuntimeNativeStandard.phpfunc_constant(PhpefRuntimeCore.Zval.from_string("PHP_VERSION_ID")), 80329);
    expect_string("DIRECTORY_SEPARATOR", PhpefRuntimeNativeStandard.phpfunc_constant(PhpefRuntimeCore.Zval.from_string("DIRECTORY_SEPARATOR")), "/");
    expect_string("PATH_SEPARATOR", PhpefRuntimeNativeStandard.phpfunc_constant(PhpefRuntimeCore.Zval.from_string("PATH_SEPARATOR")), ":");

    expect_string("typed PHP_EOL", PhpefRuntimeNativeStandard.phpfunc_constant_typed_zval_arg1_string("PHP_EOL"), "\n");
    expect_int("typed PHP_VERSION_ID", PhpefRuntimeNativeStandard.phpfunc_constant_typed_zval_arg1_string("PHP_VERSION_ID"), 80329);

    if (failures != 0) {
        return 1;
    }
    stdout.printf("ok - native standard constant wrappers\n");
    return 0;
}
