TestExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Runtime.CompilerServices;
  5. using System.Threading;
  6. using Xunit;
  7. namespace System.Linq.Expressions.Tests
  8. {
  9. public static class CompilerTests
  10. {
  11. public static void VerifyIL(this LambdaExpression expression, string expected, bool appendInnerLambdas = false)
  12. {
  13. string actual = expression.GetIL(appendInnerLambdas);
  14. string nExpected = Normalize(expected);
  15. string nActual = Normalize(actual);
  16. Assert.Equal(nExpected, nActual);
  17. }
  18. private static string Normalize(string s)
  19. {
  20. Collections.Generic.IEnumerable<string> lines =
  21. s
  22. .Replace("\r\n", "\n")
  23. .Split(new[] { '\n' })
  24. .Select(line => line.Trim())
  25. .Where(line => line != "" && !line.StartsWith("//"));
  26. return string.Join("\n", lines);
  27. }
  28. }
  29. }