Skip to content

Commit

Permalink
Hopefully fixed the windows failure
Browse files Browse the repository at this point in the history
Also modernize test files
  • Loading branch information
lizmat committed Dec 29, 2024
1 parent cd2671e commit 0153ab0
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 54 deletions.
2 changes: 1 addition & 1 deletion doc/JSON-Unmarshal.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ argument.
Copyright 2015 - 2017 Tadeusz Sośnierz
Copyright 2022, 2024 Raku Community
Copyright 2022 - 2024 Raku Community
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
Expand Down
2 changes: 1 addition & 1 deletion t/010-basic.rakutest
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Test;

use JSON::Unmarshal;

plan 25;
Expand Down Expand Up @@ -114,5 +115,4 @@ subtest "unmarshall named arguments", {
"it dies with unsupported named arguments and :die (or :throw)";
}

done-testing;
# vim: expandtab shiftwidth=4 ft=raku
5 changes: 2 additions & 3 deletions t/020-any.rakutest
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!raku
use v6;
use Test;

use JSON::Unmarshal;

plan 16;
Expand All @@ -23,5 +22,5 @@ for @tests -> $test {
is $ret.any-attr, $test<value>, "attribute has the correct value";
isa-ok $ret.any-attr, $test<type>, "and it is the right type";
}
done-testing;

# vim: expandtab shiftwidth=4 ft=raku
6 changes: 1 addition & 5 deletions t/030-null.rakutest
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env raku

use v6.*;

use Test;

use JSON::Unmarshal;

plan 4;
Expand All @@ -19,5 +16,4 @@ for @tests -> $test {
lives-ok { $obj = unmarshal($json, $test<class> ) }, $test<description>;
}

done-testing;
# vim: expandtab shiftwidth=4 ft=raku
7 changes: 1 addition & 6 deletions t/040-types.rakutest
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!raku

use v6;
use Test;

use JSON::Unmarshal;
Expand Down Expand Up @@ -166,7 +163,7 @@ my @tests =
],
;

plan 2+@tests;
plan 2 + @tests;

for @tests -> @test {
my @pos = @test.grep( * !~~ Pair );
Expand All @@ -189,6 +186,4 @@ throws-like
:message(q«Cannot unmarshal "13" into type 'Int' for attribute $!attr of 'NastyCoercive'»),
"unmarshalling into a wrong type throws";

done-testing;

# vim: expandtab shiftwidth=4 ft=raku
7 changes: 0 additions & 7 deletions t/050-json-name.rakutest
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!raku

use v6;
use lib 'lib';

use Test;

use JSON::Unmarshal;
Expand All @@ -19,8 +14,6 @@ my $json = '{ "666.evil.name" : "some value we want" }';
my $obj;
lives-ok { $obj = unmarshal($json, TestClass) }, "Unmarshal object with a json-name attribute";


is $obj.nice-name,"some value we want", "and we got the key back with the json name";

done-testing;
# vim: expandtab shiftwidth=4 ft=raku
3 changes: 3 additions & 0 deletions t/060-lists_hashes.rakutest
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Test;

use JSON::Unmarshal;

plan 18;
Expand Down Expand Up @@ -66,3 +67,5 @@ isa-ok %dogs{'also a good dog'}, Dog;
is %dogs{'also a good dog'}.name, "Panda";
is %dogs{'also a good dog'}.race, "wolfish";
is %dogs{'also a good dog'}.age, 13;

# vim: expandtab shiftwidth=4 ft=raku
7 changes: 2 additions & 5 deletions t/070-parameterised.rakutest
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!raku

use Test;

use JSON::Unmarshal;

plan 2;

class C {
has Str %.bla{subset :: of Str where any("ble", "blob")}
};
}

my $res;

