source: src/tests/result.c @ b5f9829

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since b5f9829 was 0892b1b, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Fixed random comment in result test.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// result.c --
8//
9// Author           : Andrew Beach
10// Created On       : Thr May 25 16:50:00 2017
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Jun 16 15:42:00 2017
13// Update Count     : 0
14//
15
16#include <assert>
17#include <containers/result>
18
19void checkPredicates() {
20        result(int, char) pass = {1, 4};
21        assert(pass);
22        assert(has_value(&pass));
23
24        result(int, char) fail = {0, '!'};
25        assert((fail ? false : true));
26        assert(!has_value(&fail));
27}
28
29/* Waiting for bug#11 to be fixed.
30void checkNamedConstructors() {
31        result(int, char) = result_value(4);
32        assert(has_value(&pass));
33
34        result(int, char) fail = result_error('!');
35        assert(!has_value(&fail));
36}
37*/
38
39void checkGetters() {
40        result(int, char) pass = {1, 4};
41        assert(4 == get(&pass));
42
43        result(int, char) fail = {0, '!'};
44        assert('!' == get_error(&fail));
45}
46
47void checkSetters() {
48        result(int, char) fee = {1, -7};
49        assert(-7 == get(&fee));
50        set(&fee, 42);
51        assert(42 == get(&fee));
52        set_error(&fee, '@');
53        assert('@' == get_error(&fee));
54
55        result(int, char) fy = {1, -7};
56        fee = fy;
57        assert(-7 == get(&fee));
58        result(int, char) foe = {0, '!'};
59        fee = foe;
60        assert('!' == get_error(&fee));
61}
62
63int main(int argc, char * argv[]) {
64        checkPredicates();
65        //checkNamedConstructors();
66        checkGetters();
67        checkSetters();
68}
Note: See TracBrowser for help on using the repository browser.