@@ -995,6 +995,78 @@ describe('NON EXACT WILDCARDS', () => {
995995 } ) ;
996996} ) ;
997997
998+ // GitHub Issue #258: BoxedExpression.match() with a Rational pattern
999+ describe ( 'RATIONAL PATTERN MATCHING' , ( ) => {
1000+ it ( 'should match Rational(3, 2) with Rational pattern' , ( ) => {
1001+ // Rational with two integers becomes a BoxedNumber
1002+ const result = match ( [ 'Rational' , '_num' , '_den' ] , [ 'Rational' , 3 , 2 ] ) ;
1003+ expect ( result ) . toMatchInlineSnapshot ( `
1004+ {
1005+ _den: 2,
1006+ _num: 3,
1007+ }
1008+ ` ) ;
1009+ } ) ;
1010+
1011+ it ( 'should match Rational(x, 2) with Rational pattern' , ( ) => {
1012+ // Rational with symbolic numerator is canonicalized as Multiply(x, Rational(1, 2))
1013+ const result = match ( [ 'Rational' , '_num' , '_den' ] , [ 'Rational' , 'x' , 2 ] ) ;
1014+ expect ( result ) . toMatchInlineSnapshot ( `
1015+ {
1016+ _den: 2,
1017+ _num: x,
1018+ }
1019+ ` ) ;
1020+ } ) ;
1021+
1022+ it ( 'should match Rational(x, 9) with Rational pattern' , ( ) => {
1023+ // Rational(x, Power(3, 2)) is canonicalized as Multiply(x, Rational(1, 9))
1024+ const result = match (
1025+ [ 'Rational' , '_num' , '_den' ] ,
1026+ [ 'Rational' , 'x' , [ 'Power' , 3 , 2 ] ]
1027+ ) ;
1028+ expect ( result ) . toMatchInlineSnapshot ( `
1029+ {
1030+ _den: 9,
1031+ _num: x,
1032+ }
1033+ ` ) ;
1034+ } ) ;
1035+
1036+ it ( 'should match Rational(3, y) with Rational pattern' , ( ) => {
1037+ // Rational with symbolic denominator becomes Divide(3, y)
1038+ const result = match ( [ 'Rational' , '_num' , '_den' ] , [ 'Rational' , 3 , 'y' ] ) ;
1039+ expect ( result ) . toMatchInlineSnapshot ( `
1040+ {
1041+ _den: y,
1042+ _num: 3,
1043+ }
1044+ ` ) ;
1045+ } ) ;
1046+
1047+ it ( 'should match Rational(x, y) with Rational pattern' , ( ) => {
1048+ // Rational with two symbols becomes Divide(x, y)
1049+ const result = match ( [ 'Rational' , '_num' , '_den' ] , [ 'Rational' , 'x' , 'y' ] ) ;
1050+ expect ( result ) . toMatchInlineSnapshot ( `
1051+ {
1052+ _den: y,
1053+ _num: x,
1054+ }
1055+ ` ) ;
1056+ } ) ;
1057+
1058+ it ( 'should match Divide pattern against Multiply with reciprocal' , ( ) => {
1059+ // x/2 is canonicalized as Multiply(Rational(1, 2), x)
1060+ const result = match ( [ 'Divide' , '_num' , '_den' ] , [ 'Rational' , 'x' , 2 ] ) ;
1061+ expect ( result ) . toMatchInlineSnapshot ( `
1062+ {
1063+ _den: 2,
1064+ _num: x,
1065+ }
1066+ ` ) ;
1067+ } ) ;
1068+ } ) ;
1069+
9981070describe ( 'PATTERN VALIDATION' , ( ) => {
9991071 // Test validatePattern directly with non-canonical patterns
10001072 // (canonical forms may reorder operands for commutative operators)
0 commit comments