;;; test-ox-bb.el --- Tests for ox-bb.el -*- lexical-binding: t; -*- ;; Copyright (C) 2017-2019, 2021 Christian Garbs ;; Author: Christian Garbs ;; This file is not part of GNU Emacs. ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Tests for ox-bb.el. ;;; Code: (require 'ox-bb) ;;; helper functions (defun test-org-bb-verbatim-regression () "Return t if verbatim blocks generate an extra newline. This lets the tests react to a possible regression introduced with 7d9e4da447 which was released with Org 9.1.14. See https://lists.gnu.org/archive/html/emacs-orgmode/2021-01/msg00338.html for details." (not (version< (org-release) "9.1.14"))) ;;; sanity check (ert-deftest test-org-bb/assert () (should t)) ;;; tests of internal functions ;;; org-bb--as-block (ert-deftest test-org-bb/as-block/plain () (should (equal( org-bb--as-block "some text\nline two") "\nsome text\nline two\n"))) ;;; org-bb--force-leading-newline (ert-deftest test-org-bb/force-leading-newline/add-missing-newline () (should (equal( org-bb--force-leading-newline "some text") "\nsome text"))) (ert-deftest test-org-bb/force-leading-newline/keep-existing-newline () (should (equal( org-bb--force-leading-newline "\nonly one newline") "\nonly one newline"))) (ert-deftest test-org-bb/force-leading-newline/remove-additional-newlines () (should (equal( org-bb--force-leading-newline "\n\nsome text") "\nsome text"))) (ert-deftest test-org-bb/force-leading-newline/keep-newlines-within () (should (equal( org-bb--force-leading-newline "\nline 1\nline 2\n") "\nline 1\nline 2\n"))) ;;; org-bb--format-headline (ert-deftest test-org-bb/format-headline/level-0 () (should (equal( org-bb--format-headline "some text" 0) "[b][u]some text[/u][/b]\n\n"))) (ert-deftest test-org-bb/format-headline/level-1 () (should (equal( org-bb--format-headline "some text" 1) "[b][u]# some text[/u][/b]\n\n"))) (ert-deftest test-org-bb/format-headline/level-2 () (should (equal( org-bb--format-headline "some text" 2) "[b][u]== some text[/u][/b]\n\n"))) (ert-deftest test-org-bb/format-headline/level-3 () (should (equal( org-bb--format-headline "some text" 3) "[b][u]+++ some text[/u][/b]\n\n"))) (ert-deftest test-org-bb/format-headline/level-4 () (should (equal( org-bb--format-headline "some text" 4) "[b][u]:::: some text[/u][/b]\n\n"))) (ert-deftest test-org-bb/format-headline/level-5 () (should (equal( org-bb--format-headline "some text" 5) "[b][u]----- some text[/u][/b]\n\n"))) ;;; org-bb--put-in-tag (ert-deftest test-org-bb/put-in-tag/no-attribute () (should (equal (org-bb--put-in-tag "p" "foo") "[p]foo[/p]"))) (ert-deftest test-org-bb/put-in-tag/single-attribute () (should (equal (org-bb--put-in-tag "style" "foo" '(("size" "30px"))) "[style size=\"30px\"]foo[/style]"))) (ert-deftest test-org-bb/put-in-tag/multiple-attributes () (should (equal (org-bb--put-in-tag "style" "foo" '(("color" "#00FF00") ("size" "30px"))) "[style color=\"#00FF00\" size=\"30px\"]foo[/style]"))) ;;; org-bb--put-in-value-tag (ert-deftest test-org-bb/put-in-value-tag/plain () (should (equal (org-bb--put-in-value-tag "url" "foo" "file.htm") "[url=file.htm]foo[/url]"))) ;;; org-bb--put-url (ert-deftest test-org-bb/put-url/plain () (should (equal (org-bb--put-url "some text" "https://example.com/") "[url=https://example.com/]some text[/url]"))) (ert-deftest test-org-bb/put-url/empty () (should (equal (org-bb--put-url nil "https://example.com/") "[url=https://example.com/]https://example.com/[/url]"))) (ert-deftest test-org-bb/put-url/anchor () (should (equal (org-bb--put-url "anchor text" "#anchor") "[url=#anchor]anchor text[/url]"))) (ert-deftest test-org-bb/put-url/encode-url-only-once () (should (equal (org-bb--put-url "baz" "http://foo/%20bar") "[url=http://foo/%20bar]baz[/url]"))) ;;; org-bb--remove-leading-newline (ert-deftest test-org-bb/remove-leading-newline/remove () (should (equal( org-bb--remove-leading-newline "\nsome text") "some text"))) (ert-deftest test-org-bb/remove-leading-newline/keep-text-before-first-newline () (should (equal( org-bb--remove-leading-newline "no empty line\nsome more text\n") "no empty line\nsome more text\n"))) (ert-deftest test-org-bb/remove-leading-newline/only-remove-first-newline () (should (equal( org-bb--remove-leading-newline "\n\nsome text") "\nsome text"))) (ert-deftest test-org-bb/remove-leading-newline/keep-newlines-within () (should (equal( org-bb--remove-leading-newline "\nline 1\nline 2") "line 1\nline 2"))) (ert-deftest test-org-bb/remove-leading-newline/dont-fail-with-no-newline () (should (equal( org-bb--remove-leading-newline "some text") "some text"))) ;;; org-bb--remove-trailing-newline (ert-deftest test-org-bb/remove-trailing-newline/remove () (should (equal( org-bb--remove-trailing-newline "some text\n") "some text"))) (ert-deftest test-org-bb/remove-trailing-newline/keep-text-after-last-newline () (should (equal( org-bb--remove-trailing-newline "some text\nno empty line") "some text\nno empty line"))) (ert-deftest test-org-bb/remove-trailing-newline/only-remove-last-newline () (should (equal( org-bb--remove-trailing-newline "some text\n\n") "some text\n"))) (ert-deftest test-org-bb/remove-trailing-newline/keep-newlines-within () (should (equal( org-bb--remove-trailing-newline "line 1\nline 2\n") "line 1\nline 2"))) (ert-deftest test-org-bb/remove-trailing-newline/dont-fail-with-no-newline () (should (equal( org-bb--remove-trailing-newline "some text") "some text"))) ;;; org-bb--map-to-geshi-language (ert-deftest test-org-bb/map-to-geshi-language/unchanged () (should (equal( org-bb--map-to-geshi-language "java") "java"))) (ert-deftest test-org-bb/map-to-geshi-language/changed () (should (equal( org-bb--map-to-geshi-language "elisp") "lisp"))) (ert-deftest test-org-bb/map-to-geshi-language/nil () (should (equal( org-bb--map-to-geshi-language nil) "plaintext"))) (ert-deftest test-org-bb/map-to-geshi-language/empty () (should (equal( org-bb--map-to-geshi-language "") "plaintext"))) ;;; end-to-end tests: compare given input file with expected export output (defun test-org-bb-export (input) "Transform INPUT to BBCode and return the result." (org-test-with-temp-text input (org-bb-export-as-bbcode) (with-current-buffer "*Org BBCode Export*" (buffer-substring-no-properties (point-min) (point-max))))) (ert-deftest test-org-bb/export-bold () (should (equal (test-org-bb-export "foo *BAR* baz ") "foo [b]BAR[/b] baz "))) (ert-deftest test-org-bb/export-code () (should (equal (test-org-bb-export "foo ~BAR~ baz ") "foo [font=monospace]BAR[/font] baz "))) (ert-deftest test-org-bb/export-entity () (should (equal (test-org-bb-export "This is *bold* and this is in \\ast{}asterisks\\ast{}. ") "This is [b]bold[/b] and this is in ∗asterisks∗. "))) (ert-deftest test-org-bb/export-fixed-width () ;; Where does the double newline before paragraph 2 come from? ;; in Org 9.1 there was only a single newline as expected. ;; A regression? (should (equal (test-org-bb-export "paragraph 1 : verbatim line : indented verbatim line paragraph 2") (if (test-org-bb-verbatim-regression) "paragraph 1 [code] verbatim line indented verbatim line [/code] paragraph 2 " "paragraph 1 [code] verbatim line indented verbatim line [/code] paragraph 2 ")))) (ert-deftest test-org-bb/export-footnote-multiple () (should (equal (test-org-bb-export "foo[fn:1] bar[fn:2] * Footnotes [fn:1] foo [fn:2] bar ") "foo^1 bar^2 [b][u]Footnotes[/u][/b] ^1: foo ^2: bar "))) (ert-deftest test-org-bb/export-footnote-plain () (should (equal (test-org-bb-export "bar[fn:1] * Footnotes [fn:1] foo ") "bar^1 [b][u]Footnotes[/u][/b] ^1: foo "))) (ert-deftest test-org-bb/export-geshi-block-without-language () (should (equal (test-org-bb-export "#+BEGIN_SRC package foo; /* dummy dummy */ #+END_SRC ") "[geshi lang=plaintext]package foo; /* dummy dummy */[/geshi] "))) (ert-deftest test-org-bb/export-geshi-block () (should (equal (test-org-bb-export "#+BEGIN_SRC java package foo; /* dummy dummy */ #+END_SRC ") "[geshi lang=java]package foo; /* dummy dummy */[/geshi] "))) (ert-deftest test-org-bb/export-headline-lv1 () (should (equal (test-org-bb-export "* TOPIC ") "[b][u]# TOPIC[/u][/b] "))) (ert-deftest test-org-bb/export-headline-lv2 () (should (equal (test-org-bb-export "* dummy ** TOPIC ") "[b][u]# dummy[/u][/b] [b][u]== TOPIC[/u][/b] "))) (ert-deftest test-org-bb/export-headline-lv3 () (should (equal (test-org-bb-export "* dummy ** dummy *** TOPIC ") "[b][u]# dummy[/u][/b] [b][u]== dummy[/u][/b] [b][u]+++ TOPIC[/u][/b] "))) (ert-deftest test-org-bb/export-headline-lv4 () (should (equal (test-org-bb-export "* dummy ** dummy *** dummy **** TOPIC ") "[b][u]# dummy[/u][/b] [b][u]== dummy[/u][/b] [b][u]+++ dummy[/u][/b] [b][u]:::: TOPIC[/u][/b] "))) (ert-deftest test-org-bb/export-headline-lv5 () (should (equal (test-org-bb-export "* dummy ** dummy *** dummy **** dummy ***** TOPIC ") "[b][u]# dummy[/u][/b] [b][u]== dummy[/u][/b] [b][u]+++ dummy[/u][/b] [b][u]:::: dummy[/u][/b] [b][u]----- TOPIC[/u][/b] "))) (ert-deftest test-org-bb/export-italic () (should (equal (test-org-bb-export "foo /BAR/ baz ") "foo [i]BAR[/i] baz "))) (ert-deftest test-org-bb/export-line-break () (should (equal (test-org-bb-export "foo\\\\ bar ") "foo[br]_[/br] bar "))) (ert-deftest test-org-bb/export-link-about () (should (equal (test-org-bb-export "[[about:config][bar]] ") "[url=about:config]bar[/url] "))) (ert-deftest test-org-bb/export-link-empty () (should (equal (test-org-bb-export "http://example.com/ ") "[url=http://example.com/]http://example.com/[/url] "))) (ert-deftest test-org-bb/export-link-encode-url-only-once () (should (equal (test-org-bb-export "[[http://foo/%20bar][baz]] ") "[url=http://foo/%20bar]baz[/url] "))) (ert-deftest test-org-bb/export-link-encode-url () (should (equal (test-org-bb-export "[[http://foo/ bar][baz]] ") "[url=http://foo/%20bar]baz[/url] "))) (ert-deftest test-org-bb/export-link-http () (should (equal (test-org-bb-export "[[http://foo/][bar]] ") "[url=http://foo/]bar[/url] "))) (ert-deftest test-org-bb/export-link-https () (should (equal (test-org-bb-export "[[https://foo/][bar]] ") "[url=https://foo/]bar[/url] "))) (ert-deftest test-org-bb/export-multiline-paragraph () (should (equal (test-org-bb-export "foo bar ") "foo bar "))) (ert-deftest test-org-bb/export-multiple-paragraphs () (should (equal (test-org-bb-export "foo bar ") "foo bar "))) (ert-deftest test-org-bb/export-plain-list-descriptive () (should (equal (test-org-bb-export "- foo :: pokey - bar :: hokey ") "[list] [*][i]foo:[/i] pokey [*][i]bar:[/i] hokey [/list] "))) (ert-deftest test-org-bb/export-plain-list-ordered () (should (equal (test-org-bb-export "1. foo 2. bar ") "[list=1] [*]foo [*]bar [/list] "))) (ert-deftest test-org-bb/export-plain-list-unordered () (should (equal (test-org-bb-export "- foo - bar ") "[list] [*]foo [*]bar [/list] "))) (ert-deftest test-org-bb/export-quote-block () (should (equal (test-org-bb-export "#+BEGIN_QUOTE Somebody said this. #+END_QUOTE ") "[quote] Somebody said this. [/quote] "))) (ert-deftest test-org-bb/export-single-paragraph () (should (equal (test-org-bb-export "foo ") "foo "))) (ert-deftest test-org-bb/export-strike-through () (should (equal (test-org-bb-export "foo +BAR+ baz ") "foo [s]BAR[/s] baz "))) (ert-deftest test-org-bb/export-underline () (should (equal (test-org-bb-export "foo _BAR_ baz ") "foo [u]BAR[/u] baz "))) (ert-deftest test-org-bb/export-verbatim () (should (equal (test-org-bb-export "foo =BAR= baz ") "foo [font=monospace]BAR[/font] baz "))) (provide 'test-ox-bb) ;;; test-ox-bb.el ends here