private void SetUp()
 {
     _fromNode = new Node();
     _toNode   = new Node();
     _diff     = new NodeDiff(null);
     _redoDiff = new NodeDiff(null);
 }
Exemplo n.º 2
0
 private static string PrintDiffs(IEnumerable <IDiff> diffs)
 {
     return(string.Join(Environment.NewLine, diffs.Select((x, i) =>
     {
         var diffText = x switch
         {
             NodeDiff diff when diff.Target == DiffTarget.Text && diff.Control.Path.Equals(diff.Test.Path, StringComparison.Ordinal)
             => $"The text in {diff.Control.Path} is different.",
             NodeDiff diff when diff.Target == DiffTarget.Text
             => $"The expected {diff.Control.NodeName()} at {diff.Control.Path} and the actual {diff.Test.NodeName()} at {diff.Test.Path} is different.",
             NodeDiff diff when diff.Control.Path.Equals(diff.Test.Path, StringComparison.Ordinal)
             => $"The {diff.Control.NodeName()}s at {diff.Control.Path} are different.",
             NodeDiff diff => $"The expected {diff.Control.NodeName()} at {diff.Control.Path} and the actual {diff.Test.NodeName()} at {diff.Test.Path} are different.",
             AttrDiff diff when diff.Control.Path.Equals(diff.Test.Path, StringComparison.Ordinal)
             => $"The values of the attributes at {diff.Control.Path} are different.",
             AttrDiff diff => $"The value of the attribute {diff.Control.Path} and actual attribute {diff.Test.Path} are different.",
             MissingNodeDiff diff => $"The {diff.Control.NodeName()} at {diff.Control.Path} is missing.",
             MissingAttrDiff diff => $"The attribute at {diff.Control.Path} is missing.",
             UnexpectedNodeDiff diff => $"The {diff.Test.NodeName()} at {diff.Test.Path} was not expected.",
             UnexpectedAttrDiff diff => $"The attribute at {diff.Test.Path} was not expected.",
             _ => throw new InvalidOperationException($"Unknown diff type detected: {x.GetType()}")
         };
         return $"  {i + 1}: {diffText}";
     })) + Environment.NewLine);
 }
        private SyntaxNode ComputeTernaryOperator(NodeDiff <ExpressionSyntax> diffNode)
        {
            var condition = _if.Condition;

            if (!(condition is ParenthesizedExpressionSyntax))
            {
                condition = ParenthesizedExpression(condition);
            }

            return(ParenthesizedExpression(ConditionalExpression(condition, diffNode.First, diffNode.Second)));
        }
        public void ModifyInteegr()
        {
            SetUp();

            _fromNode.Set <IntegerInterpreter>().Value = 2;
            _toNode.Set <IntegerInterpreter>().Value   = 3;

            var fromSerialTree = Document.ReflectTreeMirror(_fromNode);
            var toSerialTree   = Document.ReflectTreeMirror(_toNode);

            NodeDiff.ComputeDiff(fromSerialTree, toSerialTree, _diff, _redoDiff);

            Assert.AreEqual(_diff.ModifiedAttributeData.Count, 1);
            Assert.AreEqual(_redoDiff.ModifiedAttributeData.Count, 1);
        }
        public void OneNode()
        {
            SetUp();
            _toNode.AddNewChild();

            Assert.AreEqual(_diff.RemovedNodes.Count, 0);
            Assert.AreEqual(_redoDiff.Children.Count, 0);

            var fromSerialTree = Document.ReflectTreeMirror(_fromNode);
            var toSerialTree   = Document.ReflectTreeMirror(_toNode);

            NodeDiff.ComputeDiff(fromSerialTree, toSerialTree, _diff, _redoDiff);

            Assert.AreEqual(_diff.RemovedNodes.Count, 1);
            Assert.AreEqual(_redoDiff.Children.Count, 1);
        }
