summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-02 11:51:06 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-02 11:51:06 -0800
commit0f6603d5716d285a89a66d88200830c26917e89d (patch)
treed8d0f226e9aebc53fb97615af19280d6c1eed171
parent0d3fc60bfb0d85e4c79550caec0f65976a9692f4 (diff)
downloadtxr-0f6603d5716d285a89a66d88200830c26917e89d.tar.gz
txr-0f6603d5716d285a89a66d88200830c26917e89d.tar.bz2
txr-0f6603d5716d285a89a66d88200830c26917e89d.zip
This test case would have caught the prior regression.
* Makefile (TXR_ARGS): Defined for new test case. * tests/010/align-columns.dat: New file. * tests/010/align-columns.expected: New file. * tests/010/align-columns.txr: New file.
-rw-r--r--ChangeLog12
-rw-r--r--Makefile1
-rw-r--r--tests/010/align-columns.dat6
-rw-r--r--tests/010/align-columns.expected18
-rw-r--r--tests/010/align-columns.txr30
5 files changed, 67 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 21fca013..f9bcb661 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2012-02-02 Kaz Kylheku <kaz@kylheku.com>
+ This test case would have caught the prior regression.
+
+ * Makefile (TXR_ARGS): Defined for new test case.
+
+ * tests/010/align-columns.dat: New file.
+
+ * tests/010/align-columns.expected: New file.
+
+ * tests/010/align-columns.txr: New file.
+
+2012-02-02 Kaz Kylheku <kaz@kylheku.com>
+
* match.c (format_field): Regression. Was not handling modifiers
which are compound expression (e.g. computed field widths).
This was broken by the first commit of 2012-01-26.
diff --git a/Makefile b/Makefile
index 52e42d47..c8244ea4 100644
--- a/Makefile
+++ b/Makefile
@@ -111,6 +111,7 @@ tests/008/students.ok: TXR_ARGS := $(top_srcdir)/tests/008/students.xml
tests/008/soundex.ok: TXR_ARGS := soundex sowndex lloyd lee jackson robert
tests/009/json.ok: TXR_ARGS := $(top_srcdir)/tests/009/webapp.json
tests/009/json.ok: TXR_OPTS := -l
+tests/010/align-columns.ok: TXR_ARGS := $(top_srcdir)/tests/010/align-columns.dat
tests/002/%: TXR_SCRIPT_ON_CMDLINE := y
diff --git a/tests/010/align-columns.dat b/tests/010/align-columns.dat
new file mode 100644
index 00000000..3c722207
--- /dev/null
+++ b/tests/010/align-columns.dat
@@ -0,0 +1,6 @@
+Given$a$text$file$of$many$lines,$where$fields$within$a$line$
+are$delineated$by$a$single$'dollar'$character,$write$a$program
+that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
+column$are$separated$by$at$least$one$space.
+Further,$allow$for$each$word$in$a$column$to$be$either$left$
+justified,$right$justified,$or$center$justified$within$its$column.
diff --git a/tests/010/align-columns.expected b/tests/010/align-columns.expected
new file mode 100644
index 00000000..06e083c7
--- /dev/null
+++ b/tests/010/align-columns.expected
@@ -0,0 +1,18 @@
+Given a text file of many lines, where fields within a line
+are delineated by a single 'dollar' character, write a program
+that aligns each column of fields by ensuring that words in each
+column are separated by at least one space.
+Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
+ Given a text file of many lines, where fields within a line
+ are delineated by a single 'dollar' character, write a program
+ that aligns each column of fields by ensuring that words in each
+ column are separated by at least one space.
+ Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
+ Given a text file of many lines, where fields within a line
+ are delineated by a single 'dollar' character, write a program
+ that aligns each column of fields by ensuring that words in each
+ column are separated by at least one space.
+ Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
diff --git a/tests/010/align-columns.txr b/tests/010/align-columns.txr
new file mode 100644
index 00000000..8ae2b7f5
--- /dev/null
+++ b/tests/010/align-columns.txr
@@ -0,0 +1,30 @@
+@(collect)
+@ (coll)@{item /[^$]+/}@(end)
+@(end)
+@; nc = number of columns
+@; pi = padded items (data with row lengths equalized with empty strings)
+@; cw = vector of max column widths
+@; ce = center padding
+@(bind nc @(apply (fun max) (mapcar (fun length) item)))
+@(bind pi @(mapcar (lambda (row)
+ (append row (repeat '("") (- nc (length row)))))
+ item))
+@(bind cw @(vector-list
+ (mapcar (lambda (column)
+ (apply (fun max) (mapcar (fun length) column)))
+ ;; matrix transpose trick cols become rows:
+ (apply (fun mapcar) (cons (fun list) pi)))))
+@(bind ns "")
+@(output)
+@ (repeat)
+@ (rep :counter i)@{pi @[cw i]} @(end)
+@ (end)
+@ (repeat)
+@ (rep :counter i)@{pi @(- [cw i])} @(end)
+@ (end)
+@ (repeat)
+@ (rep :counter i)@\
+ @{ns @(trunc (- [cw i] (length pi)) 2)}@\
+ @{pi @(- [cw i] (trunc (- [cw i] (length pi)) 2))} @(end)
+@ (end)
+@(end)