Skip to content

Commit

Permalink
Add regression test for issue dotnet#731
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinCampbell committed Jan 7, 2017
1 parent 212e5b7 commit ff5455a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
3 changes: 3 additions & 0 deletions syntaxes/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ repository:
match: \.

preprocessor:
name: meta.preprocessor.cs
begin: ^\s*(\#)\s*
beginCaptures:
'1': { name: punctuation.separator.hash.cs }
Expand Down Expand Up @@ -1738,11 +1739,13 @@ repository:
captures:
'1': { name: keyword.preprocessor.warning.cs }
'2': { name: keyword.preprocessor.error.cs }
'3': { name: string.unquoted.preprocessor.message.cs }

preprocessor-region:
match: \b(region)\b\s*(.*)(?=$)
captures:
'1': { name: keyword.preprocessor.region.cs }
'2': { name: string.unquoted.preprocessor.message.cs }

preprocessor-endregion:
match: \b(endregion)\b
Expand Down
57 changes: 56 additions & 1 deletion test/syntaxes/preprocessor.test.syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ describe("Grammar", () => {
tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.Warning,
Token.PreprocessorMessage("This is a warning")
]);
});

Expand All @@ -473,6 +474,7 @@ describe("Grammar", () => {
tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.Error,
Token.PreprocessorMessage("This is an error")
]);
});

Expand All @@ -483,6 +485,7 @@ describe("Grammar", () => {
tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.Region,
Token.PreprocessorMessage("My Region")
]);
});

Expand All @@ -493,6 +496,7 @@ describe("Grammar", () => {
tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.Region,
Token.PreprocessorMessage("\"My Region\"")
]);
});

Expand All @@ -502,7 +506,7 @@ describe("Grammar", () => {

tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.EndRegion,
Token.Keywords.Preprocessor.EndRegion
]);
});

Expand All @@ -529,5 +533,56 @@ describe("Grammar", () => {
Token.Comment.SingleLine.Text("Foo")
]);
});

it("region name with double-quotes should be highlighted properly (issue #731)", () => {
const input = Input.InClass(`
#region " Register / Create New "
// GET: /Account/Register
[Authorize(Roles = UserRoles.SuperUser)]
public ActionResult Register()
{
RedirectToAction("Application");
return View();
}
`);
const tokens = tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keywords.Preprocessor.Region,
Token.PreprocessorMessage("\" Register / Create New \""),
Token.Comment.SingleLine.Start,
Token.Comment.SingleLine.Text(" GET: /Account/Register"),
Token.Punctuation.OpenBracket,
Token.Type("Authorize"),
Token.Punctuation.OpenParen,
Token.Identifiers.PropertyName("Roles"),
Token.Operators.Assignment,
Token.Variables.Object("UserRoles"),
Token.Punctuation.Accessor,
Token.Variables.Property("SuperUser"),
Token.Punctuation.CloseParen,
Token.Punctuation.CloseBracket,
Token.Keywords.Modifiers.Public,
Token.Type("ActionResult"),
Token.Identifiers.MethodName("Register"),
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Punctuation.OpenBrace,
Token.Identifiers.MethodName("RedirectToAction"),
Token.Punctuation.OpenParen,
Token.Punctuation.String.Begin,
Token.Literals.String("Application"),
Token.Punctuation.String.End,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,
Token.Keywords.Return,
Token.Identifiers.MethodName("View"),
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,
Token.Punctuation.CloseBrace
]);
});
});
});
3 changes: 2 additions & 1 deletion test/syntaxes/utils/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ITokenizeLineResult, Registry, StackElement } from 'vscode-textmate';

const registry = new Registry();
const grammar = registry.loadGrammarFromPathSync('syntaxes/csharp.tmLanguage');
const excludedTypes = ['source.cs', 'meta.interpolation.cs', 'meta.type.parameters.cs']
const excludedTypes = ['source.cs', 'meta.interpolation.cs', 'meta.preprocessor.cs', 'meta.type.parameters.cs']

export function tokenize(input: string | Input, excludeTypes: boolean = true): Token[] {
if (typeof input === "string") {
Expand Down Expand Up @@ -390,5 +390,6 @@ export namespace Token {
}

export const IllegalNewLine = (text: string) => createToken(text, 'invalid.illegal.newline.cs');
export const PreprocessorMessage = (text: string) => createToken(text, 'string.unquoted.preprocessor.message.cs');
export const Type = (text: string) => createToken(text, 'storage.type.cs');
}

0 comments on commit ff5455a

Please sign in to comment.