/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to tests/value-token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-07 18:48:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200607184824-jf14f7a1b1di2i2q
* Initial code - far from done

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
void
4
4
test_value_token () {
5
 
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/sanity", () => {
 
5
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/sanity", () => {
6
6
    var ctx = new Context ();
7
7
    
8
8
    if (ctx == null) {
20
20
    var v1 = new ConstantValueToken (13,37);
21
21
    var v2 = new VariableValueToken ("my-val", 13);
22
22
    
 
23
    #if 0
 
24
    // This should work, but it does not... It is a vala parsing bug...
 
25
    // I think...
 
26
    bool value_test = ((v1 is typeof (ConstantValueToken)) ||
 
27
                       (v1 is typeof (ValueToken)) ||
 
28
                       (v1 is typeof (Token)));
 
29
    
 
30
    #endif
 
31
    
23
32
    Type t1 = v1.get_type ();
24
 
    if (!(t1.is_a (typeof (ConstantValueToken)) &&
25
 
          t1.is_a (typeof (ValueToken)) &&
26
 
          t1.is_a (typeof (Token)))) {
 
33
    if (!(t1.is_a (typeof (ConstantValueToken))) ||
 
34
        !(t1.is_a (typeof (ValueToken))) ||
 
35
        !(t1.is_a (typeof (Token)))) {
27
36
      GLib.Test.message ("The ConstastValueToken is not the corret type.");
28
37
      GLib.Test.fail ();
29
38
      GLib.assert_not_reached ();
30
39
    }
31
40
    
32
41
   Type t2 = v2.get_type ();
33
 
    if (!((t2.is_a (typeof (VariableValueToken))) &&
34
 
          (t2.is_a (typeof (ValueToken))) &&
35
 
          (t2.is_a (typeof (Token))))) {
36
 
      GLib.Test.message ("The VariableValueToken is not the corret type.");
37
 
      GLib.Test.fail ();
38
 
      GLib.assert_not_reached ();
39
 
    }
40
 
    
41
 
  });
42
 
  
43
 
  GLib.Test.add_func ("/VQDR/Expression/token/Value/Factory", () => {
44
 
    var v3 = ValueToken.init_value_token (13L, 37);
45
 
    var v4 = ValueToken.init_value_token ("foo", 12);
46
 
    Type t4 = v4.get_type ();
47
 
    Type t3 = v3.get_type ();
48
 
    
49
 
    
50
 
    if (!(t3.is_a (typeof (ConstantValueToken))) &&
51
 
          t3.is_a (typeof (ValueToken)) &&
52
 
          t3.is_a (typeof (Token))) {
53
 
      GLib.Test.message ("The ConstastValueToken is not the corret type.");
54
 
      GLib.Test.fail ();
55
 
      GLib.assert_not_reached ();
56
 
    }
57
 
    
58
 
   
59
 
    if (!((t4.is_a (typeof (VariableValueToken))) &&
60
 
          (t4.is_a (typeof (ValueToken))) &&
61
 
          (t4.is_a (typeof (Token))))) {
62
 
      GLib.Test.message ("The VariableValueToken is not the corret type.");
63
 
      GLib.Test.fail ();
64
 
      GLib.assert_not_reached ();
65
 
    }
66
 
  });
67
 
  
68
 
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/Constant", () => {
 
42
    if (!(t2.is_a (typeof (VariableValueToken))) ||
 
43
        !(t2.is_a (typeof (ValueToken))) ||
 
44
        !(t2.is_a (typeof (Token)))) {
 
45
      GLib.Test.message ("The VariableValueToken is not the corret type.");
 
46
      GLib.Test.fail ();
 
47
      GLib.assert_not_reached ();
 
48
    }
 
49
    
 
50
    
 
51
  });
 
52
  
 
53
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/Constant", () => {
69
54
    try {
70
55
      long in_val = 12;
71
56
      
77
62
      
78
63
      root_t.evaluate (ctx);
79
64
      
80
 
      long out_val = root_t.result_value.number;
 
65
      long out_val = root_t.result_value;
81
66
      
82
67
      if (out_val != in_val) {
83
 
        GLib.Test.message ("The values do not match: Expected %li, got %li.\n",
84
 
                           in_val, out_val);
 
68
        GLib.Test.message ("The values do not match");
85
69
        GLib.Test.fail ();
86
70
      }
87
71
    } catch (GLib.Error? e) {
90
74
    }
91
75
  });
92
76
  
93
 
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/ConstantLoop", () => {
 
77
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/ConstantLoop", () => {
94
78
    
95
79
    
96
80
    try {
103
87
        
104
88
        root_t.evaluate (ctx);
105
89
        
106
 
        long out_val = root_t.result_value.number;
 
90
        long out_val = root_t.result_value;
107
91
        
108
92
        if (out_val != i) {
109
93
          GLib.Test.message ("The values do not match");
116
100
    }
117
101
  });
118
102
  
119
 
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/Varuable", () => {
 
103
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/Varuable", () => {
120
104
    try {
121
105
      var ctx = new Context ();
122
106
      ctx.set_value ("a", 0, 0, 13);
123
107
      ctx.set_value ("not a", 0, 0, 37);
124
108
      
125
109
      // Context variable santy check.
126
 
      if ((ctx.get_value ("a").number != 13) || (ctx.get_value ("not a").number != 37)) {
 
110
      if ((ctx.get_value ("a") != 13) || (ctx.get_value ("not a") != 37)) {
127
111
          GLib.Test.message ("The values do not match");
128
112
          
129
113
          GLib.Test.fail ();
132
116
      var v1 = new VariableValueToken ("a", 1);
133
117
      var v2 = new VariableValueToken ("not a", 1);
134
118
      
135
 
      print (v1.result_string + "\n");
136
 
      print (v2.result_string + "\n");
137
119
    } catch (GLib.Error? e) {
138
120
       GLib.Test.message ("An error occured: domain: %s, message: %s", e.domain.to_string (), e.message);
139
121
       GLib.Test.fail ();