-
-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathtest_output_flex_types.lua
More file actions
172 lines (162 loc) · 5.57 KB
/
Copy pathtest_output_flex_types.lua
File metadata and controls
172 lines (162 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
local test_table = osm2pgsql.define_node_table("nodes", {
{ column = 'ttext', type = 'text' },
{ column = 'tbool', type = 'boolean' },
{ column = 'tint2', type = 'int2' },
{ column = 'tint4', type = 'int4' },
{ column = 'tint8', type = 'int8' },
{ column = 'treal', type = 'real' },
{ column = 'tdubl', type = 'double' },
{ column = 'thstr', type = 'hstore' },
{ column = 'tjson', type = 'jsonb' },
{ column = 'tdirn', type = 'direction' },
{ column = 'tsqlt', sql_type = 'varchar' },
})
function osm2pgsql.process_node(object)
local test_type = object.tags.type
if test_type == 'nil' then
test_table:insert({})
return
end
if test_type == 'boolean' then
local row = { tbool = true, tint2 = true, tint4 = true,
tint8 = true, tjson = true, tdirn = true }
test_table:insert(row)
row = { tbool = false, tint2 = false, tint4 = false,
tint8 = false, tjson = false, tdirn = false }
test_table:insert(row)
return
end
if test_type == 'boolean-fail' then
test_table:insert{ [object.tags.column] = true }
return
end
if test_type == 'number' then
local numbers = { -2^31 - 1, -2^31, -2^31 + 1,
-2^15 - 1, -2^15, -2^15 + 1,
-2, -1, -0.5, 0, 0.5, 1, 2,
2^15 - 1, 2^15, 2^15 + 1,
2^31 - 1, 2^31, 2^31 + 1 }
for _, n in ipairs(numbers) do
test_table:insert{
ttext = n,
tbool = n,
tint2 = n,
tint4 = n,
tint8 = n,
treal = n,
tdubl = n,
tjson = n,
tdirn = n,
tsqlt = n,
}
end
return
end
if test_type == 'number-fail' then
test_table:insert{ [object.tags.column] = 1 }
return
end
if test_type == 'string-bool' then
test_table:insert{ tbool = '1', ttext = 'istrue' };
test_table:insert{ tbool = 'yes', ttext = 'istrue' };
test_table:insert{ tbool = 'true', ttext = 'istrue' };
test_table:insert{ tbool = '0', ttext = 'isfalse' };
test_table:insert{ tbool = 'no', ttext = 'isfalse' };
test_table:insert{ tbool = 'false', ttext = 'isfalse' };
test_table:insert{ tbool = '', ttext = 'isnull' };
test_table:insert{ tbool = '2', ttext = 'isnull' };
test_table:insert{ tbool = 'YES', ttext = 'isnull' };
return
end
if test_type == 'string-direction' then
test_table:insert{ tdirn = '1', tint2 = 1 };
test_table:insert{ tdirn = 'yes', tint2 = 1 };
test_table:insert{ tdirn = '0', tint2 = 0 };
test_table:insert{ tdirn = 'no', tint2 = 0 };
test_table:insert{ tdirn = '-1', tint2 = -1 };
test_table:insert{ tdirn = '2', tint2 = nil };
test_table:insert{ tdirn = '-2', tint2 = nil };
test_table:insert{ tdirn = '', tint2 = nil };
test_table:insert{ tdirn = 'FOO', tint2 = nil };
return
end
if test_type == 'string-with-number' then
local numbers = { -2^31 - 1, -2^31, -2^31 + 1,
-2^15 - 1, -2^15, -2^15 + 1,
-2, -1, 0, 1, 2,
2^15 - 1, 2^15, 2^15 + 1,
2^31 - 1, 2^31, 2^31 + 1 }
for _, n in ipairs(numbers) do
test_table:insert{
ttext = string.format('%d', n),
tint2 = string.format('%d', n),
tint4 = string.format('%d', n),
tint8 = string.format('%d', n),
treal = string.format('%d', n),
tdubl = string.format('%d', n),
tsqlt = string.format('%d', n),
}
end
test_table:insert{
ttext = ' 42',
tint2 = ' 42',
tint4 = ' 42',
tint8 = ' 42',
treal = ' 42',
tdubl = ' 42',
tsqlt = ' 42',
}
return
end
if test_type == 'string-with-invalid-number' then
local not_numbers = { '', 'abc', '0a', '0xa', '--1', '1foo', '1.2' }
for _, n in ipairs(not_numbers) do
test_table:insert{
ttext = n,
tint2 = n,
tint4 = n,
tint8 = n,
treal = n,
tdubl = n,
}
end
return
end
if test_type == 'function-fail' then
test_table:insert{ [object.tags.column] = table.insert }
return
end
if test_type == 'table' then
local t = { a = 'b', c = 'd' }
test_table:insert{ thstr = {}, tjson = {} }
test_table:insert{ thstr = t, tjson = t }
return
end
if test_type == 'table-hstore-fail' then
test_table:insert{ thstr = { num = 1, bln = true } }
return
end
if test_type == 'table-fail' then
test_table:insert{ [object.tags.column] = {} }
return
end
if test_type == 'json' then
test_table:insert{ tjson = {
astring = '123',
aninteger = 124,
anumber = 12.5,
atrue = true,
afalse = false,
anull = nil,
atable = { a = 'nested', tab = 'le' },
anarray = { 4, 3, 7 }
}}
return
end
if test_type == 'json-loop' then
local atable = { a = 'b' }
atable.c = atable
test_table:insert{ tjson = atable }
return
end
end