Skip to content

Commit 92b428c

Browse files
committed
Add tests for #291 and #292
1 parent 6ec3512 commit 92b428c

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

test/expressions.tests.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,118 @@ var outObjectsToKeep = allOutObjects.Where(outObject => outObject.ShouldKeep);`)
11561156
Token.Punctuation.Semicolon,
11571157
]);
11581158
});
1159+
1160+
it("lambda expression with initializer expression (issue #291)", async () => {
1161+
const input = Input.InMethod(`
1162+
var x = list.Select(item => new Foo()
1163+
{
1164+
Key = item.Name,
1165+
Value = item.Text,
1166+
});`);
1167+
const tokens = await tokenize(input);
1168+
1169+
tokens.should.deep.equal([
1170+
Token.Keyword.Definition.Var,
1171+
Token.Identifier.LocalName("x"),
1172+
Token.Operator.Assignment,
1173+
Token.Variable.Object("list"),
1174+
Token.Punctuation.Accessor,
1175+
Token.Identifier.MethodName("Select"),
1176+
Token.Punctuation.OpenParen,
1177+
Token.Identifier.ParameterName("item"),
1178+
Token.Operator.Arrow,
1179+
Token.Operator.Expression.New,
1180+
Token.Type("Foo"),
1181+
Token.Punctuation.OpenParen,
1182+
Token.Punctuation.CloseParen,
1183+
Token.Punctuation.OpenBrace,
1184+
Token.Variable.ReadWrite("Key"),
1185+
Token.Operator.Assignment,
1186+
Token.Variable.Object("item"),
1187+
Token.Punctuation.Accessor,
1188+
Token.Variable.Property("Name"),
1189+
Token.Punctuation.Comma,
1190+
Token.Variable.ReadWrite("Value"),
1191+
Token.Operator.Assignment,
1192+
Token.Variable.Object("item"),
1193+
Token.Punctuation.Accessor,
1194+
Token.Variable.Property("Text"),
1195+
Token.Punctuation.Comma,
1196+
Token.Punctuation.CloseBrace,
1197+
Token.Punctuation.CloseParen,
1198+
Token.Punctuation.Semicolon,
1199+
]);
1200+
});
1201+
1202+
it("lambda expression with comments (issue #292)", async () => {
1203+
const input = Input.InMethod(`
1204+
_ = (int a, int b /*comment*/) => /*comment*/ { };
1205+
_ = (a, b /*comment*/) => /*comment*/ { };`);
1206+
const tokens = await tokenize(input);
1207+
1208+
tokens.should.deep.equal([
1209+
Token.Variable.ReadWrite("_"),
1210+
Token.Operator.Assignment,
1211+
Token.Punctuation.OpenParen,
1212+
Token.PrimitiveType.Int,
1213+
Token.Identifier.ParameterName("a"),
1214+
Token.Punctuation.Comma,
1215+
Token.PrimitiveType.Int,
1216+
Token.Identifier.ParameterName("b"),
1217+
Token.Comment.MultiLine.Start,
1218+
Token.Comment.MultiLine.Text("comment"),
1219+
Token.Comment.MultiLine.End,
1220+
Token.Punctuation.CloseParen,
1221+
Token.Operator.Arrow,
1222+
Token.Comment.MultiLine.Start,
1223+
Token.Comment.MultiLine.Text("comment"),
1224+
Token.Comment.MultiLine.End,
1225+
Token.Punctuation.OpenBrace,
1226+
Token.Punctuation.CloseBrace,
1227+
Token.Punctuation.Semicolon,
1228+
1229+
Token.Variable.ReadWrite("_"),
1230+
Token.Operator.Assignment,
1231+
Token.Punctuation.OpenParen,
1232+
Token.Identifier.ParameterName("a"),
1233+
Token.Punctuation.Comma,
1234+
Token.Identifier.ParameterName("b"),
1235+
Token.Comment.MultiLine.Start,
1236+
Token.Comment.MultiLine.Text("comment"),
1237+
Token.Comment.MultiLine.End,
1238+
Token.Punctuation.CloseParen,
1239+
Token.Operator.Arrow,
1240+
Token.Comment.MultiLine.Start,
1241+
Token.Comment.MultiLine.Text("comment"),
1242+
Token.Comment.MultiLine.End,
1243+
Token.Punctuation.OpenBrace,
1244+
Token.Punctuation.CloseBrace,
1245+
Token.Punctuation.Semicolon,
1246+
]);
1247+
});
1248+
1249+
it("anonymous method with comments (issue #292)", async () => {
1250+
const input = Input.InMethod(`
1251+
_ = delegate /*comment*/ () /*comment*/ { };`);
1252+
const tokens = await tokenize(input);
1253+
1254+
tokens.should.deep.equal([
1255+
Token.Variable.ReadWrite("_"),
1256+
Token.Operator.Assignment,
1257+
Token.Keyword.Definition.Delegate,
1258+
Token.Comment.MultiLine.Start,
1259+
Token.Comment.MultiLine.Text("comment"),
1260+
Token.Comment.MultiLine.End,
1261+
Token.Punctuation.OpenParen,
1262+
Token.Punctuation.CloseParen,
1263+
Token.Comment.MultiLine.Start,
1264+
Token.Comment.MultiLine.Text("comment"),
1265+
Token.Comment.MultiLine.End,
1266+
Token.Punctuation.OpenBrace,
1267+
Token.Punctuation.CloseBrace,
1268+
Token.Punctuation.Semicolon,
1269+
]);
1270+
});
11591271
});
11601272

11611273
describe("Anonymous Objects", () => {

0 commit comments

Comments
 (0)