Skip to content
Browse files

Bring test suite more up-to-date. Fix some problems it found.

  • Loading branch information...
1 parent 16356ee commit 16b6b41828317cdb637885c8edc74a5812c09a25 @cgay committed Mar 6, 2012
Showing with 48 additions and 202 deletions.
  1. +1 −8 library.dylan
  2. +3 −3 substring-search.dylan
  3. +44 −191 tests/strings-test-suite.dylan
View
9 library.dylan
@@ -56,19 +56,12 @@ define module strings
// Character comparison
create
- char-equal?, // for symmetry...same as =, <, and >
- char-less?,
- char-greater?,
-
char-equal-ignoring-case?,
char-less-ignoring-case?,
char-greater-ignoring-case?;
// String copying, transformations, etc
create
- capitalize!,
- capitalize,
- ends-with?,
interpolate,
// join,
lowercase!,
@@ -81,7 +74,6 @@ define module strings
// override position(<string>, <regex>) and find(...) in common-extensions
find-substring,
- count-substrings,
replace-substrings,
// slice!,
@@ -90,6 +82,7 @@ define module strings
// split,
split-lines,
starts-with?,
+ ends-with?,
strip,
strip-left,
strip-right,
View
6 substring-search.dylan
@@ -57,7 +57,6 @@ define sealed inline method find-substring
compiled-pattern);
end method find-substring;
-/* Not used in new strings library.
// KJP: BUG!!! Removed inline because of crash compiling test case
define sealed /* inline */ method make-substring-positioner
(pattern :: <byte-string>, #key case-sensitive = #f)
@@ -71,7 +70,6 @@ define sealed /* inline */ method make-substring-positioner
end method compiled-matcher;
compiled-matcher;
end method make-substring-positioner;
-*/
define inline function equal?
(char1 :: <character>, char2 :: <character>, case-sensitive :: <boolean>)
@@ -197,6 +195,7 @@ define method replace-substrings
do-replacement(positioner, replace-with, big, start, input-end, count, #f);
end method replace-substrings;
+/*
define method make-substring-replacer
(search-for :: <byte-string>, #key replace-with, case-sensitive = #f)
=> replacer :: <function>;
@@ -218,6 +217,7 @@ define method make-substring-replacer
end method;
end if;
end method make-substring-replacer;
+*/
// The local method expand-replace-sequence probably generates
// excessive garbage for replace-with's that involve backslashes. One
@@ -240,7 +240,7 @@ define inline function do-replacement
as(<string>, new-substring[index]);
else
index := index + 1;
- if (~digit?(new-substring[index]))
+ if (~decimal-digit?(new-substring[index]))
as(<string>, new-substring[index]);
else
let ref-number
View
235 tests/strings-test-suite.dylan
@@ -31,39 +31,45 @@ define module-spec strings ()
open generic-function ascii-control? (<string-or-char>) => (<boolean>);
open generic-function ascii-graphic? (<string-or-char>) => (<boolean>);
open generic-function ascii-printable? (<string-or-char>) => (<boolean>);
- open generic-function ci-char-equal? (<character>, <character>) => (<boolean>);
- open generic-function ci-char-greater? (<character>, <character>) => (<boolean>);
- open generic-function ci-char-less? (<character>, <character>) => (<boolean>);
- open generic-function ci-string-equal? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
- open generic-function ci-string-greater? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
- open generic-function ci-string-less? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
- open generic-function count-matches (<string>, <string>, #"key", #"start", "end", #"test", #"overlap?") => (<integer>);
open generic-function decimal-digit? (<string-or-char>) => (<boolean>);
- open generic-function ends-with? (<string>, <string>, #"key", #"test") => (<boolean>);
- open generic-function find-match (<string>, <string>, #"key", #"start", "end", #"test") => (false-or(<integer>));
+
open generic-function hexadecimal-digit? (<string-or-char>) => (<boolean>);
- open generic-function lowercase (<string-or-char>) => (<string-or-char>);
- open generic-function lowercase! (<string-or-char>) => (<string-or-char>);
- open generic-function lowercase? (<string-or-char>) => (<boolean>);
open generic-function octal-digit? (<string-or-char>) => (<boolean>);
- open generic-function replace-matches (<string>, <string>, <string>, #"key", #"test", #"count") => (<string>);
open generic-function starts-with? (<string>, <string>, #"key", #"start", #"test") => (<boolean>);
+ open generic-function ends-with? (<string>, <string>, #"key", #"test") => (<boolean>);
+
open generic-function string-equal? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
open generic-function string-greater? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
open generic-function string-less? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
+ open generic-function string-equal-ignoring-case? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
+ open generic-function string-greater-ignoring-case? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
+ open generic-function string-less-ignoring-case? (<string>, <string>, #"key", #"start1", #"end1", #"start2", #"end2") => (<boolean>);
+ open generic-function char-equal-ignoring-case? (<character>, <character>) => (<boolean>);
+ open generic-function char-greater-ignoring-case? (<character>, <character>) => (<boolean>);
+ open generic-function char-less-ignoring-case? (<character>, <character>) => (<boolean>);
+
open generic-function strip (<string>, #"key", #"test") => (<string>);
open generic-function strip-left (<string>, #"key", #"test") => (<string>);
open generic-function strip-right (<string>, #"key", #"test") => (<string>);
+
+ open generic-function lowercase (<string-or-char>) => (<string-or-char>);
+ open generic-function lowercase! (<string-or-char>) => (<string-or-char>);
+ open generic-function lowercase? (<string-or-char>) => (<boolean>);
open generic-function uppercase (<string-or-char>) => (<string-or-char>);
open generic-function uppercase! (<string-or-char>) => (<string-or-char>);
open generic-function uppercase? (<string-or-char>) => (<boolean>);
+
open generic-function whitespace? (<string-or-char>) => (<boolean>);
+
+ //open generic-function count-substrings (<string>, <string>, #"key", #"start", "end", #"test", #"overlap?") => (<integer>);
+ open generic-function find-substring (<string>, <string>, #"key", #"start", "end", #"test") => (false-or(<integer>));
+ open generic-function replace-substrings (<string>, <string>, <string>, #"key", #"test", #"count") => (<string>);
end module-spec strings;
-define strings function-test ci-string-less? ()
+define strings function-test string-less-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-string-less?;
+end function-test string-less-ignoring-case?;
define strings function-test ends-with? ()
//---*** Fill this in...
@@ -73,29 +79,21 @@ define strings function-test align-left ()
//---*** Fill this in...
end function-test align-left;
-define strings function-test whitespace? ()
- //---*** Fill this in...
-end function-test whitespace?;
-
define strings function-test align-center ()
//---*** Fill this in...
end function-test align-center;
-define strings function-test ci-string-greater? ()
+define strings function-test string-greater-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-string-greater?;
+end function-test string-greater-ignoring-case?;
define strings function-test ascii-graphic? ()
//---*** Fill this in...
end function-test ascii-graphic?;
-define strings function-test ci-string-equal? ()
+define strings function-test string-equal-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-string-equal?;
-
-define strings function-test uppercase ()
- //---*** Fill this in...
-end function-test uppercase;
+end function-test string-equal-ignoring-case?;
define strings function-test ascii-alphanumeric? ()
//---*** Fill this in...
@@ -105,46 +103,34 @@ define strings function-test ascii-control? ()
//---*** Fill this in...
end function-test ascii-control?;
-define strings function-test find-match ()
+define strings function-test find-substring ()
//---*** Fill this in...
-end function-test find-match;
+end function-test find-substring;
-define strings function-test ci-char-greater? ()
+define strings function-test char-greater-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-char-greater?;
+end function-test char-greater-ignoring-case?;
-define strings function-test ci-char-equal? ()
+define strings function-test char-equal-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-char-equal?;
+end function-test char-equal-ignoring-case?;
-define strings function-test replace-matches ()
+define strings function-test replace-substrings ()
//---*** Fill this in...
-end function-test replace-matches;
+end function-test replace-substrings;
-define strings function-test ci-char-less? ()
+define strings function-test char-less-ignoring-case? ()
//---*** Fill this in...
-end function-test ci-char-less?;
-
-define strings function-test lowercase ()
- //---*** Fill this in...
-end function-test lowercase;
+end function-test char-less-ignoring-case?;
define strings function-test ascii-alphabetic? ()
//---*** Fill this in...
end function-test ascii-alphabetic?;
-define strings function-test strip-left ()
- //---*** Fill this in...
-end function-test strip-left;
-
define strings function-test octal-digit? ()
//---*** Fill this in...
end function-test octal-digit?;
-define strings function-test lowercase? ()
- //---*** Fill this in...
-end function-test lowercase?;
-
define strings function-test slice ()
//---*** Fill this in...
end function-test slice;
@@ -153,14 +139,6 @@ define strings function-test ascii-printable? ()
//---*** Fill this in...
end function-test ascii-printable?;
-define strings function-test lowercase! ()
- //---*** Fill this in...
-end function-test lowercase!;
-
-define strings function-test uppercase! ()
- //---*** Fill this in...
-end function-test uppercase!;
-
define strings function-test string-greater? ()
//---*** Fill this in...
end function-test string-greater?;
@@ -173,14 +151,6 @@ define strings function-test string-less? ()
//---*** Fill this in...
end function-test string-less?;
-define strings function-test strip ()
- //---*** Fill this in...
-end function-test strip;
-
-define strings function-test uppercase? ()
- //---*** Fill this in...
-end function-test uppercase?;
-
define strings function-test string-equal? ()
local method e (s1, s2, #rest args)
check-true(fmt("equal?(%=, %=, ,@%=)", s1, s2, args),
@@ -203,10 +173,6 @@ define strings function-test string-equal? ()
e("cd", "abcd", start2: 2);
end function-test string-equal?;
-define strings function-test count-matches ()
- //---*** Fill this in...
-end function-test count-matches;
-
define strings function-test decimal-digit? ()
//---*** Fill this in...
end function-test decimal-digit?;
@@ -219,123 +185,14 @@ define strings function-test starts-with? ()
//---*** Fill this in...
end function-test starts-with?;
-define strings function-test strip-right ()
+define strings function-test strip-left ()
//---*** Fill this in...
-end function-test strip-right;
-
-
-
-/* old definition
-define module-spec strings ()
- sealed generic-function byte-string? (<object>) => (<boolean>);
-
- open generic-function alphabetic? (<character>) => (<boolean>);
- open generic-function digit? (<character>) => (<boolean>);
- open generic-function alphanumeric? (<character>) => (<boolean>);
- open generic-function whitespace? (<character>) => (<boolean>);
- open generic-function uppercase? (<character>) => (<boolean>);
- open generic-function lowercase? (<character>) => (<boolean>);
- open generic-function graphic? (<character>) => (<boolean>);
- open generic-function printable? (<character>) => (<boolean>);
- open generic-function control? (<character>) => (<boolean>);
-
-
- open generic-function equal?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
- open generic-function less?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
- open generic-function greater?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
-
- open generic-function case-insensitive-equal?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
- open generic-function case-insensitive-less?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
- open generic-function case-insensitive-greater?
- (<string>, <string>, #"key", #"start1", #"start2", #"end1", #"end2" #"test")
- => (<boolean>);
-
- open generic-function index-of
- (<string>, <string>, #"key", #"test", #"start", #"end", #"from-end?") => (<integer>);
- open generic-function count-matches
- (<string>, <string>, #"key", #"test", #"start", #"end") => (<integer>);
-
-
- open generic-function trim
- (<string>, #"key", #"test", #"side", #"start", #"end") => (<string>);
-
- open generic-function uppercase (<string>) => (<string>);
- open generic-function uppercase! (<string>) => (<string>);
- open generic-function lowercase (<string>) => (<string>);
- open generic-function lowercase! (<string>) => (<string>);
- open generic-function capitalize (<string>, #"key", #"start", #"end") => (<string>);
- open generic-function capitalize! (<string>, #"key", #"start", #"end") => (<string>);
- open generic-function pluralize (<string>, #"key", #"count") => (<string>);
- open generic-function a-or-an (<string>) => (<string>);
-
-
- open generic-function integer-to-digit (<integer>) => (<character>);
- open generic-function digit-to-integer (<character>) => (<integer>);
-
-end module-spec strings;
-*/
-
-// Module: strings
-
-define strings function-test byte-string? ()
- for (item in list(#("", #t),
- #(5, #f),
- list(as(<unicode-string>, ""), #f)))
- let (val, expected-result) = apply(values, item);
- check-equal(fmt("byte-string?(%=) => %=", val, expected-result),
- expected-result,
- byte-string?(val));
- end for;
-end function-test byte-string?;
-
-
-define strings function-test capitalize ()
- for (item in #(#("", ""),
- #("x", "X"),
- #("abc", "Abc"),
- #("Abc", "Abc"),
- #("one two", "One Two"),
- #("_one,two", "_One,Two")))
- let (before, expected) = apply(values, item);
- check-equal(fmt("capitalize %=", before),
- expected,
- capitalize(before));
- end;
-end function-test capitalize;
-
-define strings function-test capitalize! ()
- for (item in #(#("", ""),
- #("a", "A"),
- #("abc", "Abc"),
- #("Abc", "Abc"),
- #("one two", "One Two"),
- #("_one,two", "_One,Two")))
- let (before, expected) = apply(values, map(copy-sequence, item));
- check-equal(fmt("capitalize! %=", before),
- expected,
- capitalize!(before));
- check-true(fmt("capitalize! %= retains identity", before),
- capitalize!(before) == before);
- end;
-end function-test capitalize!;
+end function-test strip-left;
-define strings function-test pluralize ()
+define strings function-test strip-right ()
//---*** Fill this in...
-end function-test pluralize;
+end function-test strip-right;
-define strings function-test a-or-an ()
- //---*** Fill this in...
-end function-test a-or-an;
define strings function-test lowercase! ()
for (item in #(#("", ""),
@@ -389,7 +246,7 @@ define strings function-test uppercase ()
end;
end function-test uppercase;
-define strings function-test trim ()
+define strings function-test strip ()
for (item in list(#("", ""),
#("a", "a"),
#("a", " a "),
@@ -399,12 +256,12 @@ define strings function-test trim ()
list(" a ", " a ", test:, method (c) #f end),
list("o", "xox", test:, method (c) c == 'x' end)
))
- let (expected, before, #rest trim-args) = apply(values, item);
- check-equal(fmt("trim %=", before),
+ let (expected, before, #rest strip-args) = apply(values, item);
+ check-equal(fmt("strip %=", before),
expected,
- apply(trim, before, trim-args));
+ apply(strip, before, strip-args));
end for;
-end function-test trim;
+end function-test strip;
define strings function-test join ()
let abc = #["a", "b", "c"];
@@ -476,10 +333,6 @@ define strings function-test alphabetic? ()
//---*** Fill this in...
end function-test alphabetic?;
-define strings function-test count-matches ()
- //---*** Fill this in...
-end function-test count-matches;
-
define strings function-test index-of ()
//---*** Fill this in...
end function-test index-of;

0 comments on commit 16b6b41

Please sign in to comment.
Something went wrong with that request. Please try again.