summaryrefslogtreecommitdiff
path: root/test/unit/expr/declaration_scope_black.h
blob: b1e77c6148c486feedef7a604158f948e7b0a8df (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*********************                                                        */
/*! \file declaration_scope_black.h
 ** \verbatim
 ** Original author: cconway
 ** Major contributors: none
 ** Minor contributors (to current version): mdeters, dejan
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief Black box testing of CVC4::DeclarationScope.
 **
 ** Black box testing of CVC4::DeclarationScope.
 **/

#include <cxxtest/TestSuite.h>

#include <sstream>
#include <string>

#include "context/context.h"
#include "expr/declaration_scope.h"
#include "expr/expr_manager.h"
#include "expr/expr.h"
#include "expr/type.h"
#include "util/Assert.h"
#include "util/exception.h"

using namespace CVC4;
using namespace CVC4::kind;
using namespace CVC4::context;
using namespace std;

class DeclarationScopeBlack : public CxxTest::TestSuite {
private:

  ExprManager* d_exprManager;

public:

  void setUp() {
    try {
      d_exprManager = new ExprManager;
    } catch(Exception e) {
      cerr << "Exception during setUp():" << endl << e;
      throw;
    }
  }

  void tearDown() {
    try {
      delete d_exprManager;
    } catch(Exception e) {
      cerr << "Exception during tearDown():" << endl << e;
      throw;
    }
  }

  void testBind() {
    DeclarationScope declScope;
    Type booleanType = d_exprManager->booleanType();
    Expr x = d_exprManager->mkVar(booleanType);
    declScope.bind("x",x);
    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), x );
  }

  void testBind2() {
    DeclarationScope declScope;
    Type booleanType = d_exprManager->booleanType();
    // var name attribute shouldn't matter
    Expr y = d_exprManager->mkVar("y", booleanType);
    declScope.bind("x",y);
    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), y );
  }

  void testBind3() {
    DeclarationScope declScope;
    Type booleanType = d_exprManager->booleanType();
    Expr x = d_exprManager->mkVar(booleanType);
    declScope.bind("x",x);
    Expr y = d_exprManager->mkVar(booleanType);
    // new binding covers old
    declScope.bind("x",y);
    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), y );
  }

  void testBind4() {
    DeclarationScope declScope;
    Type booleanType = d_exprManager->booleanType();
    Expr x = d_exprManager->mkVar(booleanType);
    declScope.bind("x",x);

    Type t = d_exprManager->mkSort("T");
    // duplicate binding for type is OK
    declScope.bindType("x",t);

    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), x );
    TS_ASSERT( declScope.isBoundType("x") );
    TS_ASSERT_EQUALS( declScope.lookupType("x"), t );
  }

  void testBindType() {
    DeclarationScope declScope;
    Type s = d_exprManager->mkSort("S");
    declScope.bindType("S",s);
    TS_ASSERT( declScope.isBoundType("S") );
    TS_ASSERT_EQUALS( declScope.lookupType("S"), s );
  }

  void testBindType2() {
    DeclarationScope declScope;
    // type name attribute shouldn't matter
    Type s = d_exprManager->mkSort("S");
    declScope.bindType("T",s);
    TS_ASSERT( declScope.isBoundType("T") );
    TS_ASSERT_EQUALS( declScope.lookupType("T"), s );
  }

  void testBindType3() {
    DeclarationScope declScope;
    Type s = d_exprManager->mkSort("S");
    declScope.bindType("S",s);
    Type t = d_exprManager->mkSort("T");
    // new binding covers old
    declScope.bindType("S",t);
    TS_ASSERT( declScope.isBoundType("S") );
    TS_ASSERT_EQUALS( declScope.lookupType("S"), t );
  }

  void testPushScope() {
    DeclarationScope declScope;
    Type booleanType = d_exprManager->booleanType();
    Expr x = d_exprManager->mkVar(booleanType);
    declScope.bind("x",x);
    declScope.pushScope();

    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), x );

    Expr y = d_exprManager->mkVar(booleanType);
    declScope.bind("x",y);

    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), y );

    declScope.popScope();
    TS_ASSERT( declScope.isBound("x") );
    TS_ASSERT_EQUALS( declScope.lookup("x"), x );
  }

  void testBadPop() {
    DeclarationScope declScope;
    // TODO: What kind of exception gets thrown here?
    TS_ASSERT_THROWS( declScope.popScope(), ScopeException );
  }
};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback