@@ -41,6 +41,79 @@ module PyCall
4141 end
4242 end
4343
44+ describe '#<=>(other)' do
45+ context 'when the value of other is a PyTypeObjectWrapper' do
46+ context 'when the given class is a superclass in Python of the receiver' do
47+ it 'returns -1' do
48+ expect ( PyCall . builtins . list <=> PyCall . builtins . object ) . to eq ( -1 )
49+ end
50+ end
51+
52+ context 'when the given class is a subclass in Python of the receiver' do
53+ it 'returns 1' do
54+ expect ( PyCall . builtins . object <=> PyCall . builtins . list ) . to eq ( 1 )
55+ end
56+ end
57+
58+ context 'when the given class is the receiver' do
59+ it 'returns 0' do
60+ expect ( PyCall . builtins . list <=> PyCall . builtins . list ) . to eq ( 0 )
61+ end
62+ end
63+ end
64+
65+ context 'when the value of other is a PyTypePtr' do
66+ context 'when the given class is a superclass in Python of the receiver' do
67+ it 'returns -1' do
68+ expect ( PyCall . builtins . list <=> PyCall . builtins . object . __pyptr__ ) . to eq ( -1 )
69+ end
70+ end
71+
72+ context 'when the given class is a subclass in Python of the receiver' do
73+ it 'returns 1' do
74+ expect ( PyCall . builtins . object <=> PyCall . builtins . list . __pyptr__ ) . to eq ( 1 )
75+ end
76+ end
77+
78+ context 'when the given class is the receiver' do
79+ it 'returns 0' do
80+ expect ( PyCall . builtins . list <=> PyCall . builtins . list . __pyptr__ ) . to eq ( 0 )
81+ end
82+ end
83+ end
84+
85+ context 'when the value of other is a Class' do
86+ context 'when the given class is a superclass of the receiver' do
87+ it 'returns -1' do
88+ expect ( PyCall . builtins . list <=> Object ) . to eq ( -1 )
89+ expect ( PyCall . builtins . list <=> PyObjectWrapper ) . to eq ( -1 )
90+ end
91+ end
92+
93+ context 'when the given class is a subclass of the receiver' do
94+ let ( :subclass ) { Class . new ( PyCall . builtins . list ) }
95+
96+ it 'returns 1' do
97+ expect ( PyCall . builtins . list <=> subclass ) . to eq ( 1 )
98+ end
99+ end
100+
101+ context 'when the given class is neither a superclass or a subclass of the receiver' do
102+ it 'returns nil' do
103+ expect ( PyCall . builtins . list <=> PyTypeObjectWrapper ) . to eq ( nil )
104+ expect ( PyCall . builtins . list <=> Array ) . to eq ( nil )
105+ end
106+ end
107+ end
108+
109+ context 'when the other cases' do
110+ it 'returns nil' do
111+ expect ( PyCall . builtins . list <=> Conversion . from_ruby ( 42 ) ) . to eq ( nil )
112+ expect ( PyCall . builtins . list <=> 42 ) . to eq ( nil )
113+ end
114+ end
115+ end
116+
44117 describe '#===' do
45118 specify do
46119 expect ( PyCall . builtins . tuple === PyCall . tuple ( ) ) . to eq ( true )
0 commit comments