Expand All @@ -17,6 +16,4 @@ lives-ok {

is $res.bla<ble> , 'bli', "and the result is what is expected";

done-testing;

# vim: expandtab shiftwidth=4 ft=raku
29 changes: 15 additions & 14 deletions t/080-trait.rakutest
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!raku
use v6;
use Test;

use JSON::Unmarshal;

subtest {
plan 4;

subtest "unmarshalled-by trait with Code" => {
class VersionClassCode {
has Version $.version is unmarshalled-by(-> $v { Version.new($v) });
}
Expand All @@ -16,8 +17,9 @@ subtest {
isa-ok $obj.version, Version, "the attribute is the right kind of thing";
ok $obj.version.defined, "and it's defined";
is $obj.version, Version.new("0.0.1"), "and has the right value";
}, "unmarshalled-by trait with Code";
subtest {
}

subtest "unmarshalled-by trait with Method name" => {
class VersionClassMethod {
has Version $.version is unmarshalled-by('new');
}
Expand All @@ -30,8 +32,9 @@ subtest {
isa-ok $obj.version, Version, "the attribute is the right kind of thing";
ok $obj.version.defined, "and it's defined";
is $obj.version, Version.new("0.0.1"), "and has the right value";
}, "unmarshalled-by trait with Method name";
subtest {
}

subtest "unmarshalled-by trait with inheritance" => {
class Inner {
has Str $.name is required;
}
Expand All @@ -50,8 +53,9 @@ subtest {
isa-ok $obj.inner, Inner, "the attribute is the right kind of thing";
ok $obj.inner.defined, "and it's defined";
is $obj.inner.name, "name", "and has the right value";
}, "unmarshalled-by trait with inheritance";
subtest {
}

subtest "unmarshalled-by on a positional attribute" => {
class CustomArrayAttribute {
class Inner {
has Str $.name is required;
Expand All @@ -70,11 +74,8 @@ subtest {
$obj = unmarshal $json, CustomArrayAttribute;
}, "unmarshal with custom marshaller on positional attribute";

ok all($obj.inners) ~~ CustomArrayAttribute::Inner, "and all the objects in the array are correct";
ok $obj.inners.are(CustomArrayAttribute::Inner), "and all the objects in the array are correct";
is-deeply $obj.inners.map( *.name), <one two three>, "and they have their names set correctly";
}


}, "unmarshalled-by on a positional attribute";

done-testing;
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 4 additions & 0 deletions t/090-unused-keys.rakutest
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Test;

use JSON::Unmarshal;

plan 2;
Expand Down Expand Up @@ -27,8 +28,11 @@ my $json = '{"count": 42, "check": true, "description": "about something", "name
flunk $msg;
}
}

throws-like
{ my Foo $foo = unmarshal $json, Foo, :throw; },
X::UnusedKeys,
:unused-keys(<description name>.Set),
"an exception is thrown for unsued JSON keys with :throw (or :die)";

# vim: expandtab shiftwidth=4 ft=raku
17 changes: 9 additions & 8 deletions t/100-issue-7.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use JSON::Unmarshal;

plan 4;

subtest {
subtest 'where subset with Junction type' => {
my class TestClass {
has $.attribute where Positional|Associative;
}
Expand All @@ -23,9 +23,9 @@ subtest {

is-deeply $obj.attribute, [ "foo", "bar" ], "attribute got set correctly";

}, 'where subset with Junction type';
}

subtest {
subtest 'positional vs associative mismatch' => {
my class TestClass {
has Str @.attribute;
}
Expand All @@ -35,9 +35,9 @@ subtest {

throws-like { unmarshal($with-object-attr, TestClass) }, X::CannotUnmarshal, "object passed for positional attribute";

}, 'positional vs associative mismatch';
}

subtest {
subtest 'class that does positional with pairwise constructor at top level' => {
my class TestClass does Positional {
has Str $.string;
}
Expand All @@ -50,9 +50,9 @@ subtest {

is $obj.string, 'test value', "got the attribute back";

}, 'class that does positional with pairwise constructor at top level';
}

subtest {
subtest 'class that does positional with pairwise constructor as attribute' => {
my class TestClassPos does Positional {
has Str $.string;
}
Expand All @@ -68,5 +68,6 @@ subtest {
lives-ok { $obj = unmarshal($string-attribute, TestClass) }, "unmarshal";

is $obj.pos.string, 'test value', "got the attribute back";
}

}, 'class that does positional with pairwise constructor as attribute';
# vim: expandtab shiftwidth=4 ft=raku
6 changes: 2 additions & 4 deletions t/opt-in.rakutest → t/110-opt-in.rakutest
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env raku

use Test;

use JSON::Unmarshal;
use JSON::OptIn;
use JSON::Name;
Expand All @@ -22,5 +21,4 @@ lives-ok { $obj = unmarshal($json, OptInClass, :opt-in) }, 'unmarshal with opt-i
is $obj.not_opted_in, 'original', "attribute not marked explicitly not populated from JSON";
is $obj.opted_in, 'something', "attribute marked is set";

done-testing;
# vim: ft=raku
# vim: expandtab shiftwidth=4 ft=raku

0 comments on commit 0153ab0

Please # to comment.