<commit_before>#!perl
# Copyright (C) 2001-2011, Parrot Foundation.

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test;
use Parrot::Config;
use File::Spec::Functions;

plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/);

plan tests => 21;

=head1 NAME

t/src/extend.t - Parrot Extension API

=head1 SYNOPSIS

    % prove t/src/extend.t

=head1 DESCRIPTION

Tests the extension API.

=cut

c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_PMC_null' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_PMC    pmcnull;

    /* Interpreter set-up */
    if (interp) {
        pmcnull  = Parrot_PMC_null();
        Parrot_destroy(interp);
    }
    return 0;
}
CODE
OUTPUT


c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_get_root_namespace/Parrot_(un)register_(pmc|string)' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_PMC    ns;
    Parrot_String string;

    /* Interpreter set-up */
    if (interp) {
        ns  = Parrot_get_root_namespace(interp);
        Parrot_register_pmc(interp, ns);
        Parrot_unregister_pmc(interp, ns);

        Parrot_register_string(interp, string);
        Parrot_unregister_string(interp, string);

        Parrot_printf(interp,"%P\n", ns);
        Parrot_destroy(interp);
    }
    return 0;
}
CODE

OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', 'set/get_intreg' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_Int    parrot_reg = 0;
    Parrot_Int    value      = 42;
    Parrot_Int    new_value;

    /* Interpreter set-up */
    if (interp) {
        Parrot_set_intreg(interp, parrot_reg, value);
        new_value = Parrot_get_intreg(interp, parrot_reg);

        printf("%d\n", (int)new_value);
        Parrot_destroy(interp);
    }
    return 0;
}

CODE
42
OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_printf with no interp');
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_printf(NULL,"42\n");
    return 0;
}

CODE
42<commit_msg>[t] Parrot_fprintf<commit_after>#!perl
# Copyright (C) 2001-2011, Parrot Foundation.

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test;
use Parrot::Config;
use File::Spec::Functions;

plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/);

plan tests => 22;

=head1 NAME

t/src/extend.t - Parrot Extension API

=head1 SYNOPSIS

    % prove t/src/extend.t

=head1 DESCRIPTION

Tests the extension API.

=cut

c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_PMC_null' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_PMC    pmcnull;

    /* Interpreter set-up */
    if (interp) {
        pmcnull  = Parrot_PMC_null();
        Parrot_destroy(interp);
    }
    return 0;
}
CODE
OUTPUT


c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_get_root_namespace/Parrot_(un)register_(pmc|string)' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_PMC    ns;
    Parrot_String string;

    /* Interpreter set-up */
    if (interp) {
        ns  = Parrot_get_root_namespace(interp);
        Parrot_register_pmc(interp, ns);
        Parrot_unregister_pmc(interp, ns);

        Parrot_register_string(interp, string);
        Parrot_unregister_string(interp, string);

        Parrot_printf(interp,"%P\n", ns);
        Parrot_destroy(interp);
    }
    return 0;
}
CODE

OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', 'set/get_intreg' );
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_Interp interp  = Parrot_new(NULL);
    Parrot_Int    parrot_reg = 0;
    Parrot_Int    value      = 42;
    Parrot_Int    new_value;

    /* Interpreter set-up */
    if (interp) {
        Parrot_set_intreg(interp, parrot_reg, value);
        new_value = Parrot_get_intreg(interp, parrot_reg);

        printf("%d\n", (int)new_value);
        Parrot_destroy(interp);
    }
    return 0;
}

CODE
42
OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_fprintf');
#include <stdio.h>
// This is to get Parrot_io_STDOUT, is there a better way?
#include "parrot/parrot.h"
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_PMC pio;
    Parrot_Interp interp  = Parrot_new(NULL);
    pio = Parrot_io_STDOUT(interp);

    /* Interpreter set-up */
    if (interp) {
        Parrot_fprintf(interp, pio,"42\n");
    }
    return 0;
}

CODE
42
OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', 'Parrot_printf with no interp');
#include <stdio.h>
#include "parrot/embed.h"
#include "parrot/extend.h"

int
main(int argc, const char *argv[])
{
    Parrot_printf(NULL,"42\n");
    return 0;
}

CODE
42
{'fraction_non_alphanumeric': 0.1437291897891232, 'fraction_numerical': 0.010543840177580466, 'mean_word_length': 3.435602953240361, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2171418', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2076, 'n_words': 450}