diff --git a/test/expressions.tests.ts b/test/expressions.tests.ts index df3f382..e858b11 100644 --- a/test/expressions.tests.ts +++ b/test/expressions.tests.ts @@ -4822,5 +4822,65 @@ select x.Key1;`); ]); }); }); + + describe("With expression", () => { + it("single line", async () => { + const input = Input.InMethod(`var p2 = p1 with { X = 5 };`); + const tokens = await tokenize(input); + + tokens.should.deep.equal([ + Token.Keywords.Var, + Token.Identifiers.LocalName("p2"), + Token.Operators.Assignment, + Token.Variables.ReadWrite("p1"), + Token.Keywords.With, + Token.Punctuation.OpenBrace, + Token.Variables.ReadWrite("X"), + Token.Operators.Assignment, + Token.Literals.Numeric.Decimal("5"), + Token.Punctuation.CloseBrace, + Token.Punctuation.Semicolon, + ]); + }); + + it("multiple lines", async () => { + const input = Input.InMethod(` +var p2 = p1 with +{ + X = 5, // comment + Y = new List { 0, 1 } +};`); + const tokens = await tokenize(input); + + tokens.should.deep.equal([ + Token.Keywords.Var, + Token.Identifiers.LocalName("p2"), + Token.Operators.Assignment, + Token.Variables.ReadWrite("p1"), + Token.Keywords.With, + Token.Punctuation.OpenBrace, + Token.Variables.ReadWrite("X"), + Token.Operators.Assignment, + Token.Literals.Numeric.Decimal("5"), + Token.Punctuation.Comma, + Token.Comment.SingleLine.Start, + Token.Comment.SingleLine.Text(" comment"), + Token.Variables.ReadWrite("Y"), + Token.Operators.Assignment, + Token.Keywords.New, + Token.Type("List"), + Token.Punctuation.TypeParameters.Begin, + Token.PrimitiveType.Int, + Token.Punctuation.TypeParameters.End, + Token.Punctuation.OpenBrace, + Token.Literals.Numeric.Decimal("0"), + Token.Punctuation.Comma, + Token.Literals.Numeric.Decimal("1"), + Token.Punctuation.CloseBrace, + Token.Punctuation.CloseBrace, + Token.Punctuation.Semicolon, + ]); + }); + }); }); }); diff --git a/test/utils/tokenize.ts b/test/utils/tokenize.ts index 26aa5d6..68729fa 100644 --- a/test/utils/tokenize.ts +++ b/test/utils/tokenize.ts @@ -368,6 +368,7 @@ export namespace Token { export const Using = createToken('using', 'keyword.other.using.cs'); export const Var = createToken('var', 'keyword.other.var.cs'); export const Where = createToken('where', 'keyword.other.where.cs'); + export const With = createToken('with', 'keyword.other.with.cs'); } export namespace Literals {