Helper class for locating and processing nuggets in a string.
コード例 #1
0
ファイル: FileNuggetFinder.cs プロジェクト: neo725/i18n
		public FileNuggetFinder(i18nSettings settings)
		{
            _settings = settings;
            _nuggetParser = new NuggetParser(new NuggetTokens(
			    _settings.NuggetBeginToken,
			    _settings.NuggetEndToken,
			    _settings.NuggetDelimiterToken,
			    _settings.NuggetCommentToken),
                NuggetParser.Context.SourceProcessing);
		}
コード例 #2
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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); }
 }
コード例 #3
0
ファイル: NuggetLocalizer.cs プロジェクト: uQr/i18n
        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);
        }
コード例 #4
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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;
     });
 }
コード例 #5
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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;
     });
 }
コード例 #6
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
        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);
        }
コード例 #7
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
        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);
        }
コード例 #8
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
        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);
        }
コード例 #9
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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;
     });
 }
コード例 #10
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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);
 }
コード例 #11
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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);
 }
コード例 #12
0
ファイル: NuggetParserTests.cs プロジェクト: neo725/i18n
 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;
     });
 }