|
| 1 | +if (typeof exports === 'object') { |
| 2 | + var assert = require('assert'); |
| 3 | + var alasql = require('..'); |
| 4 | +} |
| 5 | + |
| 6 | +describe('Test 1455 - REPLACE function', function () { |
| 7 | + it('A) REPLACE with string target', function () { |
| 8 | + var res = alasql("SELECT REPLACE('123', '2', '_')"); |
| 9 | + assert.deepEqual(res, [{["REPLACE('123','2','_')"]: '1_3'}]); |
| 10 | + }); |
| 11 | + |
| 12 | + it('B) REPLACE with numeric target (converted to string)', function () { |
| 13 | + var res = alasql("SELECT REPLACE(123, '2', '_')"); |
| 14 | + assert.deepEqual(res, [{["REPLACE(123,'2','_')"]: '1_3'}]); |
| 15 | + }); |
| 16 | + |
| 17 | + it('C) Both string and numeric in same query', function () { |
| 18 | + var res = alasql("SELECT REPLACE('123', '2', '_'), REPLACE(123, '2', '_')"); |
| 19 | + assert.deepEqual(res, [ |
| 20 | + { |
| 21 | + ["REPLACE('123','2','_')"]: '1_3', |
| 22 | + ["REPLACE(123,'2','_')"]: '1_3', |
| 23 | + }, |
| 24 | + ]); |
| 25 | + }); |
| 26 | + |
| 27 | + it('D) REPLACE with numeric search and replacement', function () { |
| 28 | + var res = alasql('SELECT REPLACE(12321, 2, 9)'); |
| 29 | + assert.deepEqual(res, [{['REPLACE(12321,2,9)']: '19391'}]); |
| 30 | + }); |
| 31 | +}); |
0 commit comments