本文整理汇总了C#中MatchingPairs.AssertEqual方法的典型用法代码示例。如果您正苦于以下问题:C# MatchingPairs.AssertEqual方法的具体用法?C# MatchingPairs.AssertEqual怎么用?C# MatchingPairs.AssertEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatchingPairs
的用法示例。
在下文中一共展示了MatchingPairs.AssertEqual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Match1
public void Match1()
{
var src1 = @"
int x = 1;
Console.WriteLine(1);
x++/*1A*/;
Console.WriteLine(2);
while (true)
{
x++/*2A*/;
}
Console.WriteLine(1);
";
var src2 = @"
int x = 1;
x++/*1B*/;
for (int i = 0; i < 10; i++) {}
y++;
if (x > 1)
{
while (true)
{
x++/*2B*/;
}
Console.WriteLine(1);
}";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "int x = 1;", "int x = 1;" },
{ "int x = 1", "int x = 1" },
{ "x = 1", "x = 1" },
{ "Console.WriteLine(1);", "Console.WriteLine(1);" },
{ "x++/*1A*/;", "x++/*1B*/;" },
{ "Console.WriteLine(2);", "y++;" },
{ "while (true) { x++/*2A*/; }", "while (true) { x++/*2B*/; }" },
{ "{ x++/*2A*/; }", "{ x++/*2B*/; }" },
{ "x++/*2A*/;", "x++/*2B*/;" }
};
expected.AssertEqual(actual);
}
示例2: MatchLambdas3
public void MatchLambdas3()
{
var src1 = @"
a += async u => u;
";
var src2 = @"
a += u => u;
";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "a += async u => u;", "a += u => u;" },
{ "async u => u", "u => u" }
};
expected.AssertEqual(actual);
}
示例3: MatchLambdas2b
public void MatchLambdas2b()
{
var src1 = @"
F(delegate { return x; });
";
var src2 = @"
F((a) => x, () => x);
";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "F(delegate { return x; });", "F((a) => x, () => x);" },
{ "delegate { return x; }", "() => x" }
};
expected.AssertEqual(actual);
}
示例4: MatchQueries4
public void MatchQueries4()
{
var src1 = "F(from a in await b from x in y select c);";
var src2 = "F(from a in await c from x in y select c);";
var match = GetMethodMatches(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "F(from a in await b from x in y select c);", "F(from a in await c from x in y select c);" },
{ "from a in await b", "from a in await c" },
{ "await b", "await c" },
{ "from x in y select c", "from x in y select c" },
{ "from x in y", "from x in y" },
{ "select c", "select c" }
};
expected.AssertEqual(actual);
}
示例5: KnownMatches
public void KnownMatches()
{
string src1 = @"
Console.WriteLine(1)/*1*/;
Console.WriteLine(1)/*2*/;
";
string src2 = @"
Console.WriteLine(1)/*3*/;
Console.WriteLine(1)/*4*/;
";
var m1 = MakeMethodBody(src1);
var m2 = MakeMethodBody(src2);
var knownMatches = new KeyValuePair<SyntaxNode, SyntaxNode>[]
{
new KeyValuePair<SyntaxNode, SyntaxNode>(m1.Statements[1], m2.Statements[0])
};
// pre-matched:
var match = StatementSyntaxComparer.Default.ComputeMatch(m1, m2, knownMatches);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "Console.WriteLine(1)/*1*/;", "Console.WriteLine(1)/*4*/;" },
{ "Console.WriteLine(1)/*2*/;", "Console.WriteLine(1)/*3*/;" }
};
expected.AssertEqual(actual);
// not pre-matched:
match = StatementSyntaxComparer.Default.ComputeMatch(m1, m2);
actual = ToMatchingPairs(match);
expected = new MatchingPairs
{
{ "Console.WriteLine(1)/*1*/;", "Console.WriteLine(1)/*3*/;" },
{ "Console.WriteLine(1)/*2*/;", "Console.WriteLine(1)/*4*/;" }
};
expected.AssertEqual(actual);
}
示例6: KnownMatches_Root
public void KnownMatches_Root()
{
string src1 = @"
Console.WriteLine(1);
";
string src2 = @"
Console.WriteLine(2);
";
var m1 = MakeMethodBody(src1);
var m2 = MakeMethodBody(src2);
var knownMatches = new[] { new KeyValuePair<SyntaxNode, SyntaxNode>(m1, m2) };
var match = StatementSyntaxComparer.Default.ComputeMatch(m1, m2, knownMatches);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "Console.WriteLine(1);", "Console.WriteLine(2);" }
};
expected.AssertEqual(actual);
}
示例7: MatchQueries2
public void MatchQueries2()
{
var src1 = @"
var q = from c in cars
from ud in users_details
from bd in bids
orderby c.listingOption descending
where a.userID == ud.userid
let images = from ai in auction_images
where ai.belongs_to == c.id
select ai
let bid = (from b in bids
orderby b.id descending
where b.carID == c.id
select b.bidamount).FirstOrDefault()
select bid;
";
var src2 = @"
var q = from c in cars
from ud in users_details
from bd in bids
orderby c.listingOption descending
where a.userID == ud.userid
let images = from ai in auction_images
where ai.belongs_to == c.id2
select ai + 1
let bid = (from b in bids
orderby b.id ascending
where b.carID == c.id2
select b.bidamount).FirstOrDefault()
select bid;
";
var match = GetMethodMatches(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "var q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id select ai let bid = (from b in bids orderby b.id descending where b.carID == c.id select b.bidamount).FirstOrDefault() select bid;",
"var q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id2 select ai + 1 let bid = (from b in bids orderby b.id ascending where b.carID == c.id2 select b.bidamount).FirstOrDefault() select bid;" },
{ "var q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id select ai let bid = (from b in bids orderby b.id descending where b.carID == c.id select b.bidamount).FirstOrDefault() select bid",
"var q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id2 select ai + 1 let bid = (from b in bids orderby b.id ascending where b.carID == c.id2 select b.bidamount).FirstOrDefault() select bid" },
{ "q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id select ai let bid = (from b in bids orderby b.id descending where b.carID == c.id select b.bidamount).FirstOrDefault() select bid",
"q = from c in cars from ud in users_details from bd in bids orderby c.listingOption descending where a.userID == ud.userid let images = from ai in auction_images where ai.belongs_to == c.id2 select ai + 1 let bid = (from b in bids orderby b.id ascending where b.carID == c.id2 select b.bidamount).FirstOrDefault() select bid" },
{ "from c in cars", "from c in cars" },
{ "from ud in users_details", "from ud in users_details" },
{ "from bd in bids", "from bd in bids" },
{ "c.listingOption descending", "c.listingOption descending" },
{ "where a.userID == ud.userid", "where a.userID == ud.userid" },
{ "let images = from ai in auction_images where ai.belongs_to == c.id select ai",
"let images = from ai in auction_images where ai.belongs_to == c.id2 select ai + 1" },
{ "from ai in auction_images", "from ai in auction_images" },
{ "where ai.belongs_to == c.id", "where ai.belongs_to == c.id2" },
{ "select ai", "select ai + 1" },
{ "let bid = (from b in bids orderby b.id descending where b.carID == c.id select b.bidamount).FirstOrDefault()",
"let bid = (from b in bids orderby b.id ascending where b.carID == c.id2 select b.bidamount).FirstOrDefault()" },
{ "from b in bids", "from b in bids" },
{ "b.id descending", "b.id ascending" },
{ "where b.carID == c.id", "where b.carID == c.id2" },
{ "select b.bidamount", "select b.bidamount" },
{ "select bid", "select bid" }
};
expected.AssertEqual(actual);
}
示例8: MatchLambdas7
public void MatchLambdas7()
{
var src1 = @"
F(a =>
{
F(c => /*1*/d);
F((u, v) =>
{
F((w) => c => /*2*/d);
F(p => p);
});
});
";
var src2 = @"
F(a =>
{
F(c => /*1*/d + 1);
F((u, v) =>
{
F((w) => c => /*2*/d + 1);
F(p => p*2);
});
});
";
var matches = GetMethodMatches(src1, src2);
var actual = ToMatchingPairs(matches);
var expected = new MatchingPairs
{
{ "F(a => { F(c => /*1*/d); F((u, v) => { F((w) => c => /*2*/d); F(p => p); }); });",
"F(a => { F(c => /*1*/d + 1); F((u, v) => { F((w) => c => /*2*/d + 1); F(p => p*2); }); });" },
{ "a => { F(c => /*1*/d); F((u, v) => { F((w) => c => /*2*/d); F(p => p); }); }",
"a => { F(c => /*1*/d + 1); F((u, v) => { F((w) => c => /*2*/d + 1); F(p => p*2); }); }" },
{ "{ F(c => /*1*/d); F((u, v) => { F((w) => c => /*2*/d); F(p => p); }); }",
"{ F(c => /*1*/d + 1); F((u, v) => { F((w) => c => /*2*/d + 1); F(p => p*2); }); }" },
{ "F(c => /*1*/d);", "F(c => /*1*/d + 1);" },
{ "c => /*1*/d", "c => /*1*/d + 1" },
{ "F((u, v) => { F((w) => c => /*2*/d); F(p => p); });", "F((u, v) => { F((w) => c => /*2*/d + 1); F(p => p*2); });" },
{ "(u, v) => { F((w) => c => /*2*/d); F(p => p); }", "(u, v) => { F((w) => c => /*2*/d + 1); F(p => p*2); }" },
{ "{ F((w) => c => /*2*/d); F(p => p); }", "{ F((w) => c => /*2*/d + 1); F(p => p*2); }" },
{ "F((w) => c => /*2*/d);", "F((w) => c => /*2*/d + 1);" },
{ "(w) => c => /*2*/d", "(w) => c => /*2*/d + 1" },
{ "c => /*2*/d", "c => /*2*/d + 1" },
{ "F(p => p);", "F(p => p*2);" },
{ "p => p", "p => p*2" }
};
expected.AssertEqual(actual);
}
示例9: IfBlocksWithLocals1
public void IfBlocksWithLocals1()
{
var src1 = @"
if (X)
{
int a = 1;
}
if (Y)
{
int b = 2;
}
";
var src2 = @"
if (Y)
{
int a = 3;
int b = 4;
}
if (X)
{
int b = 5;
}
";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "if (X) { int a = 1; }", "if (Y) { int a = 3; int b = 4; }" },
{ "{ int a = 1; }", "{ int a = 3; int b = 4; }" },
{ "int a = 1;", "int a = 3;" },
{ "int a = 1", "int a = 3" },
{ "a = 1", "a = 3" },
{ "if (Y) { int b = 2; }", "if (X) { int b = 5; }" },
{ "{ int b = 2; }", "{ int b = 5; }" },
{ "int b = 2;", "int b = 5;" },
{ "int b = 2", "int b = 5" },
{ "b = 2", "b = 5" }
};
expected.AssertEqual(actual);
}
示例10: ForEach_Swap1
public void ForEach_Swap1()
{
string src1 = @"foreach (var a in e) { foreach (var b in f) { Foo(); } }";
string src2 = @"foreach (var b in f) { foreach (var a in e) { Foo(); } }";
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
"Move [foreach (var b in f) { Foo(); }]@25 -> @2",
"Move [foreach (var a in e) { foreach (var b in f) { Foo(); } }]@2 -> @25",
"Move [Foo();]@48 -> @48");
var actual = ToMatchingPairs(edits.Match);
var expected = new MatchingPairs
{
{ "foreach (var a in e) { foreach (var b in f) { Foo(); } }", "foreach (var a in e) { Foo(); }" },
{ "{ foreach (var b in f) { Foo(); } }", "{ Foo(); }" },
{ "foreach (var b in f) { Foo(); }", "foreach (var b in f) { foreach (var a in e) { Foo(); } }" },
{ "{ Foo(); }", "{ foreach (var a in e) { Foo(); } }" },
{ "Foo();", "Foo();" }
};
expected.AssertEqual(actual);
}
示例11: MatchExceptionHandlers
public void MatchExceptionHandlers()
{
var src1 = @"
try { throw new InvalidOperationException(1); }
catch (IOException e) when (filter(e)) { Console.WriteLine(2); }
catch (Exception e) when (filter(e)) { Console.WriteLine(3); }
";
var src2 = @"
try { throw new InvalidOperationException(10); }
catch (IOException e) when (filter(e)) { Console.WriteLine(20); }
catch (Exception e) when (filter(e)) { Console.WriteLine(30); }
";
var match = GetMethodMatches(src1, src2, kind: MethodKind.Regular);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "try { throw new InvalidOperationException(1); } catch (IOException e) when (filter(e)) { Console.WriteLine(2); } catch (Exception e) when (filter(e)) { Console.WriteLine(3); }", "try { throw new InvalidOperationException(10); } catch (IOException e) when (filter(e)) { Console.WriteLine(20); } catch (Exception e) when (filter(e)) { Console.WriteLine(30); }" },
{ "{ throw new InvalidOperationException(1); }", "{ throw new InvalidOperationException(10); }" },
{ "throw new InvalidOperationException(1);", "throw new InvalidOperationException(10);" },
{ "catch (IOException e) when (filter(e)) { Console.WriteLine(2); }", "catch (IOException e) when (filter(e)) { Console.WriteLine(20); }" },
{ "(IOException e)", "(IOException e)" },
{ "when (filter(e))", "when (filter(e))" },
{ "{ Console.WriteLine(2); }", "{ Console.WriteLine(20); }" },
{ "Console.WriteLine(2);", "Console.WriteLine(20);" },
{ "catch (Exception e) when (filter(e)) { Console.WriteLine(3); }", "catch (Exception e) when (filter(e)) { Console.WriteLine(30); }" },
{ "(Exception e)", "(Exception e)" },
{ "when (filter(e))", "when (filter(e))" },
{ "{ Console.WriteLine(3); }", "{ Console.WriteLine(30); }" },
{ "Console.WriteLine(3);", "Console.WriteLine(30);" }
};
expected.AssertEqual(actual);
}
示例12: MatchConstructorWithInitializer2
public void MatchConstructorWithInitializer2()
{
var src1 = @"
() : base(a => a + 1) { Console.WriteLine(1); }
";
var src2 = @"
() { Console.WriteLine(1); }
";
var match = GetMethodMatches(src1, src2, kind: MethodKind.ConstructorWithParameters);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "{ Console.WriteLine(1); }", "{ Console.WriteLine(1); }" },
{ "Console.WriteLine(1);", "Console.WriteLine(1);" }
};
expected.AssertEqual(actual);
}
示例13: MatchQueries5
public void MatchQueries5()
{
var src1 = "F(from a in b group a by a.x into g select g);";
var src2 = "F(from a in b group z by z.y into h select h);";
var match = GetMethodMatches(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "F(from a in b group a by a.x into g select g);", "F(from a in b group z by z.y into h select h);" },
{ "from a in b", "from a in b" },
{ "group a by a.x into g select g", "group z by z.y into h select h" },
{ "group a by a.x", "group z by z.y" },
{ "into g select g", "into h select h" },
{ "select g", "select h" },
{ "select g", "select h" }
};
expected.AssertEqual(actual);
}
示例14: MatchLambdas4
public void MatchLambdas4()
{
var src1 = @"
foreach (var a in z)
{
var e = from q in a.Where(l => l > 10) select q + 1;
}
";
var src2 = @"
foreach (var a in z)
{
var e = from q in a.Where(l => l < 0) select q + 1;
}
";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "foreach (var a in z) { var e = from q in a.Where(l => l > 10) select q + 1; }", "foreach (var a in z) { var e = from q in a.Where(l => l < 0) select q + 1; }" },
{ "{ var e = from q in a.Where(l => l > 10) select q + 1; }", "{ var e = from q in a.Where(l => l < 0) select q + 1; }" },
{ "var e = from q in a.Where(l => l > 10) select q + 1;", "var e = from q in a.Where(l => l < 0) select q + 1;" },
{ "var e = from q in a.Where(l => l > 10) select q + 1", "var e = from q in a.Where(l => l < 0) select q + 1" },
{ "e = from q in a.Where(l => l > 10) select q + 1", "e = from q in a.Where(l => l < 0) select q + 1" },
{ "from q in a.Where(l => l > 10)", "from q in a.Where(l => l < 0)" },
{ "select q + 1", "select q + 1" }
};
expected.AssertEqual(actual);
}
示例15: BlocksWithLocals2
public void BlocksWithLocals2()
{
var src1 = @"
{
int a = 1;
}
{
{
int b = 2;
}
}
";
var src2 = @"
{
int b = 1;
}
{
{
int a = 2;
}
}
";
var match = GetMethodMatch(src1, src2);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs
{
{ "{ int a = 1; }", "{ int a = 2; }" },
{ "int a = 1;", "int a = 2;" },
{ "int a = 1", "int a = 2" },
{ "a = 1", "a = 2" },
{ "{ { int b = 2; } }", "{ { int a = 2; } }" },
{ "{ int b = 2; }", "{ int b = 1; }" },
{ "int b = 2;", "int b = 1;" },
{ "int b = 2", "int b = 1" },
{ "b = 2", "b = 1" }
};
expected.AssertEqual(actual);
}