1(import (edward ed cmd)2 (edward ed posix)3 (edward ed addr)4 (edward ed editor))56(define (test-parse-cmd desc expected input)7 (test desc expected8 (let* ((cmd-input (string-append input "\n"))9 (cmd-pair (%test-parse (parse-cmd) cmd-input))10 (cmd-addr (car cmd-pair))11 (cmd-args (cmd-args (cdr cmd-pair))))12 (append (list cmd-addr) cmd-args))))1314(define (test-cmd-error desc expected input)15 (test-parse-error desc expected (parse-cmd) input))1617;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1819(test-group "append command"20 (test-parse-cmd "no arguments"21 (list #f '()) "a\n.")22 (test-parse-cmd "preceeding whitespaces"23 (list #f '()) " a\n.")24 (test-parse-cmd "custom address without offset"25 (list26 (addr->range (make-addr '(nth-line . 2342)))27 '())28 "2342 a\n.")29 (test-parse-cmd "custom address with offset"30 (list31 (addr->range (make-addr '(last-line . ()) '(42)))32 '())33 "$+42 a\n."))3435(test-group "read command"36 (test-parse-cmd "no arguments"37 (list38 #f39 "") "r")4041 (test-parse-cmd "custom address"42 (list43 (addr->range (make-addr '(nth-line . 42)))44 "") "42r")4546 (test-parse-cmd "custom address and file"47 (list48 (addr->range (make-addr '(regex-backward . "foo") '(23 -42)))49 "foobar") "?foo? +23 -42 r foobar")5051 (test-cmd-error "filename w/o whitespace" "expected newline" "rfoo"))5253(test-group "write command"54 (test-parse-cmd "no arguments"55 (list56 #f57 "") "w")5859 (test-parse-cmd "custom address and offset, no whitespaces"60 (list61 (make-range62 (make-addr '(current-line))63 (make-addr '(current-line) '(10)))64 "foobar") ".,.+10w foobar")6566 (test-cmd-error "filename w/o whitespace" "expected newline" "wfoo"))6768(test-group "shell command"69 (test-parse-cmd "no replacements"70 (list #f (list "echo foobar")) "!echo foobar")71 (test-parse-cmd "command with replacement"72 (list #f (list "echo " 'current-file)) "!echo %")73 (test-parse-cmd "previous command"74 (list #f '(previous-command)) "!!")75 (test-parse-cmd "previous command appended"76 (list #f '(previous-command "foobar")) "!!foobar")77 (test-parse-cmd "previous command syntax not start"78 (list #f '("foobar !! barfoo")) "!foobar !! barfoo")79 (test-parse-cmd "escaped replacement"80 (list #f (list "echo %")) "!echo \\%")81 (test-parse-cmd "multiple replacements"82 (list #f (list "echo " 'current-file " " 'current-file)) "!echo % %"))8384(test-group "global command"85 (test-parse-cmd "single command no newline"86 (list87 (make-range88 (make-addr '(nth-line . 1))89 (make-addr '(last-line)))90 "foo"91 "p\n") "1,$g/foo/p")9293 (test-parse-cmd "empty command-list"94 (list95 #f96 "bar"97 "p\n") "g/bar/")9899 (test-parse-cmd "single trailing whitespace"100 (list101 (make-range102 (make-addr '(nth-line . 1))103 (make-addr '(last-line)))104 "foobar"105 "p \n") "1,$g/foobar/p ")106107 (test-parse-cmd "single command no newline"108 (list109 (make-range110 (make-addr '(nth-line . 23))111 (make-addr '(nth-line . 42)))112 "test"113 "p \np\n") "23,42g/test/p \\\np")114115 (test-cmd-error "missing regex" "expected regex" "1,$gp"))116117(test-group "miscellaneous"118 (test-parse-cmd "parse command with trailing blanks"119 (list (addr->range (make-addr '(nth-line . 2342)))120 '())121 "2342a \n.")122123 (test-parse-cmd "append command with suffixed printing command"124 (list (addr->range (make-addr '(nth-line . 42)))125 '())126 "42an\n.")127128 (test-cmd-error "unknown command character" "unknown command" "X")129 (test-cmd-error "quit command with argument" "expected newline" "Qn")130 (test-cmd-error "append command with argument" "expected newline" "a n"))