okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
e4c3bd6
main
1// Inline math has to leave the dollar signs of prices and shell variables 2// alone, and display math has to stay inside the list item it belongs to. 3// Replies in e2e are scripted and never look at layout, so only these pin it. 4package tui 5 6import ( 7"regexp" 8"testing" 9 10"github.com/charmbracelet/x/ansi" 11) 12 13func TestScanInlineMath (t * testing.T ) { 14for _ ,tc := range []struct { 15line string 16before rune 17tex string 18length int 19 }{ 20 {line :"$E = mc^2$ holds" ,before :' ' ,tex :"E = mc^2" ,length :10 }, 21 {line :`\(\alpha\) and` ,before :' ' ,tex :`\alpha` ,length :10 }, 22 {line :"$$x$$ inline" ,before :' ' ,tex :"x" ,length :5 }, 23 {line :`$a \$ b$` ,before :' ' ,tex :`a \$ b` ,length :8 }, 24 {line :"$5 or $10" ,before :' ' }, 25 {line :"$HOME/$USER" ,before :' ' }, 26 {line :"$FOO$BAR" ,before :' ' }, 27 {line :"$x$" ,before :'a' }, 28 {line :"$ x$" ,before :' ' }, 29 {line :"$x $" ,before :' ' }, 30 {line :"$x\n$" ,before :' ' }, 31 {line :"$$" ,before :' ' }, 32 } { 33tex ,length := scanInlineMath ([]byte (tc .line ),tc .before ) 34if tex != tc .tex || length != tc .length { 35t .Errorf ("%q after %q: got %q, %d; want %q, %d" ,tc .line ,tc .before ,tex ,length ,tc .tex ,tc .length ) 36 } 37 } 38} 39 40func TestDisplayMathHangsInsideListItems (t * testing.T ) { 41rendered := ansi .Strip (RenderMarkdownAnsi ("- item\n\n $$\\frac{a}{b}$$\n- next" ,40 )) 42want := "• item\n\n a\n ───\n b\n• next" 43if got := trailingSpace .ReplaceAllString (rendered ,"" );got != want { 44t .Errorf ("rendered\n%s\nwant\n%s" ,got ,want ) 45 } 46} 47 48var trailingSpace = regexp .MustCompile (`(?m) +$` )