Commits

Anonymous committed 2c7172c

Added some refinements to comparisons: manipulate the "got" string to get rid of hyperlinks and backspaced letters. Also added doctests of these comparisons.

Comments (0)

Files changed (1)

 function match = compare(want, got)
 % Matches two strings together... they should be identical, except that the
 % first one can contain '***', which matches anything in the second string.
+%
+% But there are also some tricksy things that Matlab does to strings.  Such
+% as add hyperlinks to help.  This doctest tests that condition.
+%
+% >> disp('Hi there!  <a href="matlab:help help">foo</a>')
+% Hi there!  foo
+%
+%
+% They also sometimes backspace over things for no apparent reason.  This
+% doctest recreates that condition.
+%
+% >> sprintf('Hi there, there is no dot here: .\x08')
+% 
+% ans =
+% 
+% Hi there, there is no dot here: 
+%
+%
+% All of the doctests should pass, and they manipulate this function.
+%
 
-got = regexprep(got, '<a href=.*?>', '');
+% This looks bad, like hardcoding for lower-case "a href"
+% and a double quote... but that's what MATLAB looks for too.
+got = regexprep(got, '<a +href=".*?>', '');
 got = regexprep(got, '</a>', '');
-got = regexprep(got, '.\x08', ''); % WHY do they need backspaces?  huh.
+
+% WHY do they need backspaces?  huh.
+got = regexprep(got, '.\x08', '');
 
 want = strtrim(want);
 got = strtrim(got);
-any(got == '{')
+
 if isempty(want) && isempty(got)
     match = 1;
     return
 
 
 
-match = regexp(got, want_re);
+result = regexp(got, want_re, 'once');
+
+match = ~ isempty(result);
 
 end