New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't sort objects of a custom class, can't supply .cmp method in Rakudo #1435
Comments
From @masakIn Rakudo 7ef386: $ perl6 -e 'class A {}; say (A.new, A.new).sort' $ perl6 -e 'class A {}; multi sub cmp(A $a, A $b) { 1 }; say (A.new, I'm not sure the end user should ever see that ungainly |
From @bbkr[18:12] <bbkr> rakudo: class A {}; say (A.new, A.new).sort # is this taken for tests |
The RT System itself - Status changed from 'new' to 'open' |
From @bbkrrechecked on * release, also works tests in |
@bbkr - Status changed from 'open' to 'resolved' |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in t/spec/S32-list/sort.t commit 307c1ab2718b1bb94c287d2b3ce1c365753f362a [t/spec] tests for RT #71258 Cant sort objects of a custom class, cant supply .cmp method in Rakudo Inline Patchdiff --git a/t/spec/S32-list/sort.t b/t/spec/S32-list/sort.t
index 1e0d219..27205a2 100644
--- a/t/spec/S32-list/sort.t
+++ b/t/spec/S32-list/sort.t
@@ -1,6 +1,6 @@
use v6;
use Test;
-plan 31;
+plan 35;
# L<S32::Containers/"List"/"=item sort">
@@ -220,4 +220,37 @@ plan 31;
'sort accepts rand method';
}
+# RT #71258
+{
+ class RT71258_1 { };
+
+ my @sorted;
+
+ lives_ok { @sorted = (RT71258_1.new, RT71258_1.new).sort },
+ 'sorting by stringified class instance (name and memory address)';
+
+ ok ([<]@sorted.map({.WHERE})),
+ 'checking sort order by class memory address';
+
+ class RT71258_2 {
+ has $.x;
+ method Str { $.x }
+ };
+
+ multi sub cmp(RT71258_2 $a, RT71258_2 $b) {
+ $a.x <=> $b.x;
+ }
+
+ lives_ok {
+ @sorted = (
+ RT71258_2.new(x => 2),
+ RT71258_2.new(x => 3),
+ RT71258_2.new(x => 1)
+ ).sort
+ }, 'sorting stringified class instance with custom cmp';
+
+ is ~@sorted, '1 2 3',
+ 'checking sort order with custom cmp';
+}
+
# vim: ft=perl6 |
Migrated from rt.perl.org#71258 (status was 'resolved')
Searchable as RT71258$
The text was updated successfully, but these errors were encountered: