js/src/tests/ecma_3/Statements/switch-001.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Statements/switch-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 07 May 2001
    1.11 + *
    1.12 + * SUMMARY: Testing the switch statement
    1.13 + *
    1.14 + * See ECMA3  Section 12.11,  "The switch Statement"
    1.15 + */
    1.16 +//-----------------------------------------------------------------------------
    1.17 +var UBound = 0;
    1.18 +var BUGNUMBER = '(none)';
    1.19 +var summary = 'Testing the switch statement';
    1.20 +var cnMatch = 'Match';
    1.21 +var cnNoMatch = 'NoMatch';
    1.22 +var status = '';
    1.23 +var statusitems = [ ];
    1.24 +var actual = '';
    1.25 +var actualvalues = [ ];
    1.26 +var expect= '';
    1.27 +var expectedvalues = [ ];
    1.28 +
    1.29 +
    1.30 +status = 'Section A of test';
    1.31 +actual = match(17, f(fInverse(17)), f, fInverse);
    1.32 +expect = cnMatch;
    1.33 +addThis();
    1.34 +
    1.35 +status = 'Section B of test';
    1.36 +actual = match(17, 18, f, fInverse);
    1.37 +expect = cnNoMatch;
    1.38 +addThis();
    1.39 +
    1.40 +status = 'Section C of test';
    1.41 +actual = match(1, 1, Math.exp, Math.log);
    1.42 +expect = cnMatch;
    1.43 +addThis();
    1.44 +
    1.45 +status = 'Section D of test';
    1.46 +actual = match(1, 2, Math.exp, Math.log);
    1.47 +expect = cnNoMatch;
    1.48 +addThis();
    1.49 +
    1.50 +status = 'Section E of test';
    1.51 +actual = match(1, 1, Math.sin, Math.cos);
    1.52 +expect = cnNoMatch;
    1.53 +addThis();
    1.54 +
    1.55 +
    1.56 +
    1.57 +//---------------------------------------------------------------------------------
    1.58 +test();
    1.59 +//---------------------------------------------------------------------------------
    1.60 +
    1.61 +
    1.62 +
    1.63 +/*
    1.64 + * If F,G are inverse functions and x==y, this should return cnMatch -
    1.65 + */
    1.66 +function match(x, y, F, G)
    1.67 +{
    1.68 +  switch (x)
    1.69 +  {
    1.70 +  case F(G(y)):
    1.71 +    return cnMatch;
    1.72 +
    1.73 +  default:
    1.74 +    return cnNoMatch;
    1.75 +  }
    1.76 +}
    1.77 +
    1.78 +
    1.79 +function addThis()
    1.80 +{
    1.81 +  statusitems[UBound] = status;
    1.82 +  actualvalues[UBound] = actual;
    1.83 +  expectedvalues[UBound] = expect;
    1.84 +  UBound++;
    1.85 +}
    1.86 +
    1.87 +
    1.88 +function test()
    1.89 +{
    1.90 +  enterFunc ('test');
    1.91 +  printBugNumber(BUGNUMBER);
    1.92 +  printStatus (summary);
    1.93 +
    1.94 +  for (var i = 0; i < UBound; i++)
    1.95 +  {
    1.96 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.97 +  }
    1.98 +
    1.99 +  exitFunc ('test');
   1.100 +}
   1.101 +
   1.102 +
   1.103 +function f(m)
   1.104 +{
   1.105 +  return 2*(m+1);
   1.106 +}
   1.107 +
   1.108 +
   1.109 +function fInverse(n)
   1.110 +{
   1.111 +  return (n-2)/2;
   1.112 +}

mercurial