Esempio n. 1
0
        public void TestErrorTemplateName()
        {
            var diagnostics = GetDiagnostics("ErrorTemplateName.lg");

            Assert.Equal(7, diagnostics.Count);
            Assert.Equal(DiagnosticSeverity.Error, diagnostics[0].Severity);
            Assert.Contains(TemplateErrors.InvalidParameter("param1; param2"), diagnostics[0].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[1].Severity);
            Assert.Contains(TemplateErrors.InvalidParameter("param1 param2"), diagnostics[1].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[2].Severity);
            Assert.Contains(TemplateErrors.InvalidTemplateName("template3(errorparams"), diagnostics[2].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[3].Severity);
            Assert.Contains(TemplateErrors.InvalidParameter("a)test(param1"), diagnostics[3].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[4].Severity);
            Assert.Contains(TemplateErrors.InvalidParameter("$%^"), diagnostics[4].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[5].Severity);
            Assert.Contains(TemplateErrors.InvalidTemplateName("the-name-of-template"), diagnostics[5].Message);

            Assert.Equal(DiagnosticSeverity.Error, diagnostics[6].Severity);
            Assert.Contains(TemplateErrors.InvalidTemplateName("t1.1"), diagnostics[6].Message);
        }
Esempio n. 2
0
            private void CheckTemplateName(string templateName, ParserRuleContext context)
            {
                var functionNameSplitDot = templateName.Split('.');

                foreach (var id in functionNameSplitDot)
                {
                    if (!TemplateNamePartRegex.IsMatch(id))
                    {
                        var diagnostic = BuildTemplatesDiagnostic(TemplateErrors.InvalidTemplateName(templateName), context);
                        this.templates.Diagnostics.Add(diagnostic);
                        break;
                    }
                }
            }