|
| 1 | +local evo = require 'evolved' |
| 2 | + |
| 3 | +evo.debug_mode(true) |
| 4 | + |
| 5 | +do |
| 6 | + local e1, e2, e3 = evo.id(3) |
| 7 | + |
| 8 | + do |
| 9 | + assert(evo.lookup('lookup_hello') == nil) |
| 10 | + assert(evo.lookup('lookup_world') == nil) |
| 11 | + |
| 12 | + do |
| 13 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 14 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 15 | + end |
| 16 | + |
| 17 | + do |
| 18 | + local entity_list, entity_count = evo.multi_lookup('lookup_world') |
| 19 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + evo.set(e1, evo.NAME, 'lookup_hello') |
| 24 | + |
| 25 | + do |
| 26 | + assert(evo.lookup('lookup_hello') == e1) |
| 27 | + assert(evo.lookup('lookup_world') == nil) |
| 28 | + |
| 29 | + do |
| 30 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 31 | + assert(entity_list and #entity_list == 1 and entity_count == 1) |
| 32 | + assert(entity_list[1] == e1) |
| 33 | + end |
| 34 | + |
| 35 | + do |
| 36 | + local entity_list, entity_count = evo.multi_lookup('lookup_world') |
| 37 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + evo.set(e2, evo.NAME, 'lookup_hello') |
| 42 | + evo.set(e3, evo.NAME, 'lookup_hello') |
| 43 | + |
| 44 | + do |
| 45 | + assert(evo.lookup('lookup_hello') == e1) |
| 46 | + assert(evo.lookup('lookup_world') == nil) |
| 47 | + |
| 48 | + do |
| 49 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 50 | + assert(entity_list and #entity_list == 3 and entity_count == 3) |
| 51 | + assert(entity_list[1] == e1 and entity_list[2] == e2 and entity_list[3] == e3) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + evo.set(e2, evo.NAME, 'lookup_world') |
| 56 | + |
| 57 | + do |
| 58 | + assert(evo.lookup('lookup_hello') == e1) |
| 59 | + assert(evo.lookup('lookup_world') == e2) |
| 60 | + |
| 61 | + do |
| 62 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 63 | + assert(entity_list and #entity_list == 2 and entity_count == 2) |
| 64 | + assert(entity_list[1] == e1 and entity_list[2] == e3) |
| 65 | + end |
| 66 | + |
| 67 | + do |
| 68 | + local entity_list, entity_count = evo.multi_lookup('lookup_world') |
| 69 | + assert(entity_list and #entity_list == 1 and entity_count == 1) |
| 70 | + assert(entity_list[1] == e2) |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + evo.set(e3, evo.NAME, 'lookup_world') |
| 75 | + |
| 76 | + do |
| 77 | + assert(evo.lookup('lookup_hello') == e1) |
| 78 | + assert(evo.lookup('lookup_world') == e2) |
| 79 | + |
| 80 | + do |
| 81 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 82 | + assert(entity_list and #entity_list == 1 and entity_count == 1) |
| 83 | + assert(entity_list[1] == e1) |
| 84 | + end |
| 85 | + |
| 86 | + do |
| 87 | + local entity_list, entity_count = evo.multi_lookup('lookup_world') |
| 88 | + assert(entity_list and #entity_list == 2 and entity_count == 2) |
| 89 | + assert(entity_list[1] == e2 or entity_list[1] == e3) |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + evo.remove(e1, evo.NAME) |
| 94 | + |
| 95 | + do |
| 96 | + assert(evo.lookup('lookup_hello') == nil) |
| 97 | + assert(evo.lookup('lookup_world') == e2) |
| 98 | + |
| 99 | + do |
| 100 | + local entity_list, entity_count = evo.multi_lookup('lookup_hello') |
| 101 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 102 | + end |
| 103 | + |
| 104 | + do |
| 105 | + local entity_list, entity_count = evo.multi_lookup('lookup_world') |
| 106 | + assert(entity_list and #entity_list == 2 and entity_count == 2) |
| 107 | + assert(entity_list[1] == e2 or entity_list[1] == e3) |
| 108 | + end |
| 109 | + end |
| 110 | +end |
| 111 | + |
| 112 | +do |
| 113 | + local e1, e2, e3 = evo.id(3) |
| 114 | + |
| 115 | + evo.set(e1, evo.NAME, 'lookup_e') |
| 116 | + |
| 117 | + do |
| 118 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 119 | + assert(entity_list and #entity_list == 1 and entity_count == 1) |
| 120 | + assert(entity_list[1] == e1) |
| 121 | + end |
| 122 | + |
| 123 | + evo.set(e2, evo.NAME, 'lookup_e') |
| 124 | + |
| 125 | + do |
| 126 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 127 | + assert(entity_list and #entity_list == 2 and entity_count == 2) |
| 128 | + assert(entity_list[1] == e1 and entity_list[2] == e2) |
| 129 | + end |
| 130 | + |
| 131 | + evo.set(e3, evo.NAME, 'lookup_e') |
| 132 | + |
| 133 | + do |
| 134 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 135 | + assert(entity_list and #entity_list == 3 and entity_count == 3) |
| 136 | + assert(entity_list[1] == e1 and entity_list[2] == e2 and entity_list[3] == e3) |
| 137 | + end |
| 138 | + |
| 139 | + evo.clear(e1, e2, e3) |
| 140 | + |
| 141 | + do |
| 142 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 143 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 144 | + end |
| 145 | + |
| 146 | + evo.set(e3, evo.NAME, 'lookup_e') |
| 147 | + |
| 148 | + do |
| 149 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 150 | + assert(entity_list and #entity_list == 1 and entity_count == 1) |
| 151 | + assert(entity_list[1] == e3) |
| 152 | + end |
| 153 | + |
| 154 | + evo.set(e2, evo.NAME, 'lookup_e') |
| 155 | + |
| 156 | + do |
| 157 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 158 | + assert(entity_list and #entity_list == 2 and entity_count == 2) |
| 159 | + assert(entity_list[1] == e3 and entity_list[2] == e2) |
| 160 | + end |
| 161 | + |
| 162 | + evo.set(e1, evo.NAME, 'lookup_e') |
| 163 | + |
| 164 | + do |
| 165 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 166 | + assert(entity_list and #entity_list == 3 and entity_count == 3) |
| 167 | + assert(entity_list[1] == e3 and entity_list[2] == e2 and entity_list[3] == e1) |
| 168 | + end |
| 169 | + |
| 170 | + evo.destroy(e3, e2, e1) |
| 171 | + |
| 172 | + do |
| 173 | + local entity_list, entity_count = evo.multi_lookup('lookup_e') |
| 174 | + assert(entity_list and #entity_list == 0 and entity_count == 0) |
| 175 | + end |
| 176 | +end |
0 commit comments