### ----------------------------------------------------
### -- CBOR::Simple
### -- Licenses: Artistic-2.0
### -- Authors: Geoffrey Broadwell
### -- File: t/03-diagnostic.rakutest
### ----------------------------------------------------
use Test;
use lib $*PROGRAM.sibling('lib');
use CodecMatches;

use CBOR::Simple;


plan 75;


### Below adapted from https://tools.ietf.org/html/rfc8949#appendix-A

# STANDARD INTEGERS

diagnostic-is   '0', '00';
diagnostic-is   '1', '01';
diagnostic-is  '10', '0a';
diagnostic-is  '23', '17';
diagnostic-is  '24', '1818';
diagnostic-is  '25', '1819';
diagnostic-is '100', '1864';

diagnostic-is                  '1000', '1903e8';
diagnostic-is               '1000000', '1a000f4240';
diagnostic-is         '1000000000000', '1b000000e8d4a51000';
diagnostic-is  '18446744073709551615', '1bffffffffffffffff';
diagnostic-is '-18446744073709551616', '3bffffffffffffffff';

diagnostic-is    '-1', '20';
diagnostic-is   '-10', '29';
diagnostic-is  '-100', '3863';
diagnostic-is '-1000', '3903e7';


# FLOATS (CBOR::Simple adds float encoding indicators as per RFC 8949 section 8.1)

diagnostic-is      '0.0_1', 'f90000';
diagnostic-is     '-0.0_1', 'f98000';
diagnostic-is      '1.0_1', 'f93c00';
diagnostic-is      '1.5_1', 'f93e00';
diagnostic-is  '65504.0_1', 'f97bff';

diagnostic-is      '1.1_3', 'fb3ff199999999999a';
diagnostic-is '100000.0_2', 'fa47c35000';
diagnostic-is '3.4028234663852886e+38_2', 'fa7f7fffff';
diagnostic-is '1.0e+300_3', 'fb7e37e43c8800759c';
diagnostic-is     '-4.0_1', 'f9c400';
diagnostic-is     '-4.1_3', 'fbc010666666666666';

diagnostic-is '5.960464477539063e-8_1', 'f90001';
# XXXX: Appendix A doesn't use scientific notation for this one for some reason
# diagnostic-is '0.00006103515625_1',     'f90400';
diagnostic-is '6.103515625e-5_1',       'f90400';

diagnostic-is  'Infinity_1', 'f97c00';
diagnostic-is       'NaN_1', 'f97e00';
diagnostic-is '-Infinity_1', 'f9fc00';

diagnostic-is  'Infinity_2', 'fa7f800000';
diagnostic-is       'NaN_2', 'fa7fc00000';
diagnostic-is '-Infinity_2', 'faff800000';

diagnostic-is  'Infinity_3', 'fb7ff0000000000000';
diagnostic-is       'NaN_3', 'fb7ff8000000000000';
diagnostic-is '-Infinity_3', 'fbfff0000000000000';


# SIMPLE VALUES

diagnostic-is 'false',       'f4';
diagnostic-is 'true',        'f5';
diagnostic-is 'null',        'f6';
diagnostic-is 'undefined',   'f7';
diagnostic-is 'simple(16)',  'f0';
diagnostic-is 'simple(255)', 'f8ff';


# TAGGED VALUES

# XXXX: BigInts are decoded as simple tagged entities
# diagnostic-is  '18446744073709551616', 'c249010000000000000000';
# diagnostic-is '-18446744073709551617', 'c349010000000000000000';

diagnostic-is '0("2013-03-21T20:04:00Z")', 'c074323031332d30332d32315432303a30343a30305a';
diagnostic-is '1(1363896240)',             'c11a514b67b0';
diagnostic-is '1(1363896240.5_3)',         'c1fb41d452d9ec200000';

diagnostic-is "23(h'01020304')",   'd74401020304';
diagnostic-is "24(h'6449455446')", 'd818456449455446';
diagnostic-is '32("http://www.example.com")',
              'd82076687474703a2f2f7777772e6578616d706c652e636f6d';


# BINARY BUFFERS

diagnostic-is "h''",         '40';
diagnostic-is "h'01020304'", '4401020304';


# STRINGS

diagnostic-is '""',          '60';
diagnostic-is '"a"',         '6161';
diagnostic-is '"IETF"',      '6449455446';

# XXXX: Requires JSON-style string escaping
# diagnostic-is '"\"\\"',         '62225c';
# diagnostic-is '"\u00fc"',       '62c3bc';
# diagnostic-is '"\u6c34"',       '63e6b0b4';
# diagnostic-is '"\ud800\udd51"', '64f0908591';


# ARRAYS

diagnostic-is '[]',                  '80';
diagnostic-is '[1, 2, 3]',           '83010203';
diagnostic-is '[1, [2, 3], [4, 5]]', '8301820203820405';
diagnostic-is '[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]', '98190102030405060708090a0b0c0d0e0f101112131415161718181819';


# MAPS

diagnostic-is '{}',                    'a0';
diagnostic-is '{1: 2, 3: 4}',          'a201020304';
diagnostic-is '{"a": 1, "b": [2, 3]}', 'a26161016162820203';
diagnostic-is '["a", {"b": "c"}]',     '826161a161626163';
diagnostic-is '{"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"}',
              'a56161614161626142616361436164614461656145';


# INDEFINITE LENGTH VALUES

diagnostic-is "(_ h'0102', h'030405')",     '5f42010243030405ff';
diagnostic-is '(_ "strea", "ming")',        '7f657374726561646d696e67ff';
diagnostic-is '[_ ]',                       '9fff';
diagnostic-is '[_ 1, [2, 3], [_ 4, 5]]',    '9f018202039f0405ffff';
diagnostic-is '[_ 1, [2, 3], [4, 5]]',      '9f01820203820405ff';
diagnostic-is '[1, [2, 3], [_ 4, 5]]',      '83018202039f0405ff';
diagnostic-is '[1, [_ 2, 3], [4, 5]]',      '83019f0203ff820405';
diagnostic-is '[_ 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]', '9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff';
diagnostic-is '{_ "a": 1, "b": [_ 2, 3]}',  'bf61610161629f0203ffff';
diagnostic-is '["a", {_ "b": "c"}]',        '826161bf61626163ff';
diagnostic-is '{_ "Fun": true, "Amt": -2}', 'bf6346756ef563416d7421ff';


