@@ -454,4 +454,125 @@ describe('NON-STRICT MODE (Math-ASCII/Typst-like syntax)', () => {
454454 ` ) ;
455455 } ) ;
456456 } ) ;
457+
458+ describe ( 'Bare function exponents' , ( ) => {
459+ test ( 'sin^2(x)' , ( ) => {
460+ expect ( ce . parse ( 'sin^2(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
461+ `["Square", ["Sin", "x"]]`
462+ ) ;
463+ } ) ;
464+
465+ test ( 'cos^{10}(x)' , ( ) => {
466+ expect (
467+ ce . parse ( 'cos^{10}(x)' , { strict : false } )
468+ ) . toMatchInlineSnapshot ( `["Power", ["Cos", "x"], 10]` ) ;
469+ } ) ;
470+
471+ test ( 'tan^-1(x)' , ( ) => {
472+ expect ( ce . parse ( 'tan^-1(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
473+ `["Divide", 1, ["Tan", "x"]]`
474+ ) ;
475+ } ) ;
476+
477+ test ( 'sin^2(x) + cos^2(x) identity' , ( ) => {
478+ const a = ce . parse ( 'sin^2(x) + cos^2(x)' , { strict : false } ) ;
479+ expect ( a . isEqual ( 1 ) ) . toBe ( true ) ;
480+ } ) ;
481+ } ) ;
482+
483+ describe ( 'Bare log with subscript' , ( ) => {
484+ test ( 'log_2(x) → base 2' , ( ) => {
485+ expect ( ce . parse ( 'log_2(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
486+ `["Log", "x", 2]`
487+ ) ;
488+ } ) ;
489+
490+ test ( 'log_{10}(x) → base 10 (default)' , ( ) => {
491+ expect (
492+ ce . parse ( 'log_{10}(x)' , { strict : false } )
493+ ) . toMatchInlineSnapshot ( `["Log", "x"]` ) ;
494+ } ) ;
495+
496+ test ( 'log_3(x) → base 3' , ( ) => {
497+ expect ( ce . parse ( 'log_3(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
498+ `["Log", "x", 3]`
499+ ) ;
500+ } ) ;
501+
502+ test ( 'log_b(x) → variable base' , ( ) => {
503+ expect ( ce . parse ( 'log_b(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
504+ `["Log", "x", "b"]`
505+ ) ;
506+ } ) ;
507+ } ) ;
508+
509+ describe ( 'Unicode superscripts' , ( ) => {
510+ test ( 'x² → Power' , ( ) => {
511+ expect ( ce . parse ( 'x²' ) ) . toMatchInlineSnapshot ( `["Square", "x"]` ) ;
512+ } ) ;
513+
514+ test ( 'x²³ → multi-digit exponent' , ( ) => {
515+ expect ( ce . parse ( 'x²³' ) ) . toMatchInlineSnapshot (
516+ `["Power", "x", 23]`
517+ ) ;
518+ } ) ;
519+
520+ test ( 'x⁻² → negative exponent' , ( ) => {
521+ expect ( ce . parse ( 'x⁻²' ) ) . toMatchInlineSnapshot (
522+ `["Divide", 1, ["Square", "x"]]`
523+ ) ;
524+ } ) ;
525+
526+ test ( 'xⁿ → letter superscript' , ( ) => {
527+ expect ( ce . parse ( 'xⁿ' ) ) . toMatchInlineSnapshot (
528+ `["Power", "x", "n"]`
529+ ) ;
530+ } ) ;
531+
532+ test ( '2ⁿ → numeric base with letter exponent' , ( ) => {
533+ expect ( ce . parse ( '2ⁿ' ) ) . toMatchInlineSnapshot (
534+ `["Power", 2, "n"]`
535+ ) ;
536+ } ) ;
537+
538+ test ( '\\sin²(x) → trig with Unicode exponent' , ( ) => {
539+ expect ( ce . parse ( '\\sin²(x)' ) ) . toMatchInlineSnapshot (
540+ `["Square", ["Sin", "x"]]`
541+ ) ;
542+ } ) ;
543+
544+ test ( 'sin²(x) bare + Unicode' , ( ) => {
545+ expect ( ce . parse ( 'sin²(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
546+ `["Square", ["Sin", "x"]]`
547+ ) ;
548+ } ) ;
549+ } ) ;
550+
551+ describe ( 'Unicode subscripts' , ( ) => {
552+ test ( 'x₁ → subscript' , ( ) => {
553+ expect ( ce . parse ( 'x₁' ) ) . toMatchInlineSnapshot ( `x_1` ) ;
554+ } ) ;
555+
556+ test ( 'x₁₂ → multi-digit subscript' , ( ) => {
557+ expect ( ce . parse ( 'x₁₂' ) ) . toMatchInlineSnapshot ( `x_12` ) ;
558+ } ) ;
559+
560+ test ( 'x₁² → subscript + superscript' , ( ) => {
561+ expect ( ce . parse ( 'x₁²' ) ) . toMatchInlineSnapshot (
562+ `["Square", "x_1"]`
563+ ) ;
564+ } ) ;
565+
566+ test ( 'log₂(x) → Unicode subscript on bare log' , ( ) => {
567+ expect ( ce . parse ( 'log₂(x)' , { strict : false } ) ) . toMatchInlineSnapshot (
568+ `["Log", "x", 2]`
569+ ) ;
570+ } ) ;
571+
572+ test ( 'log₁₀(x) → Unicode subscript base 10' , ( ) => {
573+ expect (
574+ ce . parse ( 'log₁₀(x)' , { strict : false } )
575+ ) . toMatchInlineSnapshot ( `["Log", "x"]` ) ;
576+ } ) ;
577+ } ) ;
457578} ) ;
0 commit comments