@Test public void ControlCharTest() throws Exception { String input = "\\cC"; String expectedOutput = "C"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.ControlChar)); assertThat(token.getText(), is(expectedOutput)); input = "\\cX"; expectedOutput = "X"; token = getToken(input); assertThat(token.getType(), is(PCRELexer.ControlChar)); assertThat(token.getText(), is(expectedOutput)); }
@Test public void NotWordCharTest() throws Exception { String input = "\\W"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NotWordChar)); }
@Test public void NotVerticalWhiteSpaceTest() throws Exception { String input = "\\V"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NotVerticalWhiteSpace)); }
@Test public void NewLineSequenceTest() throws Exception { String input = "\\R"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NewLineSequence)); }
@Test public void NotDecimalDigitTest() throws Exception { String input = "\\D"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NotDecimalDigit)); }
@Test public void ExtendedUnicodeCharTest() throws Exception { String input = "\\X"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.ExtendedUnicodeChar)); }
@Test public void PreviousMatchInSubjectTest() throws Exception { String input = "\\G"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.PreviousMatchInSubject)); }
@Test public void ResetStartMatchTest() throws Exception { String input = "\\K"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.ResetStartMatch)); }
private int getStringOrCommentIndent(int offset) { CommonToken tokenContainingOffset = getTokenStrictlyContainingOffset(offset); CommonToken token = getStartOfStringToken(tokenContainingOffset); if (token != null) { int type = token.getType(); int start = token.getCharPositionInLine(); if (token.getStartIndex() < offset) { switch (type) { case STRING_LITERAL: case STRING_START: case ASTRING_LITERAL: return start + 1; case STRING_MID: case STRING_END: case MULTI_COMMENT: return start + 1; // uncomment to get a bigger indent // return start+3; case VERBATIM_STRING: case AVERBATIM_STRING: return start + 3; } } } return -1; }
@Test public void OneDataUnitTest() throws Exception { String input = "\\C"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.OneDataUnit)); }
@Test public void EndOfSubjectTest() throws Exception { String input = "\\z"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.EndOfSubject)); }
private String getExtraIndent(CommonToken token) { String extraIndent = ""; switch (token.getType()) { case MULTI_COMMENT: // uncomment to get a bigger indent // if (document.getLineOfOffset(command.offset) < // document.getLineOfOffset(token.getStopIndex())) { // extraIndent=" "; // } // else { extraIndent = " "; // } break; case STRING_MID: case STRING_END: extraIndent = " "; break; case STRING_LITERAL: case ASTRING_LITERAL: case STRING_START: extraIndent = " "; break; case VERBATIM_STRING: case AVERBATIM_STRING: extraIndent = " "; break; } return extraIndent; }
@Test public void NonWordBoundaryTest() throws Exception { String input = "\\B"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NonWordBoundary)); }
@Test public void VUCTest() throws Exception { String input = "V"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.VUC)); assertThat(token.getText(), is(input)); }
@Test public void CharWithoutPropertyTest() throws Exception { for (String property : PCRELexer.propertySet) { CommonToken token = getToken(String.format("\\P{%s}", property)); assertThat(token.getType(), is(PCRELexer.CharWithoutProperty)); } }
@Test public void AmpersandTest() throws Exception { String input = "&"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.Ampersand)); assertThat(token.getText(), is(input)); }
@Test public void UnderscoreTest() throws Exception { String input = "_"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.Underscore)); assertThat(token.getText(), is(input)); }
@Test public void SingleQuoteTest() throws Exception { String input = "'"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.SingleQuote)); assertThat(token.getText(), is(input)); }
@Test public void GreaterThanTest() throws Exception { String input = ">"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.GreaterThan)); assertThat(token.getText(), is(input)); }
@Test public void POSIXNegatedNamedSetTest() throws Exception { for (String name : PCRELexer.namedSet) { CommonToken token = getToken(String.format("[[:^%s:]]", name)); assertThat(token.getType(), is(PCRELexer.POSIXNegatedNamedSet)); } }
@Test public void SubroutineOrNamedReferenceStartGTest() throws Exception { String input = "\\g"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.SubroutineOrNamedReferenceStartG)); assertThat(token.getText(), is(input)); }
@Test public void OpenBraceTest() throws Exception { String input = "{"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.OpenBrace)); assertThat(token.getText(), is(input)); }
@Test public void QuestionMarkTest() throws Exception { String input = "?"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.QuestionMark)); assertThat(token.getText(), is(input)); }
@Test public void NamedReferenceStartKTest() throws Exception { String input = "\\k"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.NamedReferenceStartK)); assertThat(token.getText(), is(input)); }
private int getTokenTypeOfCharacterAtOffset(int offset) { int tokenIndex = getTokenIndexAtCharacter(tokens, offset); if (tokenIndex >= 0) { CommonToken token = tokens.get(tokenIndex); return token.getType(); } return -1; }
@Test public void CloseParenTest() throws Exception { String input = ")"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.CloseParen)); assertThat(token.getText(), is(input)); }
private CommonToken getStartOfStringToken(CommonToken token) { if (token == null) { return null; } int type = token.getType(); if (type == STRING_MID || type == STRING_END) { while (type != STRING_START) { int index = token.getTokenIndex(); if (index == 0) { return null; } token = tokens.get(index - 1); type = token.getType(); } } return token; }
@Test public void CharacterClassEndTest() throws Exception { String input = "]"; CommonToken token = getToken(input); assertThat(token.getType(), is(PCRELexer.CharacterClassEnd)); assertThat(token.getText(), is(input)); }
private boolean isInheritanceClause(CommonToken t) { if (t == null) return false; int tt = t.getType(); return tt == CeylonLexer.EXTENDS || tt == CeylonLexer.CASE_TYPES || tt == CeylonLexer.TYPE_CONSTRAINT || tt == CeylonLexer.SATISFIES; }
@Test public void BackslashTest() throws Exception { CommonToken token = getToken("\\"); assertThat(token.getType(), is(PCRELexer.Backslash)); assertThat(token.getText(), is("\\")); }