t_str_match
- t_str_match(got, expected, msg, reps)
t_str_match()
- Tests whether two strings/char arrays match.t_str_match(got, expected, msg) t_str_match(got, expected, msg, reps) ok = t_str_match(...)
This is equivalent to
t_ok(strcmp(got, expected), msg)
, with the option to apply replacements togot
, and optionally toexpected
, as specified byreps
before comparing.- Inputs:
got (char array) – actual result
expected (char array) – expected result
msg (char array) – message to display for this test
reps (char array) – (optional) cell array of replacement specs
- Output:
ok (boolean) – (optional) true if test passed, false if failed
The
reps
argument is a cell array of replacement specs, applied sequentially, where each replacement spec is a cell array of the following form:{original, replacement} {original, replacement, re} {original, replacement, re, both}
The
original
andreplacement
arguments are passed directly as the 2nd and 3rd arguments toregexprep()
(or tostrrep()
ifre
is present and false). The replacement applies togot
only, unlessboth
is present and true, in which case it also applies toexpected
.Intended to be called between calls to
t_begin()
andt_end()
.Example:
quiet = 0; t_begin(5, quiet); % replace Windows EOL chars with Unix EOL chars reps = {{char([13 10]), char(10), 0, 1}}; got = fileread('test_generated_output.txt'); expected = fileread('expected_output.txt'); t_str_match(got, expected, 'mytest', reps); t_end;
See also
t_ok()
,t_is()
,t_file_match()
,t_skip()
,t_begin()
,t_end()
,t_run_tests()
.