@@ -154,6 +154,12 @@ def test_dump_retry
154154end
155155
156156class OpenAI ::Test ::EnumModelTest < Minitest ::Test
157+ class E0
158+ include OpenAI ::Internal ::Type ::Enum
159+
160+ def initialize ( *values ) = ( @values = values )
161+ end
162+
157163 module E1
158164 extend OpenAI ::Internal ::Type ::Enum
159165
@@ -183,6 +189,10 @@ module E4
183189
184190 def test_coerce
185191 cases = {
192+ [ E0 . new , "one" ] => [ { no : 1 } , "one" ] ,
193+ [ E0 . new ( :one ) , "one" ] => [ { yes : 1 } , :one ] ,
194+ [ E0 . new ( :two ) , "one" ] => [ { maybe : 1 } , "one" ] ,
195+
186196 # rubocop:disable Lint/BooleanSymbol
187197 [ E1 , true ] => [ { yes : 1 } , true ] ,
188198 [ E1 , false ] => [ { no : 1 } , false ] ,
@@ -432,8 +442,10 @@ def test_accessors
432442end
433443
434444class OpenAI ::Test ::UnionTest < Minitest ::Test
435- module U0
436- extend OpenAI ::Internal ::Type ::Union
445+ class U0
446+ include OpenAI ::Internal ::Type ::Union
447+
448+ def initialize ( *variants ) = variants . each { variant ( _1 ) }
437449 end
438450
439451 module U1
@@ -519,6 +531,11 @@ def test_coerce
519531 cases = {
520532 [ U0 , :"" ] => [ { no : 1 } , 0 , :"" ] ,
521533
534+ [ U0 . new ( Integer , Float ) , "one" ] => [ { no : 1 } , 2 , "one" ] ,
535+ [ U0 . new ( Integer , Float ) , 1.0 ] => [ { yes : 1 } , 2 , 1.0 ] ,
536+ [ U0 . new ( { const : :a } ) , "a" ] => [ { yes : 1 } , 1 , :a ] ,
537+ [ U0 . new ( { const : :a } ) , "2" ] => [ { maybe : 1 } , 1 , "2" ] ,
538+
522539 [ U1 , "a" ] => [ { yes : 1 } , 1 , :a ] ,
523540 [ U1 , "2" ] => [ { maybe : 1 } , 2 , "2" ] ,
524541 [ U1 , :b ] => [ { maybe : 1 } , 2 , :b ] ,
@@ -556,6 +573,12 @@ def test_coerce
556573end
557574
558575class OpenAI ::Test ::BaseModelQoLTest < Minitest ::Test
576+ class E0
577+ include OpenAI ::Internal ::Type ::Enum
578+
579+ def initialize ( *values ) = ( @values = values )
580+ end
581+
559582 module E1
560583 extend OpenAI ::Internal ::Type ::Enum
561584
@@ -575,6 +598,26 @@ module E3
575598 B = 3
576599 end
577600
601+ class U0
602+ include OpenAI ::Internal ::Type ::Union
603+
604+ def initialize ( *variants ) = variants . each { variant ( _1 ) }
605+ end
606+
607+ module U1
608+ extend OpenAI ::Internal ::Type ::Union
609+
610+ variant String
611+ variant Integer
612+ end
613+
614+ module U2
615+ extend OpenAI ::Internal ::Type ::Union
616+
617+ variant String
618+ variant Integer
619+ end
620+
578621 class M1 < OpenAI ::Internal ::Type ::BaseModel
579622 required :a , Integer
580623 end
@@ -592,8 +635,15 @@ def test_equality
592635 [ OpenAI ::Internal ::Type ::Unknown , OpenAI ::Internal ::Type ::Unknown ] => true ,
593636 [ OpenAI ::Internal ::Type ::Boolean , OpenAI ::Internal ::Type ::Boolean ] => true ,
594637 [ OpenAI ::Internal ::Type ::Unknown , OpenAI ::Internal ::Type ::Boolean ] => false ,
638+ [ E0 . new ( :a , :b ) , E0 . new ( :a , :b ) ] => true ,
639+ [ E0 . new ( :a , :b ) , E0 . new ( :b , :a ) ] => true ,
640+ [ E0 . new ( :a , :b ) , E0 . new ( :b , :c ) ] => false ,
595641 [ E1 , E2 ] => true ,
596642 [ E1 , E3 ] => false ,
643+ [ U0 . new ( String , Integer ) , U0 . new ( String , Integer ) ] => true ,
644+ [ U0 . new ( String , Integer ) , U0 . new ( Integer , String ) ] => false ,
645+ [ U0 . new ( String , Float ) , U0 . new ( String , Integer ) ] => false ,
646+ [ U1 , U2 ] => true ,
597647 [ M1 , M2 ] => false ,
598648 [ M1 , M3 ] => true
599649 }
0 commit comments