comparison tests/automated/mule-tests.el @ 5664:00fd55d635fb

Sync #'truncate-string-to-width with GNU, add tests for it. lisp/ChangeLog addition: 2012-05-12 Aidan Kehoe <kehoea@parhasard.net> * subr.el: * subr.el (truncate-string-to-width): Sync with GNU's version, use its test suite in mule-tests.el. tests/ChangeLog addition: 2012-05-12 Aidan Kehoe <kehoea@parhasard.net> * automated/mule-tests.el: Test #'truncate-string-to-width, thank you Colin Walters.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 12 May 2012 17:51:05 +0100
parents 391d809fa4e9
children 15041705c196
comparison
equal deleted inserted replaced
5663:0df4d95bd98a 5664:00fd55d635fb
806 "Test that default-process-coding-system can be nil." 806 "Test that default-process-coding-system can be nil."
807 (with-temp-buffer 807 (with-temp-buffer
808 (Assert (let (default-process-coding-system) 808 (Assert (let (default-process-coding-system)
809 (shell-command "cat </dev/null >/dev/null") 809 (shell-command "cat </dev/null >/dev/null")
810 t)))) 810 t))))
811 811 ;;; Test suite for truncate-string-to-width, from Colin Walters' tests in
812 ;;; mult-util.el in GNU.
813 (macrolet
814 ((test-truncate-string-to-width (&rest tests)
815 (let ((decode-any-string
816 ;; We can't store the East Asian characters directly in this
817 ;; file, since it needs to be read (but not executed) by
818 ;; non-Mule. Store them as UTF-8, decode them at
819 ;; macro-expansion time.
820 #'(lambda (object)
821 (if (stringp object)
822 (decode-coding-string object 'utf-8)
823 object))))
824 (cons
825 'progn
826 (mapcar
827 (function*
828 (lambda ((arguments . result))
829 `(Assert (equal (truncate-string-to-width
830 ,@(mapcar decode-any-string arguments))
831 ,(funcall decode-any-string result)))))
832 tests)))))
833 (test-truncate-string-to-width
834 (("" 0) . "")
835 (("x" 1) . "x")
836 (("xy" 1) . "x")
837 (("xy" 2 1) . "y")
838 (("xy" 0) . "")
839 (("xy" 3) . "xy")
840 (("\344\270\255" 0) . "")
841 (("\344\270\255" 1) . "")
842 (("\344\270\255" 2) . "\344\270\255")
843 (("\344\270\255" 1 nil ? ) . " ")
844 (("\344\270\255\346\226\207" 3 1 ? ) . " ")
845 (("x\344\270\255x" 2) . "x")
846 (("x\344\270\255x" 3) . "x\344\270\255")
847 (("x\344\270\255x" 3) . "x\344\270\255")
848 (("x\344\270\255x" 4 1) . "\344\270\255x")
849 (("kor\355\225\234e\352\270\200an" 8 1 ? ) .
850 "or\355\225\234e\352\270\200")
851 (("kor\355\225\234e\352\270\200an" 7 2 ? ) . "r\355\225\234e ")
852 (("" 0 nil nil "...") . "")
853 (("x" 3 nil nil "...") . "x")
854 (("\344\270\255" 3 nil nil "...") . "\344\270\255")
855 (("foo" 3 nil nil "...") . "foo")
856 (("foo" 2 nil nil "...") . "fo") ;; (old) XEmacs failure?
857 (("foobar" 6 0 nil "...") . "foobar")
858 (("foobarbaz" 6 nil nil "...") . "foo...")
859 (("foobarbaz" 7 2 nil "...") . "ob...")
860 (("foobarbaz" 9 3 nil "...") . "barbaz")
861 (("\343\201\223h\343\202\223e\343\201\253l\343\201\241l\343\201\257o" 15
862 1 ? t) . " h\343\202\223e\343\201\253l\343\201\241l\343\201\257o")
863 (("\343\201\223h\343\202\223e\343\201\253l\343\201\241l\343\201\257o" 14
864 1 ? t) . " h\343\202\223e\343\201\253l\343\201\241...")
865 (("x" 3 nil nil "\347\262\265\350\252\236") . "x")
866 (("\344\270\255" 2 nil nil "\347\262\265\350\252\236") . "\344\270\255")
867 ;; XEmacs used to error
868 (("\344\270\255" 1 nil ?x "\347\262\265\350\252\236") . "x")
869 (("\344\270\255\346\226\207" 3 nil ? "\347\262\265\350\252\236") .
870 ;; XEmacs used to error
871 "\344\270\255 ")
872 (("foobarbaz" 4 nil nil "\347\262\265\350\252\236") .
873 "\347\262\265\350\252\236")
874 (("foobarbaz" 5 nil nil "\347\262\265\350\252\236") .
875 "f\347\262\265\350\252\236")
876 (("foobarbaz" 6 nil nil "\347\262\265\350\252\236") .
877 "fo\347\262\265\350\252\236")
878 (("foobarbaz" 8 3 nil "\347\262\265\350\252\236") .
879 "b\347\262\265\350\252\236")
880 (("\343\201\223h\343\202\223e\343\201\253l\343\201\241l\343\201\257o" 14
881 4 ?x "\346\227\245\346\234\254\350\252\236") .
882 "xe\343\201\253\346\227\245\346\234\254\350\252\236")
883 (("\343\201\223h\343\202\223e\343\201\253l\343\201\241l\343\201\257o" 13
884 4 ?x "\346\227\245\346\234\254\350\252\236") .
885 "xex\346\227\245\346\234\254\350\252\236")))
812 ) ; end of tests that require MULE built in. 886 ) ; end of tests that require MULE built in.
813 887
814 ;;; end of mule-tests.el 888 ;;; end of mule-tests.el