Highlight { public String matches(String text) { text = matches(text, flags); text = matches(text, code); return text; } Highlight(final List<Option> options); String highlight(String text); String matches(String text);  }
@Test public void highlightFlags() { final List<Option> options = new ArrayList<>(); options.add(new Option("--assignee, -a=<String[]>", null)); options.add(new Option("--body, -b=<String>", null)); options.add(new Option("--body-formatter, -g=<String>", null)); options.add(new Option("--assign", null)); options.add(new Option("--file, -f=<File>", null)); options.add(new Option("--a", null)); final Highlight highlight = new Highlight(options); assertEquals("\u001B[0m\u001B[1m--assignee\u001B[0m", highlight.matches("--assignee")); assertEquals("the flags --ab and --body-wash are not valid", highlight.matches("the flags --ab and --body-wash are not valid")); assertEquals("the flags " + "\u001B[0m\u001B[1m-a\u001B[0m and " + "\u001B[0m\u001B[1m-b\u001B[0m are " + "valid but -file and --body-double are not", highlight.matches("the flags -a and -b are valid but -file and --body-double are not")); assertEquals("foo \u001B[0m\u001B[1m--assignee\u001B[0m" + " bar baz \u001B[0m\u001B[1m--a\u001B[0m" + " and \u001B[0m\u001B[1m--file\u001B[0m" + " with a \u001B[0m\u001B[1m--body\u001B[0m" + " and \u001B[0m\u001B[1m--body-formatter\u001B[0m" + " and --body-nothing and \u001B[0m\u001B[1m--a\u001B[0m", highlight.matches("foo --assignee bar baz --a and " + "--file with a --body and --body-formatter and --body-nothing and --a")); }
@Test public void highlightCode() { final List<Option> options = new ArrayList<>(); options.add(new Option("--assignee, -a=<String[]>", null)); options.add(new Option("--body, -b=<String>", null)); final Highlight highlight = new Highlight(options); assertEquals("send a " + "\u001B[0m\u001B[1mGET\u001B[0m request to " + "\u001B[0m\u001B[1m/some/place\u001B[0m", highlight.matches("send a `GET` request to `/some/place`")); }
@Test public void highlightBoth() { final List<Option> options = new ArrayList<>(); options.add(new Option("--assignee, -a=<String[]>", null)); options.add(new Option("--body, -b=<String>", null)); final Highlight highlight = new Highlight(options); assertEquals("send a " + "\u001B[0m\u001B[1mGET\u001B[0m request to " + "\u001B[0m\u001B[1m/some/place\u001B[0m with " + "\u001B[0m\u001B[1m--body\u001B[0m pointing to a json file", highlight.matches("send a `GET` request to `/some/place` with --body pointing to a json file")); }
@Test public void dontDoubleHighlight() { final List<Option> options = new ArrayList<>(); options.add(new Option("--assignee, -a=<String[]>", null)); options.add(new Option("--body, -b=<String>", null)); final Highlight highlight = new Highlight(options); assertEquals("use " + "\u001B[0m\u001B[1m--body\u001B[0m" + " to point to a json file", highlight.matches("use `--body` to point to a json file")); assertEquals("use \u001B[0m\u001B[1m--body=false\u001B[0m when in doubt", highlight.matches("use `--body=false` when in doubt")); }