|
| 1 | +-- --------------------------------------------------------------------------- |
| 2 | +-- |
| 3 | +-- Osm2pgsql Themepark |
| 4 | +-- |
| 5 | +-- A framework for pluggable osm2pgsql config files. |
| 6 | +-- |
| 7 | +-- --------------------------------------------------------------------------- |
| 8 | +-- |
| 9 | +-- tests/test-utils.lua |
| 10 | +-- |
| 11 | +-- --------------------------------------------------------------------------- |
| 12 | +-- |
| 13 | +-- Copyright 2024 Jochen Topf <[email protected]> |
| 14 | +-- |
| 15 | +-- Licensed under the Apache License, Version 2.0 (the "License"); |
| 16 | +-- you may not use this file except in compliance with the License. |
| 17 | +-- You may obtain a copy of the License at |
| 18 | +-- |
| 19 | +-- https://www.apache.org/licenses/LICENSE-2.0 |
| 20 | +-- |
| 21 | +-- Unless required by applicable law or agreed to in writing, software |
| 22 | +-- distributed under the License is distributed on an "AS IS" BASIS, |
| 23 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | +-- See the License for the specific language governing permissions and |
| 25 | +-- limitations under the License. |
| 26 | +-- |
| 27 | +-- --------------------------------------------------------------------------- |
| 28 | + |
| 29 | +require 'busted.runner'() |
| 30 | + |
| 31 | +local utils = require 'themepark/utils' |
| 32 | + |
| 33 | +describe('test build_select_query', function() |
| 34 | + |
| 35 | + it('creates simple selects', function() |
| 36 | + assert.is_equal([[SELECT first,second FROM "sometable"]], |
| 37 | + utils.build_select_query({'first', 'second'}, 'sometable')) |
| 38 | + end) |
| 39 | + |
| 40 | + it('handles tables which schemas', function() |
| 41 | + assert.is_equal([[SELECT first,second FROM "inschema"."sometable"]], |
| 42 | + utils.build_select_query({'first', 'second'}, 'inschema.sometable')) |
| 43 | + end) |
| 44 | + |
| 45 | + it('handles WHERE condition', function() |
| 46 | + assert.is_equal([[SELECT * FROM "sometable" WHERE a=b]], |
| 47 | + utils.build_select_query({'*'}, 'sometable', {'a=b'})) |
| 48 | + |
| 49 | + assert.is_equal([[SELECT * FROM "sometable" WHERE a=b AND c=1]], |
| 50 | + utils.build_select_query({'*'}, 'sometable', {'a=b', 'c=1'})) |
| 51 | + |
| 52 | + assert.is_equal([[SELECT * FROM "sometable"]], |
| 53 | + utils.build_select_query({'*'}, 'sometable', {})) |
| 54 | + end) |
| 55 | + |
| 56 | + it('handles ORDER BY sorting', function() |
| 57 | + assert.is_equal([[SELECT a,b FROM "sometable" ORDER BY "b"]], |
| 58 | + utils.build_select_query({'a', 'b'}, 'sometable', {}, 'b')) |
| 59 | + |
| 60 | + assert.is_equal([[SELECT a,b FROM "sometable" ORDER BY "b" DESC]], |
| 61 | + utils.build_select_query({'a', 'b'}, 'sometable', {}, 'b', 'DESC')) |
| 62 | + end) |
| 63 | + |
| 64 | +end) |
| 65 | + |
| 66 | +describe('test find_name_in_array', function() |
| 67 | + |
| 68 | + local a = { |
| 69 | + { name = 'some' }, |
| 70 | + { name = 'named' }, |
| 71 | + { name = 'things' }, |
| 72 | + } |
| 73 | + |
| 74 | + it('finds name in array', function() |
| 75 | + assert.is_same({ name = 'named' }, utils.find_name_in_array(a, 'named')) |
| 76 | + end) |
| 77 | + |
| 78 | + it('does not find name not in array', function() |
| 79 | + assert.is_nil(utils.find_name_in_array(a, 'unnamed')) |
| 80 | + end) |
| 81 | + |
| 82 | +end) |
| 83 | + |
| 84 | +-- --------------------------------------------------------------------------- |
0 commit comments