edward

An extensible POSIX-compatible implementation of the ed(1) text editor

git clone https://git.8pit.net/edward.git

  1(import (edward ed addr))
  2
  3(test-parse (addr->range '((current-line) ())) parse-addrs ".")
  4(test-parse (addr->range '((last-line) ()))    parse-addrs "$")
  5
  6(define (test-addr-error desc expected input)
  7  (test-parse-error desc expected parse-addrs input))
  8
  9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 10
 11(test-group "parse nth line"
 12  (test-parse (addr->range '((nth-line . 42) ())) parse-addrs "42")
 13  (test-addr-error "character in address" "unknown address format" "4x2")
 14  (test-addr-error "chained address without seperator" "unknown address format" "42."))
 15
 16(test-group "parse mark"
 17  (test-parse (addr->range '((marked-line . #\x) ())) parse-addrs "'x")
 18  (test-addr-error "multi-character mark" "invalid mark: expected lowercase character" "'FOO")
 19  (test-addr-error "mark with digit" "invalid mark: expected lowercase character" "'F23"))
 20
 21(test-group "parse-forward-bre"
 22  (test-parse (addr->range '((regex-forward . "foo") ())) parse-addrs "/foo/")
 23  (test-parse (addr->range '((regex-forward . "") ())) parse-addrs "//")
 24  (test-parse (addr->range '((regex-forward . "foo/bar") ())) parse-addrs "/foo\\/bar/")
 25  (test-parse (addr->range '((regex-forward . "f.*") ())) parse-addrs "/f.*")
 26  (test-parse (addr->range '((regex-forward . "f??") ())) parse-addrs "/f??/"))
 27
 28(test-group "parse-backward-bre"
 29  (test-parse
 30    (addr->range '((regex-backward . "foo") ()))
 31    parse-addrs
 32    "?foo?")
 33  (test-parse
 34    (addr->range '((regex-backward . "") ()))
 35    parse-addrs
 36    "??")
 37  (test-parse
 38    (addr->range '((regex-backward . "foo?bar") ()))
 39    parse-addrs
 40    "?foo\\?bar?")
 41  (test-parse
 42    (addr->range '((regex-backward . "fo\\([a-z]\\)") ()))
 43    parse-addrs
 44    "?fo\\([a-z]\\)?"))
 45
 46(test-group "parse-relative"
 47  (test-parse (addr->range '((relative . 5) ()))   parse-addrs "+5")
 48  (test-parse (addr->range '((relative . -42) ())) parse-addrs "-42")
 49  (test-parse (addr->range '((relative . 1) ()))   parse-addrs "+")
 50  (test-parse (addr->range '((relative . -1) ()))  parse-addrs "-"))
 51
 52(test-group "parse offsets"
 53  (test-parse (addr->range '((nth-line . 2342) (1))) parse-addrs "2342 +1")
 54  (test-parse (addr->range '((relative . 5) (1 2 3))) parse-addrs "+5 1 2 3")
 55  (test-parse (addr->range '((marked-line . #\f) (23 42))) parse-addrs "'f 23    42")
 56  (test-parse (addr->range '((regex-forward . "foo") (-1 2 -3))) parse-addrs "/foo/ -1 2 -3")
 57  (test-parse (addr->range '((regex-backward . "bar") (+2342))) parse-addrs "?bar?+2342")
 58  (test-parse (addr->range '((nth-line . 23) (-5 +5))) parse-addrs "23-5+5")
 59  (test-addr-error "offset with char" "unknown address format" "23+5-f"))
 60
 61(test-group "address ranges"
 62  (test-parse
 63    (list #\,)
 64    parse-addrs ",")
 65
 66  (test-parse
 67    (list
 68      #\,
 69      (make-addr '(nth-line . 2342)))
 70    parse-addrs ",2342")
 71
 72  (test-parse
 73    (list
 74      (make-addr '(nth-line . 4223))
 75      #\,)
 76    parse-addrs "4223,")
 77
 78  (test-parse
 79    (list #\;)
 80    parse-addrs ";")
 81
 82  (test-parse
 83    (list
 84      #\;
 85      (make-addr '(nth-line . 9001)))
 86    parse-addrs ";9001")
 87
 88  (test-parse
 89    (list
 90      (make-addr '(nth-line . 42))
 91      #\;)
 92    parse-addrs "42;")
 93
 94  (test-parse
 95    (make-range
 96      (make-addr '(nth-line . 2342))
 97      #\;
 98      (make-addr '(nth-line . 4223)))
 99    parse-addrs "2342;4223")
100
101  (test-parse
102    (make-range
103      (make-addr '(nth-line . 9000))
104      #\,
105      (make-addr '(nth-line . 9001)))
106    parse-addrs "9000,9001")
107
108  (test-parse
109    (make-range
110      (make-addr '(nth-line . 23))
111      #\,
112      (make-addr '(nth-line . 42)))
113    parse-addrs "23    ,   42")
114
115  (test-parse
116    (make-range
117      (make-addr '(nth-line . 23) '(23 42))
118      #\,
119      (make-addr '(nth-line . 42) '(42 23)))
120    parse-addrs "23  +23 +42,  42 +42   +23"))
121
122(test-group "multiple addresses"
123  (test-parse
124    (list
125      (make-addr '(nth-line . 1))
126      #\,
127      (make-addr '(nth-line . 2))
128      #\,
129      (make-addr '(nth-line . 3)))
130    parse-addrs "1,2,3")
131
132  (test-parse
133    (list #\, #\,)
134    parse-addrs ",,")
135
136  (test-parse
137    (list #\, #\;)
138    parse-addrs ",;")
139
140  (test-parse
141    (list
142      (make-addr '(nth-line . 7))
143      #\,
144      (make-addr '(nth-line . 5))
145      #\,)
146    parse-addrs "7,5,"))