# perl6/roast

[t/spec/] "Junction" -> "junction", ".eigenstates" -> "!eigenstates" …

…(as per r25891).

[t/TODO] Now we need to ensure that the tests can call junction!eigenstates.

git-svn-id: http://svn.pugscode.org/pugs@28971 c213334d-75ef-0310-aa23-eaa082d1ae64
Kodi authored and Kodi committed Nov 1, 2009
1 parent a586cc3 commit ffa7511e5a8c7a68f07952e45063147b9b28f05b
 @@ -8,7 +8,7 @@ plan 14; # TODO: need smartlink sub jv(Object \$j) { - return \$j.eigenstates.sort.join(' '); + return \$j!eigenstates.sort.join(' '); }
 @@ -4,17 +4,17 @@ use Test; plan 78; { - # Solves the equatioin A + B = A * C for integers + # Solves the equation A + B = A * C for integers # by autothreading over all interesting values my \$n = 0; sub is_it(\$a, \$b, \$c) { \$n++; if (\$a != \$b && \$b != \$c && \$a != \$c && \$a * 10 + \$c == \$a + \$b ) { - return "\$a + \$b = \$a\$c"; + return "\$a + \$b = \$a\$c"; } else { - return (); + return (); } } @@ -205,9 +205,9 @@ plan 78; # test that various things autothread { - my Junction \$j = [1, 2] | 5; - #?rakudo skip '.values and .eigenstates should flatten (?)' - is +\$j.values.eigenstates, 3, '([1, 2] | 3).values has three eigenstates'; + my junction \$j = [1, 2] | 5; + #?rakudo skip '.values and !eigenstates should flatten (?)' + is +\$j.values!eigenstates, 3, '([1, 2] | 3).values has three eigenstates'; #?rakudo 3 skip 'autothreading of prefix:<+>' ok ?( +\$j == 5 ), 'prefix:<+> autothreads (1)';
 @@ -15,9 +15,9 @@ These tests are derived from the Perl6 and Parrot Essentials Chapter 4, page 42 # L my \$j = any(1, 2, 3); -ok \$j ~~ Junction, '\$j is a Junction'; +ok \$j ~~ junction, '\$j is a junction'; -my @values = \$j.eigenstates.sort; +my @values = \$j!eigenstates.sort; is(+@values, 3, 'our junction has three values in it'); is(@values[0], 1, 'our junctions first value is 1'); @@ -26,18 +26,18 @@ is(@values[2], 3, 'our junctions third value is 3'); my \$sums = \$j + 3; -ok \$sums ~~ Junction, '\$j + 3 is also a Junction'; +ok \$sums ~~ junction, '\$j + 3 is also a junction'; -my @sums_values = sort \$sums.eigenstates; +my @sums_values = sort \$sums!eigenstates; is(+@sums_values, 3, 'our junction has three values in it'); is(@sums_values[0], 4, 'our junctions first value is 4'); is(@sums_values[1], 5, 'our junctions second value is 5'); is(@sums_values[2], 6, 'our junctions third value is 6'); # loop enough to go through it twice for (1 .. 6) { - ok((1 ^ 2 ^ 3) == \$j.eigenstates.pick, 'it is always at least one'); - ok((1 | 2 | 3) == \$j.eigenstates.pick, 'it is always one of them'); + ok((1 ^ 2 ^ 3) == \$j!eigenstates.pick, 'it is always at least one'); + ok((1 | 2 | 3) == \$j!eigenstates.pick, 'it is always one of them'); } # vim: ft=perl6
 @@ -58,13 +58,13 @@ ok ?(0|\$undef == 0), '0|undef == 0 in boolean context'; my \$message1 = 'boolean context collapses junctions'; my \$message2 = '...so that they\'re not junctions anymore'; ok ?(Bool::True & Bool::False) == Bool::False, \$message1; -ok ?(Bool::True & Bool::False) !~~ Junction, \$message2; +ok ?(Bool::True & Bool::False) !~~ junction, \$message2; ok !(Bool::True & Bool::False) == Bool::True, \$message1; -ok !(Bool::True & Bool::False) !~~ Junction, \$message2; +ok !(Bool::True & Bool::False) !~~ junction, \$message2; #?rakudo 2 todo 'named unary as function call' ok true(Bool::True & Bool::False) == Bool::False, \$message1; -ok true(Bool::True & Bool::False) !~~ Junction, \$message2; +ok true(Bool::True & Bool::False) !~~ junction, \$message2; ok not(Bool::True & Bool::False) == Bool::True, \$message1; -ok not(Bool::True & Bool::False) !~~ Junction, \$message2; +ok not(Bool::True & Bool::False) !~~ junction, \$message2; # vim: ft=perl6
 @@ -8,15 +8,15 @@ use Test; plan 7; -is +any(1,2,3).eigenstates, 3; -is +(1 | 2 | 3).eigenstates, 3; +is +any(1,2,3)!eigenstates, 3; +is +(1 | 2 | 3)!eigenstates, 3; -is +all(1,2,3).eigenstates, 3; -is +(1 & 2 & 3).eigenstates, 3; +is +all(1,2,3)!eigenstates, 3; +is +(1 & 2 & 3)!eigenstates, 3; -is +one(1,2,3).eigenstates, 3; -is +(1 ^ 2 ^ 3).eigenstates, 3; +is +one(1,2,3)!eigenstates, 3; +is +(1 ^ 2 ^ 3)!eigenstates, 3; -is +none(1,2,3).eigenstates, 3; +is +none(1,2,3)!eigenstates, 3; # vim: ft=perl6
 @@ -1,33 +1,35 @@ use v6; use Test; -plan 13; +plan 14; # L +dies_ok { (1|2).eigenstates }, 'junction doesn't have a public .eigenstates'; + sub je(Object \$j) { - return \$j.eigenstates.sort.join('|'); + return \$j!eigenstates.sort.join('|'); } -is je(any(1, 3, 2)), '1|2|3', '.eigenstates on any-junction (sub form)'; -is je(3|1|2), '1|2|3', '.eigenstates on any-junction (operator form)'; +is je(any(1, 3, 2)), '1|2|3', '!eigenstates on any-junction (sub form)'; +is je(3|1|2), '1|2|3', '!eigenstates on any-junction (operator form)'; -is je(all(1, 3, 2)), '1|2|3', '.eigenstates on all-junction (sub form)'; -is je(3&1&2), '1|2|3', '.eigenstates on all-junction (operator form)'; +is je(all(1, 3, 2)), '1|2|3', '!eigenstates on all-junction (sub form)'; +is je(3&1&2), '1|2|3', '!eigenstates on all-junction (operator form)'; -is je(one(1, 3, 2)), '1|2|3', '.eigenstates on one-junction (sub form)'; -is je(3^1^2), '1|2|3', '.eigenstates on one-junction (operator form)'; +is je(one(1, 3, 2)), '1|2|3', '!eigenstates on one-junction (sub form)'; +is je(3^1^2), '1|2|3', '!eigenstates on one-junction (operator form)'; -is je(none(1, 3, 2)), '1|2|3', '.eigenstates on none-junction'; +is je(none(1, 3, 2)), '1|2|3', '!eigenstates on none-junction'; -#?rakudo 2 skip '.eigenstates on nested junctions' -is +(1|(2|3)).eigenstates, 3, 'Nested junctions are flattened (count)'; +#?rakudo 2 skip '!eigenstates on nested junctions' +is +(1|(2|3))!eigenstates, 3, 'Nested junctions are flattened (count)'; is je(1|(2|3)), '1|2|3', 'Nested junctions are flattened (result)'; -# .eigenstates on any non-junction just gives a list of the thing itself -is 42.eigenstates.elems, 1, 'eigenstates on value is list of one item'; -is 42.eigenstates[0], 42, 'eigenstates on value is list containing the thingy'; +# !eigenstates on any non-junction just gives a list of the thing itself +is 42!eigenstates.elems, 1, 'eigenstates on value is list of one item'; +is 42!eigenstates[0], 42, 'eigenstates on value is list containing the thingy'; my \$x = "pivo"; -is \$x.eigenstates.elems, 1, 'eigenstates on non-Junction variable is list of one item'; -is \$x.eigenstates[0], 'pivo', 'eigenstates on non-Junction variable is list containing the thingy'; +is \$x!eigenstates.elems, 1, 'eigenstates on non-Junction variable is list of one item'; +is \$x!eigenstates[0], 'pivo', 'eigenstates on non-Junction variable is list containing the thingy'; # vim: ft=perl6
 @@ -11,8 +11,8 @@ Misc. Junction tests =end pod #?rakudo skip 'Null PMC access in get_integer() (RT #64184)' -isa_ok any(6,7), Junction; -is any(6,7).WHAT, Junction, 'Junction.WHAT works'; +isa_ok any(6,7), junction; +is any(6,7).WHAT, junction, 'junction.WHAT works'; # avoid auto-threading on ok() sub jok(Object \$condition, \$msg?) { ok ?(\$condition), \$msg }; @@ -134,14 +134,14 @@ sub jok(Object \$condition, \$msg?) { ok ?(\$condition), \$msg }; my \$l; \$j = 1|2; - is(~WHAT(\$j), 'Junction()', 'basic junction type reference test'); + is(~WHAT(\$j), 'junction()', 'basic junction type reference test'); \$k=\$j; - is(~WHAT(\$k), 'Junction()', 'assignment preserves reference'); + is(~WHAT(\$k), 'junction()', 'assignment preserves reference'); # XXX does this next one make any sense? \$l=\\$j; - is(~WHAT(\$l), 'Junction()', 'hard reference to junction'); + is(~WHAT(\$l), 'junction()', 'hard reference to junction'); } @@ -157,7 +157,7 @@ just using .perl until a better approach presents itself. # L # Canonical stringification of a junction -sub j (Junction \$j) { return \$j.perl } +sub j (junction \$j) { return \$j.perl } { # L @@ -327,66 +327,66 @@ ok(!(?(1&0) != ?(1&&0)), 'boolean context'); ok ?(undef & undef ~~ undef), 'undef & undef ~~ undef works'; ## See also S03-junctions/autothreading.t -#?rakudo skip 'substr on juctions' +#?rakudo skip 'substr on junctions' { is substr("abcd", 1, 2), "bc", "simple substr"; my \$res = substr(any("abcd", "efgh"), 1, 2); - isa_ok \$res, "Junction"; - ok \$res eq "bc", "substr on Junctions: bc"; - ok \$res eq "fg", "substr on Junctions: fg"; + isa_ok \$res, "junction"; + ok \$res eq "bc", "substr on junctions: bc"; + ok \$res eq "fg", "substr on junctions: fg"; } -#?rakudo skip 'substr on juctions' +#?rakudo skip 'substr on junctions' { my \$res = substr("abcd", 1|2, 2); - isa_ok \$res, "Junction"; - ok \$res eq "bc", "substr on Junctions: bc"; - ok \$res eq "cd", "substr on Junctions: cd"; + isa_ok \$res, "junction"; + ok \$res eq "bc", "substr on junctions: bc"; + ok \$res eq "cd", "substr on junctions: cd"; } -#?rakudo skip 'substr on juctions' +#?rakudo skip 'substr on junctions' { my \$res = substr("abcd", 1, 1|2); - isa_ok \$res, "Junction"; - ok \$res eq "bc", "substr on Junctions: bc"; - ok \$res eq "b", "substr on Junctions: b"; + isa_ok \$res, "junction"; + ok \$res eq "bc", "substr on junctions: bc"; + ok \$res eq "b", "substr on junctions: b"; } -#?rakudo skip 'index on juctions' +#?rakudo skip 'index on junctions' { my \$res = index(any("abcd", "qwebdd"), "b"); - isa_ok \$res, "Junction"; - ok \$res == 1, "index on Junctions: 1"; - ok \$res == 3, "index on Junctions: 3"; + isa_ok \$res, "junction"; + ok \$res == 1, "index on junctions: 1"; + ok \$res == 3, "index on junctions: 3"; } -#?rakudo skip 'index on juctions' +#?rakudo skip 'index on junctions' { my \$res = index("qwebdd", "b"|"w"); - isa_ok \$res, "Junction"; - ok \$res == 1, "index on Junctions: 1"; - ok \$res == 3, "index on Junctions: 3"; + isa_ok \$res, "junction"; + ok \$res == 1, "index on junctions: 1"; + ok \$res == 3, "index on junctions: 3"; } -# Naive implementation of comparing two Junctions +# Naive implementation of comparing two junctions sub junction_diff(Object \$this, Object \$that) { - if (\$this.WHAT ne 'Junction()' and \$that.WHAT ne 'Junction()') { + if (\$this.WHAT ne 'junction()' and \$that.WHAT ne 'junction()') { return if \$this ~~ \$that; } - if (\$this.WHAT ne 'Junction()' and \$that.WHAT eq 'Junction()') { - return "This is not a Junction"; + if (\$this.WHAT ne 'junction()' and \$that.WHAT eq 'junction()') { + return "This is not a junction"; } - if (\$this.WHAT eq 'Junction()' and \$that.WHAT ne 'Junction()') { - return "That is not a Junction"; + if (\$this.WHAT eq 'junction()' and \$that.WHAT ne 'junction()') { + return "That is not a junction"; } my (\$this_type) = \$this.perl ~~ /^(\w+)/; my (\$that_type) = \$that.perl ~~ /^(\w+)/; if (\$this_type ne \$that_type) { return "This is \$this_type, that is \$that_type"; } - my @these = sort \$this.eigenstates; - my @those = sort \$that.eigenstates; + my @these = sort \$this!eigenstates; + my @those = sort \$that!eigenstates; my @errors; for @these -> \$value { if \$value !~~ any(@those) { @@ -404,9 +404,9 @@ sub junction_diff(Object \$this, Object \$that) { #?rakudo skip 'Confusing tests (to pmichaud)' { - ok(! junction_diff(1, 1), 'no Junctions'); - is_deeply(junction_diff(1, 1|2), "This is not a Junction", 'Left value is not a Junction'); - is_deeply(junction_diff(1|2, 1), "That is not a Junction", 'Right value is not a Junction'); + ok(! junction_diff(1, 1), 'no junctions'); + is_deeply(junction_diff(1, 1|2), "This is not a junction", 'Left value is not a junction'); + is_deeply(junction_diff(1|2, 1), "That is not a junction", 'Right value is not a junction'); ok(! junction_diff(1|2, 1|2), 'same any junctions'); is_deeply(junction_diff(1|2, 1&2), 'This is any, that is all', 'different junction types'); is_deeply(junction_diff(1|2|3, 1|2), ["3 is missing from that"], 'Value is missing from right side'); @@ -427,10 +427,10 @@ sub junction_diff(Object \$this, Object \$that) { # RT#67866: [BUG] [LHF] Error with stringifying .WHAT on any junctions { - ok((WHAT any()) === Junction, "test WHAT on empty any junction"); - ok(any().WHAT === Junction, "test WHAT on empty any junction"); - ok((WHAT any(1,2)) === Junction, "test WHAT on any junction"); - ok(any(1,2).WHAT === Junction, "test WHAT on any junction"); + ok((WHAT any()) === junction, "test WHAT on empty any junction"); + ok(any().WHAT === junction, "test WHAT on empty any junction"); + ok((WHAT any(1,2)) === junction, "test WHAT on any junction"); + ok(any(1,2).WHAT === junction, "test WHAT on any junction"); } # vim: ft=perl6
 @@ -88,14 +88,14 @@ lives_ok {my \$x = -> {}; my \$y = \$x(); }, # The default type of pointy blocks is Object, not Any. See # http://www.nntp.perl.org/group/perl.perl6.language/2009/03/msg31181.html # L -# this means that Junctions don't autothread over pointy blocks +# this means that junctions don't autothread over pointy blocks { my @a = any(3, 4); my \$ok = 0; my \$iterations = 0; for @a -> \$x { - \$ok = 1 if \$x ~~ Junction; + \$ok = 1 if \$x ~~ junction; \$iterations++; } ok \$ok, 'Blocks receive junctions without autothreading';
 @@ -26,6 +26,6 @@ ok_eval1('Grapheme.isa(AnyChar)'); ok_eval1('Codepoint.isa(AnyChar)'); ok_eval1('Byte.isa(AnyChar)'); ok_eval1('Byte.isa(Num)'); -ok_eval1('subset MatchTest of Item | Junction;'); +ok_eval1('subset MatchTest of Item | junction;'); # vim: ft=perl6
3 TODO
 @@ -48,7 +48,6 @@ the spec (newest first) * (r28150, r28151) ::=, implicit 'is context' on \$*foo variables * (r26968) Now we know how \$! works. * (r26401) Pi/Pf characters are allowed as brackets -* (r25891) Junction -> junction, eigenstates method is now private * (r25830) named parameters to open() * (r25767) updates to builtin regexes @@ -61,6 +60,8 @@ S03 * tests for feeds using IO objects * more bitwise tests, for :signed and :unsigned, and uncomment the tests in t/spec/S03-operators/bit.t +* the tests in S03-junctions should somehow specially arrange for + access to the private method !eigenstates S04 * test warn()