/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/EditorFeatures/CSharpTest/Extensions/SyntaxTreeExtensionsTests.cs
80 строк
2 KB
Cyrus Najmabadi
Make sealed
26 мар 2025, 22:21
26 мар 2025, 22:21
d99b771
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System.Threading; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Extensions; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Extensions; public sealed class SyntaxTreeExtensionsTests { private static void VerifyWholeLineIsActive(SyntaxTree tree, int lineNumber) { var line = tree.GetText().Lines[lineNumber]; for (var pos = line.Start; pos < line.EndIncludingLineBreak; pos++) { Assert.False(tree.IsInInactiveRegion(pos, CancellationToken.None)); } } private static void VerifyWholeLineIsInactive(SyntaxTree tree, int lineNumber) { var line = tree.GetText().Lines[lineNumber]; for (var pos = line.Start; pos < line.EndIncludingLineBreak; pos++) { Assert.True(tree.IsInInactiveRegion(pos, CancellationToken.None)); } } [Fact] public void SimpleInactive() { var code = """ #if false This is inactive #else // This is active #endif """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); VerifyWholeLineIsInactive(tree, 1); VerifyWholeLineIsActive(tree, 2); VerifyWholeLineIsActive(tree, 3); VerifyWholeLineIsActive(tree, 4); } [Fact] public void InactiveEof() { var code = """ #if false This is inactive """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); VerifyWholeLineIsInactive(tree, 1); } [Fact] public void InactiveEof2() { var code = """ #if false This is inactive #endif // This is active """; var tree = CSharpSyntaxTree.ParseText(code); VerifyWholeLineIsActive(tree, 0); VerifyWholeLineIsInactive(tree, 1); VerifyWholeLineIsActive(tree, 2); VerifyWholeLineIsActive(tree, 3); } }