X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flanguage%2Fcontrol%2Fdefine.at;h=8ca40cbaba396e853b727753a8589c43fcf568e6;hb=b1b6921cc531da0593ee70b3dd1dd246dbdfbdd1;hp=bad9c15cbcd49ec36ed02b43d3761558b8b13a62;hpb=440613afbc2b901f51020c36afd59255a4988aa6;p=pspp diff --git a/tests/language/control/define.at b/tests/language/control/define.at index bad9c15cbc..8ca40cbaba 100644 --- a/tests/language/control/define.at +++ b/tests/language/control/define.at @@ -41,6 +41,18 @@ m(n, o). ]) AT_CLEANUP +AT_SETUP([redefining a macro]) +AT_DATA([define.sps], [dnl +DEFINE !macro() 0 !ENDDEFINE. +DEFINE !macro() 1 !ENDDEFINE. +DEBUG EXPAND. +!macro. +]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +1 +]) +AT_CLEANUP + AT_SETUP([macro expansion - one !TOKENS(1) positional argument]) AT_KEYWORDS([TOKENS]) AT_DATA([define.sps], [dnl @@ -169,7 +181,9 @@ e(a b) cmd(1 2 3 4) -cmd2(5 6, 7) +cmd2(5 6, ) + +note: unexpanded token "7" "Three !TOKENS(1) arguments." @@ -179,97 +193,275 @@ p(1, -2, -3) (1 -2 -3) ]) AT_CLEANUP -AT_SETUP([macro expansion with positional arguments - negative]) +AT_SETUP([macro call missing positional !TOKENS arguments]) +AT_KEYWORDS([TOKENS]) AT_DATA([define.sps], [dnl -DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE. -DEFINE !p(!positional !tokens(1) - /!positional !tokens(1) - /!positional !tokens(1)) +DEFINE !p(!positional !tokens(1) !default(x) + /!positional !tokens(1) !default(y) + /!positional !tokens(1) !default(z)) (!1, !2, !3) !ENDDEFINE. - -DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE. - -DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE. DEBUG EXPAND. -!title "Too few tokens for !TOKENS." +!p a b c. !p a b. !p a. !p. +]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +(a, b, c) -!title "Missing charend delimiter." -!ce a b c. +(a, b, z) -!title "Missing start delimiter." -!enc1 a b c. +(a, y, z) -!title "Missing end delimiter." -!enc1{a b c. +(x, y, z) +]) +AT_CLEANUP + +AT_SETUP([macro call incomplete positional !TOKENS arguments]) +AT_KEYWORDS([TOKENS]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !tokens(2) !default(x) + /!positional !tokens(2) !default(y) + /!positional !tokens(2) !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p a1 a2 b1 b2 c1 c2. +!p a1 a2 b1 b2 c1. +!p a1 a2 b1 b2. +!p a1 a2 b1. +!p a1 a2. +!p a1. +!p. ]) AT_CHECK([pspp --testing-mode define.sps], [1], [dnl -"Too few tokens for !TOKENS." +(a1 a2, b1 b2, c1 c2) -define.sps:13.7: error: DEBUG EXPAND: Unexpected end of command reading -argument !3 to macro !p. +define.sps:8.18: error: DEBUG EXPAND: Reached end of command expecting 1 more +token in argument !3 to macro !p. -note: unexpanded token "!p" +(a1 a2, b1 b2, c1) -note: unexpanded token "a" +(a1 a2, b1 b2, z) -note: unexpanded token "b" +define.sps:10.12: error: DEBUG EXPAND: Reached end of command expecting 1 more +token in argument !2 to macro !p. + +(a1 a2, b1, z) + +(a1 a2, y, z) + +define.sps:12.6: error: DEBUG EXPAND: Reached end of command expecting 1 more +token in argument !1 to macro !p. + +(a1, y, z) + +(x, y, z) +]) +AT_CLEANUP + +AT_SETUP([macro call empty positional !CHAREND arguments]) +AT_KEYWORDS([CHAREND]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !charend(',') !default(x) + /!positional !charend(';') !default(y) + /!positional !charend(':') !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p a,b;c:. +!p a,b;:. +!p a,;c:. +!p a,;:. +!p,b;c:. +!p,b;:. +!p,;c:. +!p,;:. +]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +(a, b, c) + +(a, b, ) + +(a, , c) + +(a, , ) + +(, b, c) + +(, b, ) + +(, , c) + +(, , ) +]) +AT_CLEANUP + +AT_SETUP([macro call missing positional !CHAREND arguments]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !charend(',') !default(x) + /!positional !charend(';') !default(y) + /!positional !charend(':') !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p a,b;c:. +!p a,b;. +!p a,;. +!p ,b;. +!p ,;. + +!p a,. +!p ,. + +!p. +]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +(a, b, c) + +(a, b, z) + +(a, , z) + +(, b, z) + +(, , z) + +(a, y, z) -define.sps:14.5: error: DEBUG EXPAND: Unexpected end of command reading +(, y, z) + +(x, y, z) +]) +AT_CLEANUP + +AT_SETUP([macro call incomplete positional !CHAREND arguments]) +AT_KEYWORDS([CHAREND]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !charend(',') !default(x) + /!positional !charend(';') !default(y) + /!positional !charend(':') !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p a,b;c:. +!p a,b;c. +!p a,b;. +!p a,b. +!p a,. +!p a. +!p. +]) +AT_CHECK([pspp --testing-mode define.sps], [1], [dnl +(a, b, c) + +define.sps:8.9: error: DEBUG EXPAND: Reached end of command expecting ":" in +argument !3 to macro !p. + +(a, b, c) + +(a, b, z) + +define.sps:10.7: error: DEBUG EXPAND: Reached end of command expecting ";" in argument !2 to macro !p. -note: unexpanded token "!p" +(a, b, z) -note: unexpanded token "a" +(a, y, z) -define.sps:15.3: error: DEBUG EXPAND: Unexpected end of command reading +define.sps:12.5: error: DEBUG EXPAND: Reached end of command expecting "," in argument !1 to macro !p. -note: unexpanded token "!p" +(a, y, z) + +(x, y, z) +]) +AT_CLEANUP + +AT_SETUP([macro call missing positional !ENCLOSE arguments]) +AT_KEYWORDS([ENCLOSE]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !enclose('(',')') !default(x) + /!positional !enclose('<','>') !default(y) + /!positional !enclose('{','}') !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p (a){c}. +!p (a). +!p (a). +!p. +]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +(a, b, c) -"Missing charend delimiter." +(a, b, z) -define.sps:18.10: error: DEBUG EXPAND: Unexpected end of command reading -argument !1 to macro !ce. +(a, y, z) -note: unexpanded token "!ce" +(x, y, z) +]) +AT_CLEANUP -note: unexpanded token "a" +AT_SETUP([macro call incomplete positional !ENCLOSE arguments]) +AT_KEYWORDS([ENCLOSE]) +AT_DATA([define.sps], [dnl +DEFINE !p(!positional !enclose('(',')') !default(x) + /!positional !enclose('<','>') !default(y) + /!positional !enclose('{','}') !default(z)) +(!1, !2, !3) +!ENDDEFINE. +DEBUG EXPAND. +!p (a){c}. +!p (a){c. +!p (a){. +!p (a). +!p (a)" in +argument !2 to macro !p. -note: unexpanded token "b" +(a, b, z) -note: unexpanded token "c" +define.sps:12.8: error: DEBUG EXPAND: Reached end of command expecting ">" in +argument !2 to macro !p. -"Missing end delimiter." +(a, , z) -define.sps:24.12: error: DEBUG EXPAND: Unexpected end of command reading -argument !1 to macro !enc1. +(a, y, z) -note: unexpanded token "!enc1" +define.sps:14.6: error: DEBUG EXPAND: Reached end of command expecting ")" in +argument !1 to macro !p. -note: unexpanded token "{" +(a, y, z) -note: unexpanded token "a" +define.sps:15.5: error: DEBUG EXPAND: Reached end of command expecting ")" in +argument !1 to macro !p. -note: unexpanded token "b" +(, y, z) -note: unexpanded token "c" +(x, y, z) ]) AT_CLEANUP @@ -325,18 +517,12 @@ AT_CHECK([pspp --testing-mode define.sps], [1], [dnl define.sps:3.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -define.sps:4.9: error: DEBUG EXPAND: Unexpected end of command reading argument -!arg1 to macro !k. - -note: unexpanded token "!k" +k( ) -note: unexpanded token "arg1" +define.sps:4.9: error: DEBUG EXPAND: Reached end of command expecting 1 more +token in argument !arg1 to macro !k. -note: unexpanded token "=" +k( ) ]) AT_CLEANUP @@ -383,48 +569,22 @@ AT_CHECK([pspp --testing-mode define.sps], [1], [dnl define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -define.sps:7.9: error: DEBUG EXPAND: Unexpected end of command reading argument -!arg1 to macro !k. - -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" +k(, ) -define.sps:8.10: error: DEBUG EXPAND: Unexpected end of command reading +define.sps:7.9: error: DEBUG EXPAND: Reached end of command expecting "/" in argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" +k(, ) -note: unexpanded token "=" +define.sps:8.10: error: DEBUG EXPAND: Reached end of command expecting "/" in +argument !arg1 to macro !k. -note: unexpanded token "x" +k(x, ) -define.sps:9.18: error: DEBUG EXPAND: Unexpected end of command reading +define.sps:9.18: error: DEBUG EXPAND: Reached end of command expecting "/" in argument !arg2 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "x" - -note: unexpanded token "/" - -note: unexpanded token "arg2" - -note: unexpanded token "=" - -note: unexpanded token "y" +k(x, y) ]) AT_CLEANUP @@ -475,118 +635,46 @@ AT_CHECK([pspp --testing-mode define.sps], [1], [dnl define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" +k(, ) define.sps:7.9: error: DEBUG EXPAND: Found `.' while expecting `@{:@' reading argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" +k(, ) define.sps:8.9: error: DEBUG EXPAND: Found `x' while expecting `@{:@' reading argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" +k(, ) note: unexpanded token "x" -define.sps:9.11: error: DEBUG EXPAND: Unexpected end of command reading +define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "@:}@" in argument !arg1 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "@{:@" - -note: unexpanded token "x" +k(x, ) define.sps:10.17: error: DEBUG EXPAND: Found `.' while expecting `=' reading argument !arg2 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "@{:@" - -note: unexpanded token "x" - -note: unexpanded token "@:}@" - -note: unexpanded token "arg2" +k(x, ) define.sps:11.18: error: DEBUG EXPAND: Found `.' while expecting `{' reading argument !arg2 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "@{:@" - -note: unexpanded token "x" - -note: unexpanded token "@:}@" - -note: unexpanded token "arg2" - -note: unexpanded token "=" +k(x, ) define.sps:12.18: error: DEBUG EXPAND: Found `y' while expecting `{' reading argument !arg2 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "@{:@" - -note: unexpanded token "x" - -note: unexpanded token "@:}@" - -note: unexpanded token "arg2" - -note: unexpanded token "=" +k(x, ) note: unexpanded token "y" define.sps:13.18: error: DEBUG EXPAND: Found `@{:@' while expecting `{' reading argument !arg2 to macro !k. -note: unexpanded token "!k" - -note: unexpanded token "arg1" - -note: unexpanded token "=" - -note: unexpanded token "@{:@" - -note: unexpanded token "x" - -note: unexpanded token "@:}@" - -note: unexpanded token "arg2" - -note: unexpanded token "=" +k(x, ) note: unexpanded token "@{:@" @@ -804,6 +892,72 @@ AT_CHECK([pspp --testing-mode define.sps], [0], [dnl ]) AT_CLEANUP +dnl Keep this test in sync with the examples for !NULL in the manual. +AT_SETUP([macro expansion - !NULL]) +AT_KEYWORDS([NULL]) +AT_DATA([define.sps], [dnl +DEFINE !n() +!NULL. +!QUOTE(!NULL). +!ENDDEFINE. +DEBUG EXPAND. +!n. +]) +AT_CAPTURE_FILE([define.sps]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +. +''. +]) +AT_CLEANUP + +dnl Keep this test in sync with the examples for !QUOTE and !UNQUOTE in the manual. +AT_SETUP([macro expansion - !QUOTE and !UNQUOTE]) +AT_KEYWORDS([QUOTE UNQUOTE]) +AT_DATA([define.sps], [dnl +DEFINE !q(!POS !CMDEND) +!QUOTE(123.0). +!QUOTE( 123 ). +!QUOTE('a b c'). +!QUOTE("a b c"). +!QUOTE(!1). + +!UNQUOTE(123.0). +!UNQUOTE( 123 ). +!UNQUOTE('a b c'). +!UNQUOTE("a b c"). +!UNQUOTE(!1). + +!QUOTE(!UNQUOTE(123.0)). +!QUOTE(!UNQUOTE( 123 )). +!QUOTE(!UNQUOTE('a b c')). +!QUOTE(!UNQUOTE("a b c")). +!QUOTE(!UNQUOTE(!1)). +!ENDDEFINE. +DEBUG EXPAND. +!q a 'b' c. +]) +AT_CAPTURE_FILE([define.sps]) +AT_CHECK([pspp --testing-mode define.sps], [0], [dnl +'123.0'. +'123'. +'a b c'. +"a b c". +'a ''b'' c'. + +123.0. +123. +a b c. +a b c. +a 'b' c. + +'123.0'. +'123'. +'a b c'. +'a b c'. +'a ''b'' c'. +]) +AT_CLEANUP + dnl Keep this test in sync with the examples for !SUBSTR in the manual. AT_SETUP([macro expansion - !SUBSTR]) AT_KEYWORDS([SUBSTR]) @@ -1370,14 +1524,14 @@ DEBUG EXPAND. AT_CHECK([pspp --testing-mode define.sps], [1], [dnl In the expansion of `!DO', define.sps:1-3: inside the expansion of `!for', -define.sps:7.1-7.11: error: DEBUG EXPAND: !DO loop over list exceeded maximum +define.sps:7.1-7.10: error: DEBUG EXPAND: !DO loop over list exceeded maximum number of iterations 2. (Use SET MITERATE to change the limit.) ( (a) (b) ). In the expansion of `!DO', define.sps:1-3: inside the expansion of `!for', -define.sps:8.1-8.24: error: DEBUG EXPAND: !DO loop over list exceeded maximum +define.sps:8.1-8.23: error: DEBUG EXPAND: !DO loop over list exceeded maximum number of iterations 2. (Use SET MITERATE to change the limit.) ( (foo) (bar) ). @@ -1557,10 +1711,26 @@ not a multiple of 2. ]) AT_CLEANUP +AT_SETUP([macro name overlaps with macro function name]) +dnl !len is short for macro function !LENGTH. PSPP used to +dnl reject the following with "`(' expected following !LENGTH". +dnl Now PSPP only consider macro functions when the name is +dnl followed by '('. +AT_DATA([define.sps], [dnl +DEFINE !len() 5 !ENDDEFINE. +DEFINE !x() !eval(!len) !ENDDEFINE. +DEBUG EXPAND. +!x +]) +AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl +5 +]) +AT_CLEANUP + AT_SETUP([generic macro function syntax errors]) AT_DATA([define.sps], [dnl -DEFINE !a() !SUBSTR !ENDDEFINE. -DEFINE !b() !SUBSTR x !ENDDEFINE. + + DEFINE !c() !SUBSTR(1x) !ENDDEFINE. DEFINE !d() !SUBSTR(1 !ENDDEFINE. DEFINE !narg_blanks() !BLANKS() !ENDDEFINE. @@ -1577,8 +1747,8 @@ DEFINE !narg_unquote() !UNQUOTE() !ENDDEFINE. DEFINE !narg_upcase() !UPCASE() !ENDDEFINE. dnl ) DEBUG EXPAND. -!a. -!b. + + !c. !d. !narg_blanks. @@ -1595,16 +1765,6 @@ DEBUG EXPAND. !narg_upcase. ]) AT_CHECK([pspp --testing-mode define.sps], [1], [dnl -define.sps:1: In the expansion of `!a', -define.sps:18.1-18.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR. - -!SUBSTR - -define.sps:2: At `x' in the expansion of `!b', -define.sps:19.1-19.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR. - -!SUBSTR x - define.sps:3: At `x' in the expansion of `!c', define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro function !SUBSTR.