"Fossies" - the Fresh Open Source Software Archive

Member "gnucash-3.7/gnucash/report/standard-reports/test/test-balsheet-pnl.scm" (7 Sep 2019, 23406 Bytes) of package /linux/misc/gnucash-3.7.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test-balsheet-pnl.scm": 3.6_vs_3.7.

    1 (use-modules (gnucash gnc-module))
    2 (gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0))
    3 (use-modules (gnucash engine test test-extras))
    4 (use-modules (gnucash report standard-reports balance-sheet))
    5 (use-modules (gnucash report standard-reports income-statement))
    6 (use-modules (gnucash report stylesheets))
    7 (use-modules (gnucash report report-system))
    8 (use-modules (gnucash report report-system test test-extras))
    9 (use-modules (srfi srfi-64))
   10 (use-modules (gnucash engine test srfi64-extras))
   11 (use-modules (sxml simple))
   12 (use-modules (sxml xpath))
   13 
   14 ;; This is implementation testing for Balance Sheet and Profit&Loss.
   15 
   16 (define balance-sheet-uuid "c4173ac99b2b448289bf4d11c731af13")
   17 (define pnl-uuid "0b81a3bdfd504aff849ec2e8630524bc")
   18 
   19 ;; Explicitly set locale to make the report output predictable
   20 (setlocale LC_ALL "C")
   21 
   22 (define (run-test)
   23   (test-runner-factory gnc:test-runner)
   24   (test-begin "balsheet and profit&loss")
   25   (null-test)
   26   (balsheet-pnl-tests)
   27   (test-end "balsheet and profit&loss"))
   28 
   29 (define (options->sxml uuid options test-title)
   30   (gnc:options->sxml uuid options "test-balsheet-pnl" test-title))
   31 
   32 (define (set-option! options section name value)
   33   (let ((option (gnc:lookup-option options section name)))
   34     (if option
   35         (gnc:option-set-value option value)
   36         (test-assert (format #f "wrong-option ~a ~a" section name) #f))))
   37 
   38 (define (mnemonic->commodity sym)
   39   (gnc-commodity-table-lookup
   40    (gnc-commodity-table-get-table (gnc-get-current-book))
   41    (gnc-commodity-get-namespace (gnc-default-report-currency))
   42    sym))
   43 
   44 (define USD (gnc-default-report-currency)) ;default currency should be USD because LC_ALL="C"
   45 (define GBP (mnemonic->commodity "GBP"))
   46 (define FUNDS (gnc-commodity-new (gnc-get-current-book)
   47                                  "Funds"            ;fullname
   48                                  "FUNDS"            ;namespace
   49                                  "FUNDS"            ;mnemonic
   50                                  "FUNDS"            ;cusip
   51                                  1000               ;fraction
   52                                  ))
   53 (gnc-commodity-set-user-symbol GBP "#")
   54 
   55 (define structure
   56   (list "Root" (list (cons 'type ACCT-TYPE-ASSET)
   57                      (cons 'commodity USD))
   58         (list "Asset"
   59               (list "Bank1"
   60                     (list "Savings")
   61                     (list "Bonds")
   62                     (list "Empty")
   63                     (list "Current"))
   64               (list "House")
   65               (list "ForeignBank" (list (cons 'commodity GBP))
   66                     (list "ForeignSavings"))
   67               (list "Broker"
   68                     (list "Funds" (list (cons 'type ACCT-TYPE-STOCK)
   69                                         (cons 'commodity FUNDS)))))
   70         (list "Liability" (list (cons 'type ACCT-TYPE-LIABILITY))
   71               (list "Bank2"
   72                     (list "Loan")
   73                     (list "CreditCard")))
   74         (list "Equity" (list (cons 'type ACCT-TYPE-EQUITY)))
   75         (list "Income" (list (cons 'type ACCT-TYPE-INCOME))
   76               (list "Income-GBP" (list (cons 'commodity GBP))))))
   77 
   78 (define (null-test)
   79   ;; This null-test tests for the presence of report.
   80   (let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
   81     (test-assert "null-test" (options->sxml balance-sheet-uuid balance-sheet-options "null-test"))))
   82 
   83 (define (balsheet-pnl-tests)
   84   ;; This function will perform implementation testing on the transaction report.
   85   (let* ((env (create-test-env))
   86          (account-alist (env-create-account-structure-alist env structure))
   87          (bank1savings (cdr (assoc "Savings" account-alist)))
   88          (bank1bonds (cdr (assoc "Bonds" account-alist)))
   89          (bank1current (cdr (assoc "Current" account-alist)))
   90          (house (cdr (assoc "House" account-alist)))
   91          (foreignsavings (cdr (assoc "ForeignSavings" account-alist)))
   92          (broker (cdr (assoc "Broker" account-alist)))
   93          (brokerfunds (cdr (assoc "Funds" account-alist)))
   94          (bank2loan (cdr (assoc "Loan" account-alist)))
   95          (bank2creditcard (cdr (assoc "CreditCard" account-alist)))
   96          (equity (cdr (assoc "Equity" account-alist)))
   97          (income (cdr (assoc "Income" account-alist)))
   98          (income-GBP (cdr (assoc "Income-GBP" account-alist)))
   99          (YEAR (gnc:time64-get-year (gnc:get-today))))
  100 
  101     (define (default-balsheet-testing-options)
  102       (let ((balance-sheet-options (gnc:make-report-options balance-sheet-uuid)))
  103         (set-option! balance-sheet-options "General" "Balance Sheet Date" (cons 'absolute (gnc-dmy2time64 1 1 1971)))
  104         (set-option! balance-sheet-options "Accounts" "Levels of Subaccounts" 'all)
  105         (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
  106         balance-sheet-options))
  107 
  108     (define (default-pnl-testing-options)
  109       (let ((pnl-options (gnc:make-report-options pnl-uuid)))
  110         (set-option! pnl-options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 1 1 1980)))
  111         (set-option! pnl-options "General" "End Date" (cons 'absolute (gnc-dmy2time64 1 1 1981)))
  112         (set-option! pnl-options "Accounts" "Levels of Subaccounts" 'all)
  113         (set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
  114         pnl-options))
  115 
  116     ;; $100 in Savings account
  117     (env-transfer env 01 01 1970 equity bank1savings 100)
  118     ;; $2000 in Bonds
  119     (env-transfer env 01 01 1970 equity bank1bonds 2000)
  120     ;; $500 in Current Acc
  121     (env-transfer env 01 01 1970 equity bank1current 9000)
  122     ;; $100,000 in house
  123     (env-transfer env 01 01 1970 equity house 100000)
  124 
  125     ;; pre-existing GBPs
  126     (env-transfer-foreign env 01 01 1970 bank1current foreignsavings  130  100 #:description "buy 100GBP at $1.30")
  127     (env-transfer-foreign env 01 02 1970 bank1current foreignsavings  140  100 #:description "buy 100GBP at $1.40")
  128     (env-transfer-foreign env 15 02 1970 bank1current foreignsavings -142 -100 #:description "sell 100GBP at $1.42")
  129     (env-transfer-foreign env 01 03 1970 bank1current foreignsavings  150  100 #:description "buy 100GBP at $1.50")
  130     (env-transfer-foreign env 01 04 1970 bank1current foreignsavings  155  100 #:description "buy 100GBP at $1.55")
  131     (env-transfer-foreign env 15 04 1970 bank1current foreignsavings -157 -100 #:description "sell 100GBP at $1.57")
  132     (env-transfer-foreign env 01 05 1970 bank1current foreignsavings -160 -100 #:description "sell 100GBP at $1.60")
  133     (env-transfer-foreign env 01 06 1970 bank1current foreignsavings  155  100 #:description "buy 100GBP at $1.55")
  134     (env-transfer-foreign env 01 07 1970 bank1current foreignsavings -145 -100 #:description "sell 100GBP at $1.45")
  135     (env-transfer-foreign env 01 08 1970 bank1current foreignsavings  165  100 #:description "buy 100GBP at $1.65")
  136 
  137     ;; broker has $2000
  138     (env-transfer env 01 01 1970 equity broker 2000)
  139 
  140     ;; existing FUNDs = 200 USD on 01/01/1970
  141     (env-transfer-foreign env 01 01 1970 bank1current brokerfunds  2000  10 #:description "buy 10FUND at $200")
  142     (env-transfer-foreign env 01 02 1970 bank1current brokerfunds  2100  10 #:description "buy 10FUND at $210")
  143     (env-transfer-foreign env 01 03 1970 bank1current brokerfunds  2250  10 #:description "buy 10FUND at $225")
  144     (env-transfer-foreign env 01 04 1970 bank1current brokerfunds  2440  10 #:description "buy 10FUND at $244")
  145     (env-transfer-foreign env 01 05 1970 bank1current brokerfunds -2640 -10 #:description "sell 10FUND at $264")
  146     (env-transfer-foreign env 01 06 1970 bank1current brokerfunds -2550 -10 #:description "sell 10FUND at $255")
  147     (env-transfer-foreign env 01 07 1970 bank1current brokerfunds  2500  10 #:description "buy 10FUND at $250")
  148 
  149     ;; $9000 loan
  150     (env-transfer env 01 01 1970 equity bank2loan -9000)
  151 
  152     ;; $500 on creditcard debt
  153     (env-transfer env 01 01 1970 equity bank2creditcard -500)
  154 
  155     ;; further prices into pricedb
  156     ;; GBP = 1.50 to 1.90 USD
  157     (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1971) 15/10)
  158     (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1972) 16/10)
  159     (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1973) 17/10)
  160     (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1974) 18/10)
  161     (gnc-pricedb-create USD GBP (gnc-dmy2time64 1 1 1975) 19/10)
  162     ;; FUND = 300 to 500 USD
  163     (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1971) 300)
  164     (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1972) 350)
  165     (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1973) 400)
  166     (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1974) 450)
  167     (gnc-pricedb-create USD FUNDS (gnc-dmy2time64 1 1 1975) 500)
  168 
  169     ;; a couple INCOME transactions, a decade later
  170     (env-transfer env 01 01 1980 income bank1current 250)
  171     (env-transfer env 01 01 1980 income-GBP foreignsavings 500)
  172     (env-transfer-foreign env 01 02 1980 income-GBP bank1current 100 170 #:description "earn 100GBP into $170")
  173 
  174     ;; Finally we can begin testing balsheet
  175     (display "\n\n balsheet tests\n\n")
  176     (let* ((balance-sheet-options (default-balsheet-testing-options))
  177            (sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-default")))
  178       (test-equal "total assets = $116,009"
  179         (list "$116,009.00")
  180         (sxml->table-row-col sxml 1 15 6))
  181       (test-equal "total liabilities = $9,500.00"
  182         (list "$9,500.00")
  183         (sxml->table-row-col sxml 1 23 6))
  184       (test-equal "total equity  = $106,509.00"
  185         (list "$106,509.00")
  186         (sxml->table-row-col sxml 1 28 6))
  187 
  188       (set-option! balance-sheet-options "Commodities" "Price Source" 'weighted-average)
  189       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-weighted-average")))
  190         (test-equal "weighted average assets = $114,071.66"
  191           (list "$114,071.66")
  192           (sxml->table-row-col sxml 1 15 6)))
  193 
  194       (set-option! balance-sheet-options "Commodities" "Price Source" 'average-cost)
  195       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-average-cost")))
  196         (test-equal "average-cost assets = $113,100"
  197           (list "$113,100.00")
  198           (sxml->table-row-col sxml 1 15 6)))
  199 
  200       (set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-nearest)
  201       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-nearest")))
  202         (test-equal "pricedb-nearest assets = $116,009"
  203           (list "$116,009.00")
  204           (sxml->table-row-col sxml 1 15 6)))
  205 
  206       (set-option! balance-sheet-options "Commodities" "Price Source" 'pricedb-latest)
  207       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-pricedb-latest")))
  208         (test-equal "pricedb-latest assets = $122,049"
  209           (list "$122,049.00")
  210           (sxml->table-row-col sxml 1 15 6)))
  211 
  212       ;; set multilevel subtotal style
  213       ;; verifies amount in EVERY line of the report.
  214       (set-option! balance-sheet-options "Display" "Parent account balances" 'immediate-bal)
  215       (set-option! balance-sheet-options "Display" "Parent account subtotals" 't)
  216       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-multilevel")))
  217         (test-equal "multilevel. root = $0.00"
  218           (list "$0.00")
  219           (sxml->table-row-col sxml 1 3 6))
  220         (test-equal "multilevel. assets = $0.00"
  221           (list "$0.00")
  222           (sxml->table-row-col sxml 1 4 5))
  223         (test-equal "multilevel. bank1 = $0.00"
  224           (list "$0.00")
  225           (sxml->table-row-col sxml 1 5 4))
  226         (test-equal "multilevel. bonds = $2,000.00"
  227           (list "$2,000.00")
  228           (sxml->table-row-col sxml 1 6 3))
  229         (test-equal "multilevel. current = $2609.00"
  230           (list "$2,609.00")
  231           (sxml->table-row-col sxml 1 7 3))
  232         (test-equal "multilevel. empty = $0.00"
  233           (list "$0.00")
  234           (sxml->table-row-col sxml 1 8 3))
  235         (test-equal "multilevel. savings = $100.00"
  236           (list "$100.00")
  237           (sxml->table-row-col sxml 1 9 3))
  238         (test-equal "multilevel. total bank1 = $4709"
  239           (list "$4,709.00")
  240           (sxml->table-row-col sxml 1 10 4))
  241         (test-equal "multilevel. broker = $2,000.00"
  242           (list "$2,000.00")
  243           (sxml->table-row-col sxml 1 11 4))
  244         (test-equal "multilevel. funds = $15,000.00"
  245           (list "30 FUNDS" "$15,000.00" "$15,000.00")
  246           (sxml->table-row-col sxml 1 12 3))
  247         (test-equal "multilevel. total broker = $17,000.00"
  248           (list "$17,000.00")
  249           (sxml->table-row-col sxml 1 13 4))
  250         (test-equal "multilevel. foreign = $0.00"
  251           (list "$0.00")
  252           (sxml->table-row-col sxml 1 14 4))
  253         (test-equal "multilevel. foreignsavings = #200.00 = $340"
  254           (list "#200.00" "$340.00" "$340.00")
  255           (sxml->table-row-col sxml 1 15 3))
  256         (test-equal "multilevel. total foreign = $340"
  257           (list "$340.00")
  258           (sxml->table-row-col sxml 1 16 4))
  259         (test-equal "multilevel. house = $100,000"
  260           (list "$100,000.00")
  261           (sxml->table-row-col sxml 1 17 4))
  262         (test-equal "multilevel. total asset = $122,049"
  263           (list "$122,049.00")
  264           (sxml->table-row-col sxml 1 18 5))
  265         (test-equal "multilevel. total root = $122,049"
  266           (list "$122,049.00")
  267           (sxml->table-row-col sxml 1 19 6))
  268         (test-equal "multilevel. total assets = $122,049"
  269           (list "$122,049.00")
  270           (sxml->table-row-col sxml 1 20 6)))
  271 
  272       ;; set recursive-subtotal subtotal style
  273       (set-option! balance-sheet-options "Display" "Parent account balances" 'recursive-bal)
  274       (set-option! balance-sheet-options "Display" "Parent account subtotals" 'f)
  275       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-recursive")))
  276         (test-equal "recursive. root = $760+15000+104600"
  277           (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
  278           (sxml->table-row-col sxml 1 3 6))
  279         (test-equal "recursive. assets = $760+15000+104600"
  280           (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
  281           (sxml->table-row-col sxml 1 4 5))
  282         (test-equal "recursive. bank1 = $4,709.00"
  283           (list "$4,709.00")
  284           (sxml->table-row-col sxml 1 5 4))
  285         (test-equal "recursive. bonds = $2,000.00"
  286           (list "$2,000.00")
  287           (sxml->table-row-col sxml 1 6 3))
  288         (test-equal "recursive. current = $2609.00"
  289           (list "$2,609.00")
  290           (sxml->table-row-col sxml 1 7 3))
  291         (test-equal "recursive. empty = $0.00"
  292           (list "$0.00")
  293           (sxml->table-row-col sxml 1 8 3))
  294         (test-equal "recursive. savings = $100.00"
  295           (list "$100.00")
  296           (sxml->table-row-col sxml 1 9 3))
  297         (test-equal "recursive. broker = $15000+2000.00"
  298           (list "30 FUNDS" "$15,000.00" "$2,000.00" "$2,000.00")
  299           (sxml->table-row-col sxml 1 10 4))
  300         (test-equal "recursive. funds = $15,000.00"
  301           (list "30 FUNDS" "$15,000.00" "$15,000.00")
  302           (sxml->table-row-col sxml 1 11 3))
  303         (test-equal "recursive. foreign = $340.00"
  304           (list "#200.00" "$340.00")
  305           (sxml->table-row-col sxml 1 12 4))
  306         (test-equal "recursive. foreignsavings = #200.00 = $340"
  307           (list "#200.00" "$340.00" "$340.00")
  308           (sxml->table-row-col sxml 1 13 3))
  309         (test-equal "recursive. house = $100,000"
  310           (list "$100,000.00")
  311           (sxml->table-row-col sxml 1 14 4))
  312         (test-equal "recursive. total assets = $122,049.00"
  313           (list "$122,049.00")
  314           (sxml->table-row-col sxml 1 15 6)))
  315 
  316       (set-option! balance-sheet-options "Commodities" "Show Foreign Currencies" #f)
  317       (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #f)
  318       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-disable show-fcur show-rates")))
  319         (test-equal "show-fcur disabled"
  320           (list "$122,049.00")
  321           (sxml->table-row-col sxml 1 3 6))
  322         (test-equal "show-rates disabled"
  323           '()
  324           (sxml->table-row-col sxml 2 #f #f)))
  325 
  326       (set-option! balance-sheet-options "Commodities" "Show Foreign Currencies" #t)
  327       (set-option! balance-sheet-options "Commodities" "Show Exchange Rates" #t)
  328       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-enable show-fcur show-rates")))
  329         (test-equal "show-fcur enabled"
  330           (list "#200.00" "$340.00" "30 FUNDS" "$15,000.00" "$106,709.00" "$106,709.00")
  331           (sxml->table-row-col sxml 1 3 6))
  332         (test-equal "show-rates enabled"
  333           (list "1 FUNDS" "$500.00" "#1.00" "$1.70")
  334           (sxml->table-row-col sxml 2 #f #f)))
  335 
  336       ;;make-multilevel
  337       (set-option! balance-sheet-options "Display" "Parent account balances" 'immediate-bal)
  338       (set-option! balance-sheet-options "Display" "Parent account subtotals" 't)
  339 
  340       (set-option! balance-sheet-options "Display" "Omit zero balance figures" #t)
  341       (set-option! balance-sheet-options "Display" "Include accounts with zero total balances" #f)
  342       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-incl-zb-accts=#f omit-zb-bals=#t")))
  343         (test-equal "omit-zb-bals=#t"
  344           '()
  345           (sxml->table-row-col sxml 1 3 5))
  346         (test-equal "incl-zb-accts=#f"
  347           '("Savings" "$100.00")        ;i.e.skips "Empty" account with $0.00
  348           (sxml->table-row-col sxml 1 8 #f)))
  349 
  350       (set-option! balance-sheet-options "Display" "Omit zero balance figures" #f)
  351       (set-option! balance-sheet-options "Display" "Include accounts with zero total balances" #t)
  352       (let ((sxml (options->sxml balance-sheet-uuid balance-sheet-options "balsheet-incl-zb-accts=#t omit-zb-bals=#f")))
  353         (test-equal "omit-zb-bals=#f"
  354           (list "$0.00")
  355           (sxml->table-row-col sxml 1 3 6))
  356         (test-equal "incl-zb-accts=#t"
  357           '("Empty" "$0.00")
  358           (sxml->table-row-col sxml 1 8 #f)))
  359       )
  360 
  361     (display "\n\n pnl tests\n\n")
  362     (let* ((pnl-options (default-pnl-testing-options))
  363            (sxml (options->sxml pnl-uuid pnl-options "pnl-default")))
  364       (test-equal "total revenue  = $1,270.00"
  365         (list "$1,270.00")
  366         ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  367          sxml))
  368       (test-equal "total expenses  = $0.00"
  369         (list "$0.00")
  370         ((sxpath '(// table // (tr 2) // table // (tr 3) // (td 6) // *text*))
  371          sxml))
  372 
  373       (set-option! pnl-options "Commodities" "Price Source" 'weighted-average)
  374       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-weighted-average")))
  375         (test-equal "weighted average revenue = $1160.36"
  376           (list "$1,160.36")
  377           ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  378            sxml)))
  379 
  380       (set-option! pnl-options "Commodities" "Price Source" 'average-cost)
  381       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-average-cost")))
  382         (test-equal "average-cost revenue = $976"
  383           (list "$976.00")
  384           ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  385            sxml)))
  386 
  387       (set-option! pnl-options "Commodities" "Price Source" 'pricedb-nearest)
  388       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-pricedb-nearest")))
  389         (test-equal "pricedb-nearest revenue = $1270"
  390           (list "$1,270.00")
  391           ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  392            sxml)))
  393 
  394       (set-option! pnl-options "Commodities" "Price Source" 'pricedb-latest)
  395       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-pricedb-latest")))
  396         (test-equal "pricedb-latest revenue = $1270"
  397           (list "$1,270.00")
  398           ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  399            sxml)))
  400 
  401       ;; set multilevel subtotal style
  402       ;; verifies amount in EVERY line of the report.
  403       (set-option! pnl-options "Display" "Parent account balances" 'immediate-bal)
  404       (set-option! pnl-options "Display" "Parent account subtotals" 't)
  405       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-multilevel")))
  406         (test-equal "multilevel. income = -$250.00"
  407           (list "-$250.00")
  408           ((sxpath '(// table // (tr 1) // table // (tr 3) // (td 6) // *text*))
  409            sxml))
  410         (test-equal "multilevel. income-GBP = -#600"
  411           (list "-#600.00" "-$1,020.00")
  412           ((sxpath '(// table // (tr 1) // table // (tr 4) // (td 5) // *text*))
  413            sxml))
  414         (test-equal "multilevel. total income = -$1,270.00"
  415           (list "-$1,270.00")
  416           ((sxpath '(// table // (tr 1) // table // (tr 5) // (td 6) // *text*))
  417            sxml))
  418         (test-equal "multilevel. total revenue = $1,270.00"
  419           (list "$1,270.00")
  420           ((sxpath '(// table // (tr 1) // table // (tr 6) // (td 6) // *text*))
  421            sxml))
  422         (test-equal "multilevel. expenses = $0.00"
  423           (list "$0.00")
  424           ((sxpath '(// table // (tr 2) // table // (tr 3) // (td 6) // *text*))
  425            sxml))
  426         (test-equal "multilevel. net-income = $1,270"
  427           (list "$1,270.00")
  428           ((sxpath '(// table // (tr 2) // table // (tr 4) // (td 6) // *text*))
  429            sxml)))
  430 
  431       ;; set recursive-subtotal subtotal style
  432       (set-option! pnl-options "Display" "Parent account balances" 'recursive-bal)
  433       (set-option! pnl-options "Display" "Parent account subtotals" 'f)
  434       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-recursive")))
  435         (test-equal "recursive. income = $1020+250"
  436           (list "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00" "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00")
  437           (sxml->table-row-col sxml 1 3 6))
  438         (test-equal "recursive. income-gbp = $1020"
  439           (list "-#600.00" "-$1,020.00" "-#600.00" "-$1,020.00")
  440           (sxml->table-row-col sxml 1 4 5))
  441         (test-equal "recursive. total revenue = $1270"
  442           (list "$1,270.00" "$1,270.00")
  443           (sxml->table-row-col sxml 1 5 6)))
  444 
  445       (set-option! pnl-options "Commodities" "Show Foreign Currencies" #f)
  446       (set-option! pnl-options "Commodities" "Show Exchange Rates" #f)
  447       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-disable show-fcur show-rates")))
  448         (test-equal "show-fcur disabled"
  449           (list "-$1,270.00" "$0.00" "-$1,270.00" "$0.00")
  450           (sxml->table-row-col sxml 1 3 6))
  451         (test-equal "show-rates disabled"
  452           '()
  453           (sxml->table-row-col sxml 2 #f #f)))
  454 
  455       (set-option! pnl-options "Commodities" "Show Foreign Currencies" #t)
  456       (set-option! pnl-options "Commodities" "Show Exchange Rates" #t)
  457       (let ((sxml (options->sxml pnl-uuid pnl-options "pnl-enable show-fcur show-rates")))
  458         (test-equal "show-fcur enabled"
  459           (list "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00" "-#600.00" "-$1,020.00" "-$250.00" "-$250.00" "$0.00")
  460           (sxml->table-row-col sxml 1 3 6))
  461         (test-equal "show-rates enabled"
  462           (list "#1.00" "$1.70")
  463           (sxml->table-row-col sxml 2 #f #f)))
  464 
  465       ;;make-multilevel
  466       (set-option! pnl-options "Display" "Parent account balances" 'immediate-bal)
  467       (set-option! pnl-options "Display" "Parent account subtotals" 't)
  468       )))