1#!./parrot
2# Copyright (C) 2007-2009, Parrot Foundation.
3
4=head1 NAME
5
6t/compilers/pge/04-compile.t - Test our ability to compile regexes into various names
7
8=head1 SYNOPSIS
9
10        % prove t/compilers/pge/04-compile.t
11
12=head1 DESCRIPTION
13
14Tests various arguments to the compiler.
15
16=cut
17
18.namespace []
19
20.sub main :main
21    .include 'test_more.pir'
22    plan(4)
23
24    test_basic_compile_no_name_grammar()
25    test_compile_into_current_namespace()
26    test_compile_into_a_new_grammar()
27    test_compile_into_a_new_grammar_2x()
28.end
29
30
31.sub test_basic_compile_no_name_grammar
32    load_bytecode 'PGE.pbc'
33
34    .local pmc p6compiler
35    p6compiler = compreg 'PGE::Perl6Regex'
36    $P1 = p6compiler('.+')
37    $P2 = $P1('ok 1')
38    is($P2, 'ok 1', 'basic compile, no name/grammar')
39.end
40
41
42.sub test_compile_into_current_namespace
43    load_bytecode 'PGE.pbc'
44
45    .local pmc p6compiler
46    p6compiler = compreg 'PGE::Perl6Regex'
47    $P1 = p6compiler('.+', 'name'=>'xyz', 'grammar'=>'')
48    $P2 = 'xyz'('ok 1')
49    is($P2, 'ok 1', 'compile into current namespace')
50.end
51
52
53.sub test_compile_into_a_new_grammar
54    load_bytecode 'PGE.pbc'
55
56    .local pmc p6compiler
57    p6compiler = compreg 'PGE::Perl6Regex'
58    $P1 = p6compiler('.+', 'name'=>'xyz1', 'grammar'=>'PGE::Test')
59    $P2 = get_hll_global ['PGE';'Test'], 'xyz1'
60    $P3 = $P2('ok 1')
61    is($P3, 'ok 1', 'compile into a new grammar')
62.end
63
64
65.sub test_compile_into_a_new_grammar_2x
66    load_bytecode 'PGE.pbc'
67
68    .local pmc p6compiler
69    p6compiler = compreg 'PGE::Perl6Regex'
70    $P1 = p6compiler('.+', 'name'=>'abc', 'grammar'=>'PGE::Test')
71    $P1 = p6compiler('.+', 'name'=>'xyz2', 'grammar'=>'PGE::Test')
72    $P2 = get_hll_global ['PGE';'Test'], 'abc'
73    $P3 = $P2('ok 1')
74    is($P3, 'ok 1', 'compile into a new grammar, 2x')
75.end
76
77# Local Variables:
78#   mode: pir
79#   fill-column: 100
80# End:
81# vim: expandtab shiftwidth=4 ft=pir:
82