langtools/test/jdk/jshell/ToolFormatTest.java
changeset 38539 71874886920f
parent 38531 c449daa25b45
child 38615 9221159d84fb
equal deleted inserted replaced
38538:8bdc63ff6961 38539:71874886920f
    41 public class ToolFormatTest extends ReplToolTesting {
    41 public class ToolFormatTest extends ReplToolTesting {
    42 
    42 
    43     public void testSetFormat() {
    43     public void testSetFormat() {
    44         try {
    44         try {
    45             test(
    45             test(
    46                     (a) -> assertCommandOutputStartsWith(a, "/set newmode test -command", "|  Created new feedback mode: test"),
    46                     (a) -> assertCommandOutputStartsWith(a, "/set mode test -command", "|  Created new feedback mode: test"),
    47                     (a) -> assertCommand(a, "/set format test pre '$ '", ""),
    47                     (a) -> assertCommand(a, "/set format test pre '$ '", ""),
    48                     (a) -> assertCommand(a, "/set format test post ''", ""),
    48                     (a) -> assertCommand(a, "/set format test post ''", ""),
    49                     (a) -> assertCommand(a, "/set format test act 'ADD' added", ""),
    49                     (a) -> assertCommand(a, "/set format test act 'ADD' added", ""),
    50                     (a) -> assertCommand(a, "/set format test act 'MOD' modified", ""),
    50                     (a) -> assertCommand(a, "/set format test act 'MOD' modified", ""),
    51                     (a) -> assertCommand(a, "/set format test act 'REP' replaced", ""),
    51                     (a) -> assertCommand(a, "/set format test act 'REP' replaced", ""),
    80         }
    80         }
    81     }
    81     }
    82 
    82 
    83     public void testSetFormatSelector() {
    83     public void testSetFormatSelector() {
    84         List<ReplTest> tests = new ArrayList<>();
    84         List<ReplTest> tests = new ArrayList<>();
    85         tests.add((a) -> assertCommandOutputStartsWith(a, "/set newmode ate -quiet",
    85         tests.add((a) -> assertCommandOutputStartsWith(a, "/set mode ate -quiet",
    86                             "|  Created new feedback mode: ate"));
    86                             "|  Created new feedback mode: ate"));
    87         tests.add((a) -> assertCommand(a, "/set feedback ate", ""));
    87         tests.add((a) -> assertCommand(a, "/set feedback ate", ""));
    88         StringBuilder sb = new StringBuilder();
    88         StringBuilder sb = new StringBuilder();
    89         class KindList {
    89         class KindList {
    90             final String[] values;
    90             final String[] values;
   160             test(
   160             test(
   161                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", ""),
   161                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", ""),
   162                     (a) -> assertCommand(a, "String s = java.util.stream.IntStream.range(65, 74)"+
   162                     (a) -> assertCommand(a, "String s = java.util.stream.IntStream.range(65, 74)"+
   163                             ".mapToObj(i -> \"\"+(char)i).reduce((a,b) -> a + b + a).get()",
   163                             ".mapToObj(i -> \"\"+(char)i).reduce((a,b) -> a + b + a).get()",
   164                             "s ==> \"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABAGABACABADABA ..."),
   164                             "s ==> \"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABAGABACABADABA ..."),
   165                     (a) -> assertCommandOutputStartsWith(a, "/set newmode test -quiet", ""),
   165                     (a) -> assertCommandOutputStartsWith(a, "/set mode test -quiet", ""),
   166                     (a) -> assertCommandOutputStartsWith(a, "/set feedback test", ""),
   166                     (a) -> assertCommandOutputStartsWith(a, "/set feedback test", ""),
   167                     (a) -> assertCommand(a, "/set format test display '{type}:{value}' primary", ""),
   167                     (a) -> assertCommand(a, "/set format test display '{type}:{value}' primary", ""),
   168                     (a) -> assertCommand(a, "/set truncation test 20", ""),
   168                     (a) -> assertCommand(a, "/set truncation test 20", ""),
   169                     (a) -> assertCommand(a, "/set trunc test 10 varvalue", ""),
   169                     (a) -> assertCommand(a, "/set trunc test 10 varvalue", ""),
   170                     (a) -> assertCommand(a, "/set trunc test 3 assignment", ""),
   170                     (a) -> assertCommand(a, "/set trunc test 3 assignment", ""),
   185     }
   185     }
   186 
   186 
   187     public void testSetNewModeQuiet() {
   187     public void testSetNewModeQuiet() {
   188         try {
   188         try {
   189             test(
   189             test(
   190                     (a) -> assertCommandOutputStartsWith(a, "/set newmode nmq -quiet normal", "|  Created new feedback mode: nmq"),
   190                     (a) -> assertCommandOutputStartsWith(a, "/set mode nmq -quiet normal", "|  Created new feedback mode: nmq"),
   191                     (a) -> assertCommand(a, "/set feedback nmq", ""),
   191                     (a) -> assertCommand(a, "/set feedback nmq", ""),
   192                     (a) -> assertCommand(a, "/se ne nmq2 -q nor", ""),
   192                     (a) -> assertCommand(a, "/se mo nmq2 -q nor", ""),
   193                     (a) -> assertCommand(a, "/se fee nmq2", ""),
   193                     (a) -> assertCommand(a, "/se fee nmq2", ""),
   194                     (a) -> assertCommand(a, "/set newmode nmc -command normal", ""),
   194                     (a) -> assertCommand(a, "/set mode nmc -command normal", ""),
   195                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "|  Feedback mode: nmc"),
   195                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "|  Feedback mode: nmc"),
   196                     (a) -> assertCommandOutputStartsWith(a, "/set newmode nm", "|  Created new feedback mode: nm"),
   196                     (a) -> assertCommandOutputStartsWith(a, "/set mode nm", "|  Created new feedback mode: nm"),
   197                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "|  Feedback mode: nm"),
   197                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "|  Feedback mode: nm"),
   198                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
   198                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
   199             );
   199             );
   200         } finally {
   200         } finally {
   201             assertCommandCheckOutput(false, "/set feedback normal", s -> {
   201             assertCommandCheckOutput(false, "/set feedback normal", s -> {
   204     }
   204     }
   205 
   205 
   206     public void testSetError() {
   206     public void testSetError() {
   207         try {
   207         try {
   208             test(
   208             test(
   209                     (a) -> assertCommandOutputStartsWith(a, "/set newmode tee -command foo",
   209                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee -command foo",
   210                             "|  Does not match any current feedback mode: foo"),
   210                             "|  Does not match any current feedback mode: foo"),
   211                     (a) -> assertCommandOutputStartsWith(a, "/set newmode tee flurb",
   211                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee flurb",
   212                             "|  Specify either '-command' or '-quiet'"),
   212                             "|  Does not match any current feedback mode: flurb"),
   213                     (a) -> assertCommandOutputStartsWith(a, "/set newmode te2",
   213                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee",
   214                             "|  Created new feedback mode: te2"),
   214                             "|  Created new feedback mode: tee"),
   215                     (a) -> assertCommandOutputStartsWith(a, "/set newmode te2 -command",
   215                     (a) -> assertCommandOutputStartsWith(a, "/set mode verbose",
   216                             "|  Expected a new feedback mode name. 'te2' is a known feedback mode"),
   216                             "|  Not valid with a predefined mode: verbose"),
   217                     (a) -> assertCommandOutputStartsWith(a, "/set newmode te -command normal",
   217                     (a) -> assertCommandOutputStartsWith(a, "/set mode te -command normal",
   218                             "|  Created new feedback mode: te"),
   218                             "|  Created new feedback mode: te"),
   219                     (a) -> assertCommand(a, "/set format te errorpre 'ERROR: '", ""),
   219                     (a) -> assertCommand(a, "/set format te errorpre 'ERROR: '", ""),
   220                     (a) -> assertCommandOutputStartsWith(a, "/set feedback te",
   220                     (a) -> assertCommandOutputStartsWith(a, "/set feedback te",
   221                             ""),
   221                             ""),
   222                     (a) -> assertCommandOutputStartsWith(a, "/set ",
   222                     (a) -> assertCommandOutputStartsWith(a, "/set ",
   224                     (a) -> assertCommandOutputStartsWith(a, "/set xyz",
   224                     (a) -> assertCommandOutputStartsWith(a, "/set xyz",
   225                             "ERROR: Invalid '/set' argument: xyz"),
   225                             "ERROR: Invalid '/set' argument: xyz"),
   226                     (a) -> assertCommandOutputStartsWith(a, "/set f",
   226                     (a) -> assertCommandOutputStartsWith(a, "/set f",
   227                             "ERROR: Ambiguous sub-command argument to '/set': f"),
   227                             "ERROR: Ambiguous sub-command argument to '/set': f"),
   228                     (a) -> assertCommandOutputStartsWith(a, "/set feedback",
   228                     (a) -> assertCommandOutputStartsWith(a, "/set feedback",
   229                             "ERROR: Expected a feedback mode"),
   229                             "ERROR: Missing the feedback mode"),
   230                     (a) -> assertCommandOutputStartsWith(a, "/set feedback xyz",
   230                     (a) -> assertCommandOutputStartsWith(a, "/set feedback xyz",
   231                             "ERROR: Does not match any current feedback mode"),
   231                             "ERROR: Does not match any current feedback mode"),
   232                     (a) -> assertCommandOutputStartsWith(a, "/set format",
   232                     (a) -> assertCommandOutputStartsWith(a, "/set format",
   233                             "ERROR: Expected a feedback mode"),
   233                             "ERROR: Missing the feedback mode"),
   234                     (a) -> assertCommandOutputStartsWith(a, "/set format xyz",
   234                     (a) -> assertCommandOutputStartsWith(a, "/set format xyz",
   235                             "ERROR: Does not match any current feedback mode"),
   235                             "ERROR: Does not match any current feedback mode"),
   236                     (a) -> assertCommandOutputStartsWith(a, "/set format t",
   236                     (a) -> assertCommandOutputStartsWith(a, "/set format t",
   237                             "ERROR: Matches more then one current feedback mode: t"),
   237                             "ERROR: Matches more then one current feedback mode: t"),
   238                     (a) -> assertCommandOutputStartsWith(a, "/set format te",
   238                     (a) -> assertCommandOutputStartsWith(a, "/set format te",
   239                             "ERROR: Expected field name missing"),
   239                             "ERROR: Missing the field name"),
   240                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld",
   240                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld",
   241                             "ERROR: Expected format missing"),
   241                             "ERROR: Expected format missing"),
   242                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld aaa",
   242                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld aaa",
   243                             "ERROR: Format 'aaa' must be quoted"),
   243                             "ERROR: Format 'aaa' must be quoted"),
   244                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' frog",
   244                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' frog",
   253                             "ERROR: Truncation length must be an integer: 20x"),
   253                             "ERROR: Truncation length must be an integer: 20x"),
   254                     (a) -> assertCommandOutputStartsWith(a, "/set trunc te",
   254                     (a) -> assertCommandOutputStartsWith(a, "/set trunc te",
   255                             "ERROR: Expected truncation length"),
   255                             "ERROR: Expected truncation length"),
   256                     (a) -> assertCommandOutputStartsWith(a, "/set truncation te 111 import,added",
   256                     (a) -> assertCommandOutputStartsWith(a, "/set truncation te 111 import,added",
   257                             "ERROR: Different selector kinds in same sections of"),
   257                             "ERROR: Different selector kinds in same sections of"),
   258                     (a) -> assertCommandOutputStartsWith(a, "/set newmode",
   258                     (a) -> assertCommandOutputStartsWith(a, "/set mode",
   259                             "ERROR: Expected new feedback mode"),
   259                             "ERROR: Missing the feedback mode"),
   260                     (a) -> assertCommandOutputStartsWith(a, "/set newmode te",
   260                     (a) -> assertCommandOutputStartsWith(a, "/set mode x -quiet y",
   261                             "ERROR: Expected a new feedback mode name"),
       
   262                     (a) -> assertCommandOutputStartsWith(a, "/set newmode x xyz",
       
   263                             "ERROR: Specify either '-command' or '-quiet'"),
       
   264                     (a) -> assertCommandOutputStartsWith(a, "/set newmode x -quiet y",
       
   265                             "ERROR: Does not match any current feedback mode"),
   261                             "ERROR: Does not match any current feedback mode"),
   266                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   262                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   267                             "ERROR: Expected a feedback mode"),
   263                             "ERROR: Missing the feedback mode"),
   268                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   264                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   269                             "ERROR: Expected format missing"),
   265                             "ERROR: Expected format missing"),
   270                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa xyz",
   266                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa xyz",
   271                             "ERROR: Format 'aaa' must be quoted"),
   267                             "ERROR: Format 'aaa' must be quoted"),
   272                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa' xyz",
   268                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa' xyz",
   273                             "ERROR: Format 'xyz' must be quoted"),
   269                             "ERROR: Format 'xyz' must be quoted"),
   274                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   270                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   275                             "ERROR: Expected a feedback mode"),
   271                             "ERROR: Missing the feedback mode"),
   276                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   272                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   277                             "ERROR: Expected format missing"),
   273                             "ERROR: Expected format missing"),
   278                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa",
   274                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa",
   279                             "ERROR: Format 'aaa' must be quoted"),
   275                             "ERROR: Format 'aaa' must be quoted"),
   280                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa'",
   276                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa'",