@@ -594,4 +594,41 @@ func TestReadExitContinuation(t *testing.T) {
594594 assert .Equal (t , "(select 1)" , result )
595595 assert .False (t , readLineCalled , "Readline should not be called for balanced input" )
596596 })
597+
598+ t .Run ("restores original prompt when batch is initialized" , func (t * testing.T ) {
599+ s := & Sqlcmd {}
600+ s .batch = NewBatch (nil , nil )
601+ lines := []string {")" }
602+ lineIndex := 0
603+ s .lineIo = & testConsole {
604+ OnReadLine : func () (string , error ) {
605+ if lineIndex >= len (lines ) {
606+ return "" , io .EOF
607+ }
608+ line := lines [lineIndex ]
609+ lineIndex ++
610+ return line , nil
611+ },
612+ OnPasswordPrompt : func (prompt string ) ([]byte , error ) {
613+ return nil , nil
614+ },
615+ }
616+ s .lineIo .SetPrompt ("1> " )
617+
618+ result , err := readExitContinuation (s , "(select 1" )
619+ assert .NoError (t , err )
620+ assert .Equal (t , "(select 1" + SqlcmdEol + ")" , result )
621+ // After function returns, prompt should be restored to original
622+ tc := s .lineIo .(* testConsole )
623+ assert .Equal (t , "1> " , tc .PromptText )
624+ })
625+ }
626+
627+ func TestExitCommandNonInteractiveUnbalanced (t * testing.T ) {
628+ // Test that unbalanced parentheses in non-interactive mode returns InvalidCommandError
629+ s := & Sqlcmd {}
630+ s .lineIo = nil // non-interactive mode
631+
632+ err := exitCommand (s , []string {"(select 1" }, 1 )
633+ assert .EqualError (t , err , InvalidCommandError ("EXIT" , 1 ).Error (), "unbalanced parens in non-interactive should error" )
597634}
0 commit comments