File: json-tokenize.t

package info (click to toggle)
libjson-parse-perl 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 572 kB
  • sloc: ansic: 3,614; perl: 475; makefile: 12
file content (28 lines) | stat: -rw-r--r-- 948 bytes parent folder | download | duplicates (2)
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
# Test for JSON::Tokenize

use FindBin '$Bin';
use lib "$Bin";
use JPT;
use JSON::Tokenize ':all';

my $input = '{"tuttie":["fruity", true, 100]}';
ok (valid_json ($input));
my $token = tokenize_json ($input);
is (tokenize_type ($token), 'object');
my $child = tokenize_child ($token);
is (tokenize_type ($child), "string");
is (tokenize_text ($input, $child), '"tuttie"');
my $next = tokenize_next ($child);
is (tokenize_type ($next), "colon");
is (tokenize_start ($next), 9, "start at 9");
is (tokenize_text ($input, $next), ":");
my $nnext = tokenize_next ($next);
is (tokenize_text ($input, $nnext), '["fruity", true, 100]');
use utf8;
my $utf8input = '{"くそ":"くらえ"}';
ok (valid_json ($utf8input), "valid input");
my $tokenutf8 = tokenize_json ($utf8input);
my $childutf8 = tokenize_child ($tokenutf8);
is (tokenize_type ($childutf8), "string", "is a string");
is (tokenize_text ($utf8input, $childutf8), '"くそ"');
done_testing ();