예제 #1
0
        public void TestErrorCommentParse(string input, ErrorType expErrType, string expMsg, int start, int end,
                                          int sliceStart, int sliceEnd)
        {
            Resource parsed = new LinguiniParser(input).ParseWithComments();

            Assert.That(parsed.Errors.Count, Is.EqualTo(1));
            Assert.AreEqual(expErrType, parsed.Errors[0].Kind);
            Assert.AreEqual(expMsg, parsed.Errors[0].Message);
            Assert.AreEqual(new Range(start, end), parsed.Errors[0].Position);
            Assert.AreEqual(new Range(sliceStart, sliceEnd), parsed.Errors[0].Slice);
        }
예제 #2
0
        private static Resource ParseFtlFileFast(string path)
        {
            LinguiniParser parser;

            using (var reader = new StreamReader(path))
            {
                parser = new LinguiniParser(reader);
            }

            return(parser.Parse());
        }
예제 #3
0
        public void TestMessageParse(string input, string expName, string expValue)
        {
            Resource parsed = new LinguiniParser(input).ParseWithComments();

            Assert.AreEqual(0, parsed.Errors.Count, "Failed, with errors");
            Assert.AreEqual(1, parsed.Entries.Count);
            if (parsed.Entries[0] is AstMessage {
                Value : { }
            } message)
            {
                Assert.AreEqual(expName, message.Id.ToString());
                Assert.AreEqual(expValue, message.Value.Stringify());
            }
예제 #4
0
        public void TestCommentParse(string input, CommentLevel expectedCommentLevel = CommentLevel.Comment,
                                     string expectedContent = "Comment")
        {
            Resource parsed = new LinguiniParser(input).ParseWithComments();

            Assert.That(parsed.Entries.Count, Is.EqualTo(1));
            if (parsed.Entries[0] is AstComment comment)
            {
                Assert.AreEqual(expectedCommentLevel, comment.CommentLevel);
                Assert.AreEqual(expectedContent, comment.AsStr());
            }
            else
            {
                Assert.Fail("Comment was not found");
            }
        }
예제 #5
0
        public void TestDetailedErrors(string input, int row, int startErr, int endErr,
                                       int startMark, int endMark)
        {
            var parse             = new LinguiniParser(input).Parse();
            var parseWithComments = new LinguiniParser(input).ParseWithComments();

            Assert.AreEqual(1, parse.Errors.Count);
            Assert.AreEqual(1, parseWithComments.Errors.Count);

            var detailMsg = parse.Errors[0];

            Assert.AreEqual(row, detailMsg.Row);
            Assert.IsNotNull(detailMsg.Slice);
            Assert.AreEqual(new Range(startErr, endErr), detailMsg.Slice !.Value);
            Assert.AreEqual(new Range(startMark, endMark), detailMsg.Position);
        }