|
| 1 | +if (typeof exports === 'object') { |
| 2 | + var assert = require('assert'); |
| 3 | + var alasql = require('..'); |
| 4 | +} |
| 5 | + |
| 6 | +describe('Test 735: BETWEEN in CASE statement', function () { |
| 7 | + it('1. CASE WHEN with > and < operators should work', function (done) { |
| 8 | + var cities = [ |
| 9 | + {City: 'Moscow', Population: 1}, |
| 10 | + {City: 'London', Population: 10}, |
| 11 | + {City: 'Paris', Population: 100}, |
| 12 | + ]; |
| 13 | + |
| 14 | + var res = alasql( |
| 15 | + 'SELECT City, CASE WHEN Population > 1 AND Population < 100 THEN "yes" ELSE "no" END AS isBetween1and100 FROM ?', |
| 16 | + [cities] |
| 17 | + ); |
| 18 | + |
| 19 | + assert.deepEqual(res, [ |
| 20 | + {City: 'Moscow', isBetween1and100: 'no'}, |
| 21 | + {City: 'London', isBetween1and100: 'yes'}, |
| 22 | + {City: 'Paris', isBetween1and100: 'no'}, |
| 23 | + ]); |
| 24 | + done(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('2. CASE WHEN with BETWEEN operator should work', function (done) { |
| 28 | + var cities = [ |
| 29 | + {City: 'Moscow', Population: 1}, |
| 30 | + {City: 'London', Population: 10}, |
| 31 | + {City: 'Paris', Population: 100}, |
| 32 | + ]; |
| 33 | + |
| 34 | + var res = alasql( |
| 35 | + 'SELECT City, CASE WHEN Population BETWEEN 1 AND 100 THEN "yes" ELSE "no" END AS isBetween1and100 FROM ?', |
| 36 | + [cities] |
| 37 | + ); |
| 38 | + |
| 39 | + assert.deepEqual(res, [ |
| 40 | + {City: 'Moscow', isBetween1and100: 'yes'}, |
| 41 | + {City: 'London', isBetween1and100: 'yes'}, |
| 42 | + {City: 'Paris', isBetween1and100: 'yes'}, |
| 43 | + ]); |
| 44 | + done(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('3. CASE WHEN with BETWEEN operator (exclusive) should work', function (done) { |
| 48 | + var cities = [ |
| 49 | + {City: 'Moscow', Population: 1}, |
| 50 | + {City: 'London', Population: 10}, |
| 51 | + {City: 'Paris', Population: 100}, |
| 52 | + ]; |
| 53 | + |
| 54 | + var res = alasql( |
| 55 | + 'SELECT City, CASE WHEN Population BETWEEN 2 AND 99 THEN "yes" ELSE "no" END AS isBetween2and99 FROM ?', |
| 56 | + [cities] |
| 57 | + ); |
| 58 | + |
| 59 | + assert.deepEqual(res, [ |
| 60 | + {City: 'Moscow', isBetween2and99: 'no'}, |
| 61 | + {City: 'London', isBetween2and99: 'yes'}, |
| 62 | + {City: 'Paris', isBetween2and99: 'no'}, |
| 63 | + ]); |
| 64 | + done(); |
| 65 | + }); |
| 66 | +}); |
0 commit comments