Helper class for locating and processing nuggets in a string.
Example #1
0
		public FileNuggetFinder(i18nSettings settings)
		{
            _settings = settings;
            _nuggetParser = new NuggetParser(new NuggetTokens(
			    _settings.NuggetBeginToken,
			    _settings.NuggetEndToken,
			    _settings.NuggetDelimiterToken,
			    _settings.NuggetCommentToken),
                NuggetParser.Context.SourceProcessing);
		}
Example #2
0
 private void ParseAndComp(string nuggetString, Nugget rhs, bool equal = true)
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
    // Act.
     Nugget nugget = nuggetParser.BreakdownNugget(nuggetString);
    // Assert.
     if (equal) {
         Assert.AreEqual(nugget, rhs); }
     else {
         Assert.AreNotEqual(nugget, rhs); }
 }
Example #3
0
        public NuggetLocalizer(
            i18nSettings settings,
            ITextLocalizer textLocalizer)
        {
            _settings = settings;
            _textLocalizer = textLocalizer;

            _nuggetParser = new NuggetParser(new NuggetTokens(
                _settings.NuggetBeginToken,
                _settings.NuggetEndToken,
                _settings.NuggetDelimiterToken,
                _settings.NuggetCommentToken),
                NuggetParser.Context.ResponseProcessing);
        }
Example #4
0
 public void NuggetParser_CanParseEntity01()
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
     string entity = "<p>[[[hello]]]</p><p>[[[there]]]</p>";
    // Act.
     nuggetParser.ParseString(entity, delegate(string nuggetString, int pos, Nugget nugget1, string entity1)
     {
         if (pos == 3) {
             Assert.AreEqual(nugget1, new Nugget { MsgId = "hello" }); }
         else if (pos == 21) {
             Assert.AreEqual(nugget1, new Nugget { MsgId = "there" }); }
         else {
             Assert.Fail(); }
         return null;
     });
 }
Example #5
0
 private void CanParseEntity_CustomNuggetTokens_Act(string entity, NuggetParser nuggetParser)
 {
    // Act.
     int i = 0;
     nuggetParser.ParseString(entity, delegate(string nuggetString, int pos, Nugget nugget1, string entity1)
     {
         switch (i++) {
             case 0: {
                 Assert.AreEqual(nugget1, new Nugget { MsgId = "hello", FormatItems = new string[] { "{0}" } });
                 break;
             }
             case 1: {
                 Assert.AreEqual(nugget1, new Nugget { MsgId = "there", FormatItems = new string[] { "{0}", "{1}" }, Comment = "comment comment comment" });
                 break;
             }
             default:
                 Assert.Fail();
                 break;
         }
         return null;
     });
 }
Example #6
0
        public void NuggetParser_ResponseMode_CanParseEntity_TwoParams_FirstNonEmpty_SecondEmpty() {
            var nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
            NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.ResponseProcessing);
            var input = "[[[Title: %0, %1|||X|||]]]";
            var result = nuggetParser.ParseString(input, (nuggetString, pos, nugget, i_entity) => {
                Assert.IsTrue(nugget.IsFormatted);
                return nugget.MsgId;
            });

            Assert.AreEqual("Title: %0, %1", result);
        }
Example #7
0
        public void NuggetParser_SourceMode_CanParseEntity_EmptyParam() {
            var nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
            NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
            var input = "[[[Title: %0|||]]]";
            var result = nuggetParser.ParseString(input, (nuggetString, pos, nugget, i_entity) => {
                Assert.IsFalse(nugget.IsFormatted);
                return nugget.MsgId;
            });

            Assert.AreEqual("Title: %0|||", result);
        }
Example #8
0
        public void NuggetParser_ResponseMode_CanParseEntity_EmptyParam() {
            var nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
            NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.ResponseProcessing);
            var input = "[[[Title: %0|||]]]";
            var result = nuggetParser.ParseString(input, (nuggetString, pos, nugget, i_entity) => {
                Assert.IsTrue(nugget.IsFormatted);
                var message = NuggetLocalizer.ConvertIdentifiersInMsgId(nugget.MsgId);
                message = String.Format(message, nugget.FormatItems);
                return message;
            });

            Assert.AreEqual("Title: ", result);
        }
Example #9
0
 public void NuggetParser_CanParseEntity_MultiLineNugget01()
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
     string entity = "<p>[[[hello\r\n%0|||{0}]]]</p><p>[[[there]]]</p>";
    // Act.
     int i = 0;
     nuggetParser.ParseString(entity, delegate(string nuggetString, int pos, Nugget nugget1, string entity1)
     {
         switch (i++) {
             case 0: {
                 Assert.AreEqual(nugget1, new Nugget { MsgId = "hello\r\n%0", FormatItems = new string[] { "{0}" } });
                 break;
             }
             case 1: {
                 Assert.AreEqual(nugget1, new Nugget { MsgId = "there" });
                 break;
             }
             default:
                 Assert.Fail();
                 break;
         }
         return null;
     });
 }
Example #10
0
 public void NuggetParser_CanParseEntity_CustomNuggetTokens03()
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("```", "'''", "###", "@@@");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
     string entity = "<p>```hello###{0}'''</p><p>```there###{0}###{1}@@@comment comment comment'''</p>";
    // Act.
     CanParseEntity_CustomNuggetTokens_Act(entity, nuggetParser);
 }
Example #11
0
 public void NuggetParser_CanParseEntity_CustomNuggetTokens02()
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("[[[:", ":]]]", "|||", "///");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
     string entity = "<p>[[[:hello|||{0}:]]]</p><p>[[[:there|||{0}|||{1}///comment comment comment:]]]</p>";
    // Act.
     CanParseEntity_CustomNuggetTokens_Act(entity, nuggetParser);
 }
Example #12
0
 public void NuggetParser_CanParseEntity03()
 {
    // Arrange.
     NuggetTokens nuggetTokens = new NuggetTokens("[[[", "]]]", "|||", "///");
     NuggetParser nuggetParser = new NuggetParser(nuggetTokens, NuggetParser.Context.SourceProcessing);
     string entity = "<p>[[[hello|||{0}]]]</p><p>[[[there|||{0}|||{1}///comment comment comment]]]</p>";
    // Act.
     nuggetParser.ParseString(entity, delegate(string nuggetString, int pos, Nugget nugget1, string entity1)
     {
         if (pos == 3) {
             Assert.AreEqual(nugget1, new Nugget { MsgId = "hello", FormatItems = new string[] { "{0}" } }); }
         else if (pos == 27) {
             Assert.AreEqual(nugget1, new Nugget { MsgId = "there", FormatItems = new string[] { "{0}", "{1}" }, Comment = "comment comment comment" }); }
         else {
             Assert.Fail(); }
         return null;
     });
 }