From 6a55637086be8c9df75f6ca3ae8e127f0bb665bf Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 Aug 2010 21:58:02 -0700 Subject: [PATCH] Add tests for a grammar in package scope These tests produce a core dump from Parrot that looks like http://gist.github.com/546982 --- t/sql/plperl6.sql | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/sql/plperl6.sql b/t/sql/plperl6.sql index 14e1790..3a8df73 100644 --- a/t/sql/plperl6.sql +++ b/t/sql/plperl6.sql @@ -115,6 +115,30 @@ CREATE OR REPLACE FUNCTION test_grammar(text) RETURNS integer LANGUAGE plperl6 A } $q$; +CREATE OR REPLACE FUNCTION test_global_grammar(text) RETURNS integer LANGUAGE plperl6 AS $q$ +($item) { + return ?Inventory.parse($item); +} +$q$; + +CREATE OR REPLACE FUNCTION load_global_grammar() RETURNS void LANGUAGE plperl6 AS $q$ +{ + grammar Inventory { + regex product { \d+ } + regex quantity { \d+ } + regex color { \S+ } + regex description { \N* } + rule TOP { ^^ + [ + | '(' \s* \s* ')' + | + ] + $$ + } + } +} +$q$; + CREATE OR REPLACE FUNCTION test_string_plperl6() RETURNS varchar AS $$ { "rakudo" } $$ LANGUAGE plperl6; @@ -143,11 +167,20 @@ select is(test_input_3_args(10,20,30), 20, 'Input 3 named args'); select is(test_regex('PL/Parrot'), 'MATCHED', 'match a regex'); select is(test_regex('PL/Pluto'), 'NO_MATCH', 'do not match a regex'); +-- these tests must come before load_global_grammar() select is(test_grammar('some junk'), 0, 'test a string that does not parse in the Inventory grammar'); select is(test_grammar('123 456 red balloon'), 1, 'test a string that parses in the Inventory grammar'); select is(test_grammar('123 456 balloons (red)'), 1, 'test a string that parses in the Inventory grammar'); select is(test_grammar(''), 0, 'empty string should not parse in the Inventory grammar'); +-- load the Inventory grammar into package scope +select load_global_grammar(); + +select is(test_global_grammar('some junk'), 0, 'test a string that does not parse in the global Inventory grammar'); +select is(test_global_grammar('123 456 red balloon'), 1, 'test a string that parses in the global Inventory grammar'); +select is(test_global_grammar('123 456 balloons (red)'), 1, 'test a string that parses in the global Inventory grammar'); +select is(test_global_grammar(''), 0, 'empty string should not parse in the global Inventory grammar'); + SELECT language_is_trusted( 'plperl6', 'PL/Perl6 should be trusted' ); -- Finish the tests and clean up.