Skip to content

Commit

Permalink
Add tests for with expression
Browse files Browse the repository at this point in the history
  • Loading branch information
wise0704 committed Aug 1, 2023
1 parent 5757be9 commit 72355c0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/expressions.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> { 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,
]);
});
});
});
});
1 change: 1 addition & 0 deletions test/utils/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 72355c0

Please sign in to comment.