"Fossies" - the Fresh Open Source Software Archive

Member "eprints3.4-3.4.4/tests/11_epscript.pl" (7 Aug 2022, 6317 Bytes) of package /linux/www/eprints3.4-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "11_epscript.pl": 3.4-3.4.3_vs_3.4-3.4.4.

    1 use strict;
    2 use Test::More tests => (32);
    3 
    4 BEGIN { use_ok( "EPrints" ); }
    5 BEGIN { use_ok( "EPrints::Test" ); }
    6 
    7 my $session = EPrints::Test::get_test_session( 0 );
    8 my $rv;
    9 
   10 $rv = EPrints::Script::execute( "2", { session=>$session } );
   11 ok( defined $rv, "EPScript returns a value" );
   12 is( $rv->[0], 2, "EPScript returns correct value?" );
   13 is( $rv->[1], "INTEGER", "EPScript returns correct value?" );
   14 
   15 $rv = EPrints::Script::execute( '$foo{bar}', { session=>$session, foo=>{ bar=>23 } } );
   16 is( $rv->[0], 23, "Value from a passed parameter" );
   17 
   18 $rv = EPrints::Script::execute( '17+9', { session=>$session } );
   19 is( $rv->[0], 26, "17+9: Basic Math" );
   20 
   21 $rv = EPrints::Script::execute( '17-9', { session=>$session } );
   22 is( $rv->[0], 8, "17-9: Basic Math" );
   23 
   24 $rv = EPrints::Script::execute( '-42', { session=>$session } );
   25 is( $rv->[0], -42, "-42: Unary minus" );
   26 
   27 $rv = EPrints::Script::execute( '1--42', { session=>$session } );
   28 is( $rv->[0], 43, "1--42: Unary minus again" );
   29 
   30 $rv = EPrints::Script::execute( '-5*---(2+3)', { session=>$session } );
   31 is( $rv->[0], 25, "-5*---(2+3): Unary minus with brackets and stacked uminus" );
   32 
   33 $rv = EPrints::Script::execute( '$list.join(":")', { session=>$session, list=>[[1,2,3],"ARRAY"] } );
   34 is( $rv->[0], "1:2:3", "join() function" );
   35 
   36 my $mfield = $session->dataset( "user" )->field( "roles" );
   37 $rv = EPrints::Script::execute( '$list.join(":")', { session=>$session, list=>[["a","b","c"],$mfield] } );
   38 is( $rv->[0], "a:b:c", "join() function on a multiple field value" );
   39 
   40 # Test one_of()
   41 # Added by QUT, 20130522 for modified one_of() function
   42 
   43 # Test original operation, i.e., items as an argument list
   44 # Should match
   45 $rv = EPrints::Script::execute( '$value.one_of("1","2","3")', { session=>$session, value=>["1","STRING"] } );
   46 is( $rv->[0], "1", "one_of() function passed list of items, value matches on lower boundary item" );
   47 
   48 $rv = EPrints::Script::execute( '$value.one_of("1","2","3")', { session=>$session, value=>["3","STRING"] } );
   49 is( $rv->[0], "1", "one_of() function passed list of items, value matches on upper boundary item" );
   50 
   51 $rv = EPrints::Script::execute( '$value.one_of("1")', { session=>$session, value=>["1","STRING"] } );
   52 is( $rv->[0], "1", "one_of() function passed list with single item, value matches" );
   53 
   54 $rv = EPrints::Script::execute( '$value.one_of(1,2,3)', { session=>$session, value=>[1,"INT"] } );
   55 is( $rv->[0], "1", "one_of() function integer values, matching" );
   56 
   57 $rv = EPrints::Script::execute( '$value.one_of("one","two","three")', { session=>$session, value=>["one","STRING"] } );
   58 is( $rv->[0], "1", "one_of() function string values, matching" );
   59 
   60 
   61 # Shouldn't match
   62 $rv = EPrints::Script::execute( '$value.one_of("1","2","3")', { session=>$session, value=>["4","STRING"] } );
   63 is( $rv->[0], "0", "one_of() function passed list of items, value doesn't match" );
   64 
   65 $rv = EPrints::Script::execute( '$value.one_of("1")', { session=>$session, value=>["4","STRING"] } );
   66 is( $rv->[0], "0", "one_of() function passed list with single item, value doesn't match" );
   67 
   68 $rv = EPrints::Script::execute( '$value.one_of()', { session=>$session, value=>["4","STRING"] } );
   69 is( $rv->[0], "0", "one_of() function passed no arguments, value doesn't match" );
   70 
   71 $rv = EPrints::Script::execute( '$value.one_of(1,2,3)', { session=>$session, value=>[4,"INT"] } );
   72 is( $rv->[0], "0", "one_of() function integer values, no match" );
   73 
   74 $rv = EPrints::Script::execute( '$value.one_of("one","two","three")', { session=>$session, value=>["four","STRING"] } );
   75 is( $rv->[0], "0", "one_of() function string values, no match" );
   76 
   77 
   78 # Test array ref operation
   79 # Should match
   80 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["1","STRING"], array=>[ ["1","2","3"], "ARRAY"] } );
   81 is( $rv->[0], "1", "one_of() function passed array ref, value matches on lower boundary item" );
   82 
   83 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["3","STRING"], array=>[ ["1","2","3"], "ARRAY"] } );
   84 is( $rv->[0], "1", "one_of() function passed array ref, value matches on upper boundary item" );
   85 
   86 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["1","STRING"], array=>[ ["1"], "ARRAY"] } );
   87 is( $rv->[0], "1", "one_of() function passed array ref with single item, value matches" );
   88 
   89 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>[1,"INT"], array=>[ [1,2,3], "ARRAY"] } );
   90 is( $rv->[0], "1", "one_of() function passed array ref, integer values, value matches" );
   91 
   92 # Shouldn't match
   93 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["4","STRING"], array=>[ ["1","2","3"], "ARRAY"] } );
   94 is( $rv->[0], "0", "one_of() function passed array ref with multiple elements, value doesn't match" );
   95 
   96 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["4","STRING"], array=>[ ["1"], "ARRAY"] } );
   97 is( $rv->[0], "0", "one_of() function passed array ref with single element, value doesn't match" );
   98 
   99 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>["4","STRING"], array=>[ [], "ARRAY"] } );
  100 is( $rv->[0], "0", "one_of() function passed empty array ref arg" );
  101 
  102 $rv = EPrints::Script::execute( '$value.one_of($array)', { session=>$session, value=>[4,"INT"], array=>[ [1,2,3], "ARRAY"] } );
  103 is( $rv->[0], "0", "one_of() function passed array ref, integer values, value matches" );
  104 
  105 $session->terminate;
  106 
  107 ok(1);
  108 
  109 
  110 =head1 COPYRIGHT
  111 
  112 =for COPYRIGHT BEGIN
  113 
  114 Copyright 2022 University of Southampton.
  115 EPrints 3.4 is supplied by EPrints Services.
  116 
  117 http://www.eprints.org/eprints-3.4/
  118 
  119 =for COPYRIGHT END
  120 
  121 =for LICENSE BEGIN
  122 
  123 This file is part of EPrints 3.4 L<http://www.eprints.org/>.
  124 
  125 EPrints 3.4 and this file are released under the terms of the
  126 GNU Lesser General Public License version 3 as published by
  127 the Free Software Foundation unless otherwise stated.
  128 
  129 EPrints 3.4 is distributed in the hope that it will be useful,
  130 but WITHOUT ANY WARRANTY; without even the implied warranty of
  131 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  132 See the GNU Lesser General Public License for more details.
  133 
  134 You should have received a copy of the GNU Lesser General Public
  135 License along with EPrints 3.4.
  136 If not, see L<http://www.gnu.org/licenses/>.
  137 
  138 =for LICENSE END
  139