Download PowerShell-master/test/xUnit/csharp/test_AstDefaultVisit.cs from MegaBites-AI/Windows-powershell: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/xUnit/csharp/test_AstDefaultVisit.cs
- Command line
-
hf download hf://datasets/MegaBites-AI/Windows-powershell/PowerShell-master/test/xUnit/csharp/test_AstDefaultVisit.cs
-
curl -L -o test_AstDefaultVisit.cs https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/xUnit/csharp/test_AstDefaultVisit.cs
2.03 kB
| // Copyright (c) Microsoft Corporation. | |
| // Licensed under the MIT License. | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Management.Automation.Language; | |
| using Xunit; | |
| namespace PSTests.Parallel | |
| { | |
| internal sealed class MyICustomAstVisitor2 : ICustomAstVisitor2 | |
| { | |
| public object DefaultVisit(Ast ast) => ast.GetType().Name; | |
| } | |
| internal sealed class MyDefaultCustomAstVisitor2 : DefaultCustomAstVisitor2 | |
| { | |
| public override object DefaultVisit(Ast ast) => ast.GetType().Name; | |
| } | |
| internal sealed class MyAstVisitor2 : AstVisitor2 | |
| { | |
| public List<string> Commands { get; } | |
| public MyAstVisitor2() | |
| { | |
| Commands = new List<string>(); | |
| } | |
| public override AstVisitAction DefaultVisit(Ast ast) | |
| { | |
| if (ast is CommandAst commandAst && commandAst.CommandElements[0] is StringConstantExpressionAst str) | |
| { | |
| Commands.Add(str.Value); | |
| } | |
| return AstVisitAction.Continue; | |
| } | |
| } | |
| public static class AstDefaultVisitTests | |
| { | |
| [] | |
| public static void TestCustomAstVisitor() | |
| { | |
| var ast = Parser.ParseInput("a | b", out _, out _); | |
| var expected = nameof(NamedBlockAst); | |
| var myVisitor1 = new MyICustomAstVisitor2(); | |
| var result1 = ast.EndBlock.Accept(myVisitor1); | |
| Assert.Equal(expected, result1); | |
| var myVisitor2 = new MyDefaultCustomAstVisitor2(); | |
| var result2 = ast.EndBlock.Accept(myVisitor2); | |
| Assert.Equal(expected, result2); | |
| } | |
| [] | |
| public static void TestAstVisitor() | |
| { | |
| var ast = Parser.ParseInput("a | b", out _, out _); | |
| var myVisitor = new MyAstVisitor2(); | |
| ast.Visit(myVisitor); | |
| Assert.Equal(2, myVisitor.Commands.Count); | |
| Assert.Equal("a", myVisitor.Commands[0]); | |
| Assert.Equal("b", myVisitor.Commands[1]); | |
| } | |
| } | |
| } | |