~percona-toolkit-dev/percona-toolkit/pt-table-sync-binlog-format-only-if-not-statement

« back to all changes in this revision

Viewing changes to t/lib/Transformers.t

  • Committer: Daniel Nichter
  • Date: 2012-06-01 15:13:11 UTC
  • mfrom: (171.3.3 json)
  • Revision ID: daniel@percona.com-20120601151311-ro2aopjdb9tnj1wv
Merge advisor-json-output and clean up pt-query-advisor docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl
2
2
 
 
3
# This file is encoded in UTF-8.
 
4
 
3
5
BEGIN {
4
6
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
7
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
12
14
use strict;
13
15
use warnings FATAL => 'all';
14
16
use English qw(-no_match_vars);
15
 
use Test::More tests => 49;
 
17
use Test::More tests => 73;
16
18
 
17
19
use Transformers;
18
20
use PerconaTest;
19
21
 
20
22
Transformers->import( qw(parse_timestamp micro_t shorten secs_to_time
21
23
   time_to_secs percentage_of unix_timestamp make_checksum any_unix_timestamp
22
 
   ts crc32) );
 
24
   ts crc32 encode_json) );
23
25
 
24
26
# #############################################################################
25
27
# micro_t() tests.
189
191
   'any_unix_timestamp MySQL expression that looks like another type'
190
192
);
191
193
 
 
194
{
 
195
   # Tests borrowed from http://api.metacpan.org/source/MAKAMAKA/JSON-2.53/t/08_pc_base.t
 
196
   my $obj  = {};
 
197
   my $js  = encode_json($obj);
 
198
   is($js,'{}', '{}');
 
199
   
 
200
   $obj = [];
 
201
   $js  = encode_json($obj);
 
202
   is($js,'[]', '[]');
 
203
   
 
204
   $obj = {"foo" => "bar"};
 
205
   $js  = encode_json($obj);
 
206
   is($js,'{"foo":"bar"}', '{"foo":"bar"}');
 
207
   
 
208
   $js  = encode_json({"foo" => ""});
 
209
   is($js,'{"foo":""}', '{"foo":""}');
 
210
   
 
211
   $js  = encode_json({"foo" => " "});
 
212
   is($js,'{"foo":" "}' ,'{"foo":" "}');
 
213
   
 
214
   $js  = encode_json({"foo" => "0"});
 
215
   is($js,'{"foo":"0"}',q|{"foo":"0"} - autoencode (default)|);
 
216
   
 
217
   $js  = encode_json({"foo" => "0 0"});
 
218
   is($js,'{"foo":"0 0"}','{"foo":"0 0"}');
 
219
   
 
220
   $js  = encode_json([1,2,3]);
 
221
   is($js,'[1,2,3]');
 
222
   
 
223
   $js  = encode_json({"foo"=>{"bar"=>"hoge"}});
 
224
   is($js,q|{"foo":{"bar":"hoge"}}|);
 
225
   
 
226
   $obj = [{"foo"=>[1,2,3]},-0.12,{"a"=>"b"}];
 
227
   $js  = encode_json($obj);
 
228
   is($js,q|[{"foo":[1,2,3]},-0.12,{"a":"b"}]|);
 
229
      
 
230
   $obj = ["\x01"];
 
231
   is(encode_json($obj),'["\\u0001"]');
 
232
   
 
233
   $obj = ["\e"];
 
234
   is(encode_json($obj),'["\\u001b"]');
 
235
 
 
236
   {
 
237
      # http://api.metacpan.org/source/MAKAMAKA/JSON-2.53/t/07_pc_esc.t
 
238
      use utf8;
 
239
   
 
240
      $obj = {test => qq|abc"def|};
 
241
      my $str = encode_json($obj);
 
242
      is($str,q|{"test":"abc\"def"}|);
 
243
      
 
244
      $obj = {qq|te"st| => qq|abc"def|};
 
245
      $str = encode_json($obj);
 
246
      is($str,q|{"te\"st":"abc\"def"}|);
 
247
      
 
248
      $obj = {test => q|abc\def|};
 
249
      $str = encode_json($obj);
 
250
      is($str,q|{"test":"abc\\\\def"}|);
 
251
      
 
252
      $obj = {test => "abc\bdef"};
 
253
      $str = encode_json($obj);
 
254
      is($str,q|{"test":"abc\bdef"}|);
 
255
      
 
256
      $obj = {test => "abc\fdef"};
 
257
      $str = encode_json($obj);
 
258
      is($str,q|{"test":"abc\fdef"}|);
 
259
      
 
260
      $obj = {test => "abc\ndef"};
 
261
      $str = encode_json($obj);
 
262
      is($str,q|{"test":"abc\ndef"}|);
 
263
      
 
264
      $obj = {test => "abc\rdef"};
 
265
      $str = encode_json($obj);
 
266
      is($str,q|{"test":"abc\rdef"}|);
 
267
      
 
268
      $obj = {test => "abc-def"};
 
269
      $str = encode_json($obj);
 
270
      is($str,q|{"test":"abc-def"}|);
 
271
      
 
272
      $obj = {test => "abc(def"};
 
273
      $str = encode_json($obj);
 
274
      is($str,q|{"test":"abc(def"}|);
 
275
      
 
276
      $obj = {test => "abc\\def"};
 
277
      $str = encode_json($obj);
 
278
      is($str,q|{"test":"abc\\\\def"}|);
 
279
      
 
280
      
 
281
      $obj = {test => "あいうえお"};
 
282
      $str = encode_json($obj);
 
283
      my $expect = q|{"test":"あいうえお"}|;
 
284
      utf8::encode($expect);
 
285
      is($str,$expect);
 
286
      
 
287
      $obj = {"あいうえお" => "かきくけこ"};
 
288
      $str = encode_json($obj);
 
289
      $expect = q|{"あいうえお":"かきくけこ"}|;
 
290
      utf8::encode($expect);
 
291
      is($str,$expect);
 
292
   }
 
293
}
 
294
 
192
295
 
193
296
# #############################################################################
194
297
# Done.