Commits

Anonymous committed 80a29ac

Initial import

Comments (0)

Files changed (3)

+function match = compare(want, got)
+want_escaped = regexptranslate('escape', want);
+want_re = regexprep(want_escaped, '(\\\*){3}', '.*');
+
+
+
+match = regexp(got, want_re);
+
+end
+function doctest(func_name, verbose)
+% Run examples embedded in documentation
+%
+% doctest func_name
+% doctest('func_name')
+%
+% Example:
+% Say you have a function that adds 7 to things:
+%     function res = add7(num)
+%         % >> add7(3)
+%         %
+%         % ans =
+%         %
+%         %      10
+%         %
+%         res = num + 7;
+%     end
+% 
+
+docstring = help(func_name);
+
+if nargin < 2
+    verbose = 0;
+else
+    verbose = 1;
+end
+
+
+test_anything(run_doctests(docstring), verbose);
+
+end
+
+function results = run_doctests(docstring)
+%
+% 
+% >> 1 + 2
+% ans =
+%      3
+%
+
+% loosely based on Python 2.6 doctest.py, line 510
+example_re = '(?m)(?-s)(?:^ *>> )(?<source>.*)\n(?<want>(?:(?:^ *$\n)?(?!\s*>>).*\w.*\n)*)';
+
+[matches] = regexp(docstring, example_re, 'names', 'warnings');
+
+results = struct;
+
+for I = 1:length(matches)
+    
+    % ['<<' matches(I).want '>>']
+    
+    got = evalc(matches(I).source);
+    % ['{{' got '}}']
+    
+    want_unspaced = regexprep(matches(I).want, '\s+', ' ');
+    
+    got_unspaced = regexprep(got, '\s+', ' ');
+    
+    results(I).source = matches(I).source;
+    results(I).want = want_unspaced;
+    results(I).got = got_unspaced;
+    results(I).pass = strcmp(want_unspaced, got_unspaced);
+    
+end
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.