(defun sp-test--paired-expression-parse-in-latex (initial result &optional back)
  (let ((sp-pairs '((t . ((:open "\\{" :close "\\}" :actions (insert wrap autoskip navigate))
                          (:open "("   :close ")"   :actions (insert wrap autoskip navigate))
                          (:open "["   :close "]"   :actions (insert wrap autoskip navigate))
                          (:open "{"   :close "}"   :actions (insert wrap autoskip navigate))
                          (:open "\""  :close "\""  :actions (insert wrap autoskip navigate))
                          (:open "\\\""  :close "\\\""  :actions (insert wrap autoskip navigate))
                          (:open "\\langle"  :close "\\rangle"  :actions (insert wrap autoskip navigate))
                          (:open "OPEN"  :close "CLOSE"  :actions (insert wrap autoskip navigate))
                          (:open "\\big("  :close "\\big)"  :actions (insert wrap autoskip navigate) :trigger "\\b")
                          (:open "``"   :close "''" :actions (insert wrap autoskip navigate))
                          (:open "`"   :close "'" :actions (insert wrap autoskip navigate))
                          (:open "$"   :close "$" :actions (insert wrap autoskip navigate)))))))
    (sp-test-with-temp-buffer initial
        (latex-mode)
      (should (equal (sp-get-paired-expression back) result)))))

(ert-deftest sp-test-get-paired-expression-latex ()
  (sp-test--paired-expression-parse-in-latex "|``''"  '(:beg 1 :end 5 :op "``" :cl "''" :prefix "" :suffix ""))
  (sp-test--paired-expression-parse-in-latex "``|''"  '(:beg 1 :end 5 :op "``" :cl "''" :prefix "" :suffix ""))
  (sp-test--paired-expression-parse-in-latex "|foo ``bar'' baz"  '(:beg 5 :end 12 :op "``" :cl "''" :prefix "" :suffix ""))
  (sp-test--paired-expression-parse-in-latex "|`'"  '(:beg 1 :end 3 :op "`" :cl "'" :prefix "" :suffix ""))
  (sp-test--paired-expression-parse-in-latex "`|'"  '(:beg 1 :end 3 :op "`" :cl "'" :prefix "" :suffix ""))
  (sp-test--paired-expression-parse-in-latex "|foo `bar' baz"  '(:beg 5 :end 10 :op "`" :cl "'" :prefix "" :suffix ""))
  )

(ert-deftest sp-test-get-paired-expression-latex-backward ()
  (sp-test--paired-expression-parse-in-latex "``''|"  '(:beg 1 :end 5 :op "``" :cl "''" :prefix "" :suffix "") t)
  (sp-test--paired-expression-parse-in-latex "``|''"  '(:beg 1 :end 5 :op "``" :cl "''" :prefix "" :suffix "") t)
  (sp-test--paired-expression-parse-in-latex "foo ``bar'' b|az"  '(:beg 5 :end 12 :op "``" :cl "''" :prefix "" :suffix "") t)
  (sp-test--paired-expression-parse-in-latex "`'|"  '(:beg 1 :end 3 :op "`" :cl "'" :prefix "" :suffix "") t)
  (sp-test--paired-expression-parse-in-latex "`|'"  '(:beg 1 :end 3 :op "`" :cl "'" :prefix "" :suffix "") t)
  (sp-test--paired-expression-parse-in-latex "foo `bar' baz|"  '(:beg 5 :end 10 :op "`" :cl "'" :prefix "" :suffix "") t)
  )
