Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-635.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e843091b9ab2bacc7b3dd226165752f8912e3269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;

class ShortCircuitFold {
  static int calls;
  static bool False { get { ++calls; return false; } }
  static bool True { get { ++calls; return true; } }
  static void a (bool e, bool v) { if (e != v) throw new Exception ("unexpected value"); }
  static void c (int e) { if (e != calls) throw new Exception ("call count mismatch: expected " + e + " but got " + calls); }
  static bool f () { throw new Exception ("not short circuited out"); }
  static void Main ()
  {
    // short circuit out f ()
    a (false, false && f ());
    a (true,  true || f ());

    // short circuit out side effects
    a (false, false && False); c (0);
    a (true,  true || True);   c (0);

    // ensure all side effects occur
    a (false, true && False);  c (1);
    a (true,  false || True);  c (2);

    a (false, false & False);  c (3);
    a (true,  true | True);    c (4);

    a (false, true & False);   c (5);
    a (true,  false | True);   c (6);
  }
}