File tree Expand file tree Collapse file tree 2 files changed +40
-5
lines changed
Tests/OneScript.Core.Tests Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ This Source Code Form is subject to the terms of the
99using OneScript . Exceptions ;
1010using OneScript . Localization ;
1111using OneScript . Types ;
12+ using ScriptEngine . Machine ;
1213
1314namespace OneScript . Values
1415{
@@ -57,12 +58,15 @@ public override string ToString()
5758
5859 public override bool Equals ( BslValue other )
5960 {
60- if ( ReferenceEquals ( null , other ) )
61- return false ;
62- if ( ReferenceEquals ( this , other ) )
63- return true ;
61+ if ( other is null ) return false ;
62+ if ( ReferenceEquals ( this , other ) ) return true ;
6463
65- return false ;
64+ return other switch
65+ {
66+ BslNumericValue num => num == ( ( decimal ) this ) ,
67+ BslBooleanValue boolean => _flag == boolean . _flag ,
68+ _ => false
69+ } ;
6670 }
6771
6872 public override int CompareTo ( BslValue other )
Original file line number Diff line number Diff line change @@ -201,6 +201,37 @@ public void String_To_String_Comparison()
201201 str1 . CompareTo ( ValueFactory . Create ( "абв" ) ) . Should ( ) . BeGreaterThan ( 0 ) ;
202202 }
203203
204+ [ Fact ]
205+ public void Boolean_Equality ( )
206+ {
207+ var bool1 = ValueFactory . Create ( true ) ;
208+ var bool0 = ValueFactory . Create ( false ) ;
209+ var num1 = ValueFactory . Create ( 1 ) ;
210+ var num0 = ValueFactory . Create ( 0 ) ;
211+ var num2 = ValueFactory . Create ( 2 ) ;
212+
213+ Assert . True ( bool0 . Equals ( bool0 ) ) ;
214+ Assert . True ( bool1 . Equals ( bool1 ) ) ;
215+ Assert . False ( bool0 . Equals ( bool1 ) ) ;
216+ Assert . False ( bool1 . Equals ( bool0 ) ) ;
217+
218+ Assert . True ( bool0 . Equals ( num0 ) ) ;
219+ Assert . True ( bool1 . Equals ( num1 ) ) ;
220+ Assert . False ( bool0 . Equals ( num1 ) ) ;
221+ Assert . False ( bool1 . Equals ( num0 ) ) ;
222+
223+ Assert . False ( bool0 . Equals ( num2 ) ) ;
224+ Assert . False ( bool1 . Equals ( num2 ) ) ;
225+
226+ Assert . True ( num0 . Equals ( bool0 ) ) ;
227+ Assert . True ( num1 . Equals ( bool1 ) ) ;
228+ Assert . False ( num0 . Equals ( bool1 ) ) ;
229+ Assert . False ( num1 . Equals ( bool0 ) ) ;
230+
231+ Assert . False ( num2 . Equals ( bool1 ) ) ;
232+ Assert . False ( num2 . Equals ( bool0 ) ) ;
233+ }
234+
204235 [ Fact ]
205236 public void Boolean_Comparison ( )
206237 {
You can’t perform that action at this time.
0 commit comments