1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
use File::Spec;
use lib (File::Spec->catdir(File::Spec->updir(),'blib','lib'), File::Spec->catdir(File::Spec->curdir(),'blib','lib'));
use strict;
use Test;
use diagnostics;
use Inline Config => DIRECTORY => '_Inline_test';
BEGIN {
plan(tests => 5,
todo => [],
onfail => sub {},
);
}
use Inline Config =>
DIRECTORY => '_Inline_test';
# test 1 - Check string syntax
ok(add(3, 7) == 10);
# test 2 - Check string syntax again
ok(subtract(3, 7) == -4);
# test 3 - Check DATA syntax
ok(multiply(3, 7) == 21);
# test 4 - Check DATA syntax again
ok(divide(7, -3) == -2);
use Inline 'C';
use Inline C => 'DATA';
use Inline C => <<'END_OF_C_CODE';
int add(int x, int y) {
return x + y;
}
int subtract(int x, int y) {
return x - y;
}
END_OF_C_CODE
Inline->bind(C => <<'END');
int incr(int x) {
return x + 1;
}
END
# test 5 - Test Inline->bind() syntax
ok(incr(incr(7)) == 9);
__END__
# unused code or maybe AutoLoader stuff
sub crap {
return 'crap';
}
__C__
int multiply(int x, int y) {
return x * y;
}
__C__
int divide(int x, int y) {
return x / y;
}
|