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 byrepsbefore 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 (logical) – (optional) true if test passed, false if failed
The
repsargument 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
originalandreplacementarguments are passed directly as the 2nd and 3rd arguments toregexprep()(or tostrrep()ifreis present and false). The replacement applies togotonly, unlessbothis 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().