AI-Prolog

 view release on metacpan or  search on metacpan

t/80preprocessor_math.t  view on Meta::CPAN

    '(17.2 * (A) % 2 )',
    '(A+B/)C+D+2)',
);
foreach my $not_simple_group_term (@not_simple_group_term) {
    ok ! $CLASS->_simple_group_term($not_simple_group_term), "$not_simple_group_term should not match : simple group term";
}
my @math_term = (
    '3',
    '0.3',
    '3.0',
    '(3)',
    '.3',
    '-.3',
    '( A%2)',
    '(A % 2 )',
    '(17.2 * A % 2 )',
    '(A+B/C+D+2)',
);
foreach my $math_term (@math_term) {
    ok $CLASS->_math_term($math_term), "$math_term matches : math term";
}

my @not_math_term = (
    'x',
    'y_',
    ' % _',
    '3 + ',
    '- 0.3',
);
foreach my $not_math_term (@not_math_term) {
    ok ! $CLASS->_math_term($not_math_term), "$not_math_term should not match : math term";
}

my @complex_rhs = (
    'X',
    'Y_',
    '3',
    '.3',
    '3.0',
    '(3)',
    '( A%2)',
    '(A % 2 )',
    '(17.2 * A % 2 )',
    '(A+B/C+D+2)',
    '2 + (3)',
    '( A%2) / 3 * (2+2)',
);
foreach my $complex_rhs (@complex_rhs) {
    ok $CLASS->_complex_rhs($complex_rhs), "$complex_rhs matches : complex rhs";
}

my @not_complex_rhs = (
    'x',
    '_Y',
    '3)',
);
foreach my $not_complex_rhs (@not_complex_rhs) {
    ok ! $CLASS->_complex_rhs($not_complex_rhs), "$not_complex_rhs should not match : complex rhs";
}

#print $CLASS->expression;
my @complex_group_term = (
    '( X )',
    '( Y_ )',
    '( 3 )',
    '( .3 )',
    '( 3.0 )',
    '( (3) )',
    '(( A%2) )',
    '( (A % 2 ) )',
    '( (17.2 * A % 2 ) )',
    '( (A+B/C+D+2))',
    '(2 + (3))',
    '( ( A%2) / 3 * (2+2) )',
);
foreach my $complex_group_term (@complex_group_term) {
    ok $CLASS->_complex_group_term($complex_group_term), "$complex_group_term matches : complex group term";
}

my @not_complex_group_term = (
    '( x )',
    '()',
    '( 3',
    '( .3 ))',
    '(( 3.)0 )',
    '(( A%2 )',
    '( (A+B/(C+D+2))',
    '( ( A%2) (/) 3 * (2+2) )',
);
foreach my $not_complex_group_term (@not_complex_group_term) {
    ok ! $CLASS->_complex_group_term($not_complex_group_term), "$not_complex_group_term should not match : complex group term";
}

can_ok $CLASS, '_lex';
my $rhs = '3';
is_deeply $CLASS->_lex($rhs), [[qw/ ATOM 3 /]], "$rhs : lexes properly";

$rhs = 'A + 3';
is_deeply $CLASS->_lex($rhs), [
    [qw/ ATOM A /],
    [qw/ OP   + /],
    [qw/ ATOM 3 /]
], "$rhs : lexes properly";

$rhs = 'A ** 3';
is_deeply $CLASS->_lex($rhs), [
    [qw/ ATOM A  /],
    [qw/ OP   ** /],
    [qw/ ATOM 3  /]
], "$rhs : lexes properly";

$rhs = '3 * ( 7 +4)';
is_deeply $CLASS->_lex($rhs), [
    [qw/ ATOM   3 /],
    [qw/ OP     * /],
    [qw/ LPAREN ( /],
    [qw/ ATOM   7 /],
    [qw/ OP     + /],
    [qw/ ATOM   4 /],
    [qw/ RPAREN ) /],
], "$rhs : lexes properly";



( run in 0.535 second using v1.01-cache-2.11-cpan-39bf76dae61 )