source: tests/result.cfa @ 6c57b67

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6c57b67 was 66812dd, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

convert tests to always print output (no empty .expect files)

  • Property mode set to 100644
File size: 1.5 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 : Peter A. Buhr
12// Last Modified On : Fri Sep 25 15:22:59 2020
13// Update Count     : 2
14//
15
16#include <assert.h>
17#include <containers/result.hfa>
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        printf( "done\n" );                             // non-empty .expect file
69}
Note: See TracBrowser for help on using the repository browser.