From a90a6f00cfcc1bce79f9f67d547c53428c5a30d5 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Tue, 26 Apr 2022 15:13:18 +0000 Subject: [PATCH] chore: adding test for mp_chop() --- tests/crossplatform/mp_chop.test.sas | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/crossplatform/mp_chop.test.sas diff --git a/tests/crossplatform/mp_chop.test.sas b/tests/crossplatform/mp_chop.test.sas new file mode 100644 index 0000000..aef42ae --- /dev/null +++ b/tests/crossplatform/mp_chop.test.sas @@ -0,0 +1,70 @@ +/** + @file + @brief Testing mp_chop.sas macro + +

SAS Macros

+ @li mp_chop.sas + @li mp_assert.sas + @li mp_assertscope.sas + +**/ + +/* prep input string */ +%let src="%sysfunc(pathname(work))/file.txt"; +%let str=Chop here!; +%let out1="%sysfunc(pathname(work))/file1.txt"; +%let out2="%sysfunc(pathname(work))/file2.txt"; +%let out3="%sysfunc(pathname(work))/file3.txt"; +%let out4="%sysfunc(pathname(work))/file4.txt"; + +data _null_; + file &src; + put "startsection&str.endsection"; +run; + + +%mp_assertscope(SNAPSHOT) +%mp_chop(&src, matchvar=str, keep=FIRST, outfile=&out1) +%mp_chop(&src, matchvar=str, keep=LAST, outfile=&out2) +%mp_chop(&src, matchvar=str, keep=FIRST, matchpoint=END, outfile=&out3) +%mp_chop(&src, matchvar=str, keep=LAST, matchpoint=END, outfile=&out4) +%mp_assertscope(COMPARE) + +data _null_; + infile &out1 lrecl=200; + input; + call symputx('test1',_infile_); +data _null_; + infile &out2 lrecl=200; + input; + call symputx('test2',_infile_); +data _null_; + infile &out3 lrecl=200; + input; + call symputx('test3',_infile_); +data _null_; + infile &out4 lrecl=200; + input; + call symputx('test4',_infile_); +run; + +%mp_assert( + iftrue=("&test1" ne "startsection"), + desc=Checking keep FIRST matchpoint START + outds=work.test_results +) +%mp_assert( + iftrue=("&test2" ne "Chop here!endsection"), + desc=Checking keep LAST matchpoint START + outds=work.test_results +) +%mp_assert( + iftrue=("&test1" ne "startsectionChop here!"), + desc=Checking keep FIRST matchpoint END + outds=work.test_results +) +%mp_assert( + iftrue=("&test2" ne "endsection"), + desc=Checking keep LAST matchpoint END + outds=work.test_results +)