private static void AssertExpectedContext(int position, ReferenceContext expected, string reason)
        {
            var actual = ReferenceContext.Create(Path, Content, position);

            Assert.AreEqual(expected.Path, actual.Path, "Path: " + reason);
            Assert.AreEqual(expected.LineNumber, actual.LineNumber, "LineNumber: " + reason);
            Assert.AreEqual(expected.Context, actual.Context, "Context:" + reason);
        }
Beispiel #2
0
        private void AddNewTemplateItem(
            string fileName,
            ReferenceContext referenceContext,
            Nugget nugget, 
            ConcurrentDictionary<string, TemplateItem> templateItems)
        {
            string msgid = nugget.MsgId.Replace("\r\n", "\n").Replace("\r", "\\n");
                // NB: In memory msgids are normalized so that LFs are converted to "\n" char sequence.
            string key = TemplateItem.KeyFromMsgidAndComment(msgid, nugget.Comment, _settings.MessageContextEnabledFromComment);
            List<string> tmpList;
               //
            templateItems.AddOrUpdate(
                key,
                // Add routine.
                k => {
                    TemplateItem item = new TemplateItem();
                    item.MsgKey = key;
                    item.MsgId = msgid;
                    item.FileName = fileName;

                    item.References = new List<ReferenceContext> {referenceContext};

                    if (nugget.Comment.IsSet()) {
                        tmpList = new List<string>();
                        tmpList.Add(nugget.Comment);
                        item.Comments = tmpList;
                    }

                    return item;
                },
                // Update routine.
                (k, v) =>
                {
                    if (!_settings.DisableReferences)
                    {
                        var newReferences = new List<ReferenceContext>(v.References.ToList());
                        newReferences.Add(referenceContext);
                        v.References = newReferences;
                    }

                    if (nugget.Comment.IsSet()) {
                        tmpList = v.Comments != null ? v.Comments.ToList() : new List<string>();
                        if (!_settings.DisableReferences || !tmpList.Contains(nugget.Comment))
                            tmpList.Add(nugget.Comment);
                        v.Comments = tmpList;
                    }

                    return v;
                });
        }