| 1 |
root |
1.1 |
use common::sense; |
| 2 |
|
|
use Test::More; |
| 3 |
root |
1.2 |
use Types::Serialiser (); |
| 4 |
root |
1.1 |
|
| 5 |
|
|
# Modules that need only the mandatory distribution dependencies. |
| 6 |
|
|
# Optional components such as Worker::IMAP have their own tests. |
| 7 |
|
|
for my $module (qw( |
| 8 |
|
|
AnyEvent::MCP |
| 9 |
|
|
AnyEvent::MCP::Client |
| 10 |
|
|
AnyEvent::MCP::Client::HTTP |
| 11 |
|
|
AnyEvent::MCP::Client::JSONL |
| 12 |
|
|
AnyEvent::MCP::Client::Request |
| 13 |
|
|
AnyEvent::MCP::Config |
| 14 |
|
|
AnyEvent::MCP::Extension |
| 15 |
|
|
AnyEvent::MCP::Helper |
| 16 |
|
|
AnyEvent::MCP::Permissions::Ask |
| 17 |
|
|
AnyEvent::MCP::Server |
| 18 |
|
|
AnyEvent::MCP::Server::Connect |
| 19 |
|
|
AnyEvent::MCP::Server::HTTP |
| 20 |
|
|
AnyEvent::MCP::Server::JSONL |
| 21 |
|
|
AnyEvent::MCP::Server::Permissions |
| 22 |
|
|
AnyEvent::MCP::Server::Request |
| 23 |
|
|
AnyEvent::MCP::Server::Simple |
| 24 |
|
|
AnyEvent::MCP::Server::Toolset |
| 25 |
|
|
AnyEvent::MCP::Workdirs |
| 26 |
|
|
)) { |
| 27 |
|
|
require_ok $module; |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
my $text = "\x{e4}\x{1f642}"; |
| 31 |
|
|
my $bytes = AnyEvent::MCP::utf8enc $text; |
| 32 |
|
|
is $bytes, "\xc3\xa4\xf0\x9f\x99\x82", "encode UTF-8"; |
| 33 |
|
|
is AnyEvent::MCP::utf8dec ($bytes), $text, "decode UTF-8"; |
| 34 |
|
|
is $text, "\x{e4}\x{1f642}", "source is unchanged"; |
| 35 |
|
|
eval { AnyEvent::MCP::utf8dec ("\xff") }; |
| 36 |
|
|
ok $@, "reject invalid UTF-8"; |
| 37 |
|
|
|
| 38 |
root |
1.2 |
my $json = AnyEvent::MCP::json (); |
| 39 |
|
|
is ref $json, AnyEvent::MCP::json_class (), "selected JSON backend"; |
| 40 |
|
|
is $json->encode ("foo"), '"foo"', "encode top-level scalar"; |
| 41 |
|
|
is $json->decode ('"foo"'), "foo", "decode top-level scalar"; |
| 42 |
|
|
is $json->encode ([\1, \0, Types::Serialiser::true, Types::Serialiser::false]), |
| 43 |
|
|
'[true,false,true,false]', "both representations encode as booleans"; |
| 44 |
|
|
my $booleans = $json->decode ("[true,false]"); |
| 45 |
|
|
ok Types::Serialiser::is_bool ($_) for @$booleans; |
| 46 |
|
|
ok $booleans->[0] && !$booleans->[1], "decoded booleans have Perl truth values"; |
| 47 |
|
|
is AnyEvent::MCP::encode_json ($text), qq("$bytes"), "encode UTF-8 JSON bytes"; |
| 48 |
|
|
is AnyEvent::MCP::decode_json (qq("$bytes")), $text, "decode UTF-8 JSON bytes"; |
| 49 |
|
|
$json->allow_nonref (0); |
| 50 |
|
|
ok AnyEvent::MCP::json ()->get_allow_nonref, "new coders have independent settings"; |
| 51 |
|
|
|
| 52 |
root |
1.1 |
done_testing; |