/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: 2021-09-15 17:10:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210915171052-yhdw16iyipyj5a5l
* Fixed Fastnumber's normalisation problem with the getters/setters

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/Exprossion/Token/Value/sanity", () => {
 
5
  GLib.Test.add_func ("/VQDR/Expression/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
 
    
32
23
    Type t1 = v1.get_type ();
33
 
    if (!(t1.is_a (typeof (ConstantValueToken))) ||
34
 
        !(t1.is_a (typeof (ValueToken))) ||
35
 
        !(t1.is_a (typeof (Token)))) {
 
24
    if (!(t1.is_a (typeof (ConstantValueToken)) &&
 
25
          t1.is_a (typeof (ValueToken)) &&
 
26
          t1.is_a (typeof (Token)))) {
36
27
      GLib.Test.message ("The ConstastValueToken is not the corret type.");
37
28
      GLib.Test.fail ();
38
29
      GLib.assert_not_reached ();
39
30
    }
40
31
    
41
32
   Type t2 = v2.get_type ();
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", () => {
 
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", () => {
54
69
    try {
55
70
      long in_val = 12;
56
71
      
62
77
      
63
78
      root_t.evaluate (ctx);
64
79
      
65
 
      long out_val = root_t.result_value;
 
80
      long out_val = root_t.result_value.number;
66
81
      
67
82
      if (out_val != in_val) {
68
 
        GLib.Test.message ("The values do not match");
 
83
        GLib.Test.message ("The values do not match: Expected %li, got %li.\n",
 
84
                           in_val, out_val);
69
85
        GLib.Test.fail ();
70
86
      }
71
87
    } catch (GLib.Error? e) {
74
90
    }
75
91
  });
76
92
  
77
 
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/ConstantLoop", () => {
 
93
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/ConstantLoop", () => {
78
94
    
79
95
    
80
96
    try {
87
103
        
88
104
        root_t.evaluate (ctx);
89
105
        
90
 
        long out_val = root_t.result_value;
 
106
        long out_val = root_t.result_value.number;
91
107
        
92
108
        if (out_val != i) {
93
109
          GLib.Test.message ("The values do not match");
100
116
    }
101
117
  });
102
118
  
103
 
  GLib.Test.add_func ("/VQDR/Exprossion/Token/Value/Varuable", () => {
 
119
  GLib.Test.add_func ("/VQDR/Expression/Token/Value/Varuable", () => {
104
120
    try {
105
121
      var ctx = new Context ();
106
122
      ctx.set_value ("a", 0, 0, 13);