Exemplo n.º 6
0
        public override async Task <int> ExecuteAsync()
        {
            try
            {
                IEnumerable <DependencyDetail> rootDependencies = null;
                DependencyGraph graph;
                RemoteFactory   remoteFactory = new RemoteFactory(_options);

                if (!_options.Local)
                {
                    NodeDiff diffOption = NodeDiff.None;
                    // Check node diff options
                    switch (_options.DeltaFrom.ToLowerInvariant())
                    {
                    case "none":
                        break;

                    case "newest-in-channel":
                        diffOption = NodeDiff.LatestInChannel;
                        break;

                    case "newest-in-graph":
                        diffOption = NodeDiff.LatestInGraph;
                        break;

                    default:
                        Console.WriteLine("Unknown --delta-from option, please see help.");
                        return(Constants.ErrorCode);
                    }

                    // If the repo uri and version are set, then call the graph
                    // build operation based on those.  Both should be set in this case.
                    // If they are not set, then gather the initial set based on the local repository,
                    // and then call the graph build with that root set.

                    if (!string.IsNullOrEmpty(_options.RepoUri))
                    {
                        if (string.IsNullOrEmpty(_options.Version))
                        {
                            Console.WriteLine("If --repo is set, --version should be supplied");
                            return(Constants.ErrorCode);
                        }

                        Console.WriteLine($"Getting root dependencies from {_options.RepoUri}@{_options.Version}...");

                        // Grab root dependency set. The graph build can do this, but
                        // if an original asset name is passed, then this will do the initial filtering.
                        IRemote rootRepoRemote = await remoteFactory.GetRemoteAsync(_options.RepoUri, Logger);

                        rootDependencies = await rootRepoRemote.GetDependenciesAsync(
                            _options.RepoUri,
                            _options.Version,
                            _options.AssetName);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(_options.Version))
                        {
                            Console.WriteLine("If --version is supplied, then --repo is required");
                            return(Constants.ErrorCode);
                        }

                        Console.WriteLine($"Getting root dependencies from local repository...");

                        // Grab root dependency set from local repo
                        Local local = new Local(Logger);
                        rootDependencies = await local.GetDependenciesAsync(
                            _options.AssetName);
                    }

                    Console.WriteLine($"Building repository dependency graph...");

                    rootDependencies = FilterToolsetDependencies(rootDependencies);

                    if (!rootDependencies.Any())
                    {
                        Console.WriteLine($"No root dependencies found, exiting.");
                        return(Constants.ErrorCode);
                    }

                    DependencyGraphBuildOptions graphBuildOptions = new DependencyGraphBuildOptions()
                    {
                        IncludeToolset = _options.IncludeToolset,
                        LookupBuilds   = diffOption != NodeDiff.None || !_options.SkipBuildLookup,
                        NodeDiff       = diffOption
                    };

                    // Build graph
                    graph = await DependencyGraph.BuildRemoteDependencyGraphAsync(
                        remoteFactory,
                        rootDependencies,
                        _options.RepoUri ?? LocalHelpers.GetRootDir(Logger),
                        _options.Version ?? LocalHelpers.GetGitCommit(Logger),
                        graphBuildOptions,
                        Logger);
                }
                else
                {
                    Console.WriteLine($"Getting root dependencies from local repository...");

                    Local local = new Local(Logger);
                    rootDependencies = await local.GetDependenciesAsync(
                        _options.AssetName);

                    rootDependencies = FilterToolsetDependencies(rootDependencies);

                    if (!rootDependencies.Any())
                    {
                        Console.WriteLine($"No root dependencies found, exiting.");
                        return(Constants.ErrorCode);
                    }

                    Console.WriteLine($"Building repository dependency graph from local information...");

                    DependencyGraphBuildOptions graphBuildOptions = new DependencyGraphBuildOptions()
                    {
                        IncludeToolset = _options.IncludeToolset,
                        LookupBuilds   = false,
                        NodeDiff       = NodeDiff.None
                    };

                    // Build graph using only local resources
                    graph = await DependencyGraph.BuildLocalDependencyGraphAsync(
                        rootDependencies,
                        graphBuildOptions,
                        Logger,
                        LocalHelpers.GetRootDir(Logger),
                        LocalHelpers.GetGitCommit(Logger),
                        _options.ReposFolder,
                        _options.RemotesMap);
                }

                if (_options.Flat)
                {
                    await LogFlatDependencyGraph(graph);
                }
                else
                {
                    await LogDependencyGraph(graph);
                }

                if (!string.IsNullOrEmpty(_options.GraphVizOutputFile))
                {
                    await LogGraphViz(graph);
                }

                return(Constants.SuccessCode);
            }
            catch (Exception exc)
            {
                Logger.LogError(exc, "Something failed while getting the dependency graph.");
                return(Constants.ErrorCode);
            }
        }
 private bool AreRValues(NodeDiff <ExpressionSyntax> r)
 {
     return(IsRValue(r.First) && IsRValue(r.Second));
 }
 private bool AreExpressionStatements(IfStatementSyntax @if, NodeDiff <ExpressionSyntax> r)
 {
     return(IsExpressionStatement(@if, r.First) || IsExpressionStatement(@if, r.Second));
 }