Пример #1
0
        public static void ValidateReturnsErrorWhenNamespaceAttributeIsNotSpecified()
        {
            var           directive = new ImportDirective(new DirectiveBlockStart(0), new DirectiveName(4, "import"), new Attribute[0], new BlockEnd(18));
            TemplateError error     = directive.Validate().Single();

            Assert.Contains("Namespace", error.Message, StringComparison.OrdinalIgnoreCase);
        }
Пример #2
0
        public static void ValidateReturnsErrorWhenProcessorAttributeIsNotSpecified()
        {
            var           directive = new CustomDirective(new DirectiveBlockStart(0), new DirectiveName(4, "custom"), new Attribute[0], new BlockEnd(24));
            TemplateError error     = directive.Validate().Single();

            Assert.Contains("Processor", error.Message, StringComparison.OrdinalIgnoreCase);
        }
Пример #3
0
        public static void ValidateReturnsTemplateErrorWhenAttributeValueDoesNotPassPropertyValidationAttributes()
        {
            var           directive = new DirectiveWithRequiredAttribute(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new Attribute[0], new BlockEnd(13));
            TemplateError error     = directive.Validate().Single();

            Assert.Contains("RequiredAttribute", error.Message, StringComparison.OrdinalIgnoreCase);
            Assert.Equal(directive.Span, error.Span);
            Assert.Equal(directive.Position, error.Position);
        }
Пример #4
0
        public static void ValidateReturnsErrorWhenExtensionAttributeIsNotSpecified()
        {
            var directive = new OutputDirective(
                new DirectiveBlockStart(0),
                new DirectiveName(4, "output"),
                new[] { new Attribute(new AttributeName(14, "encoding"), new Equals(18), new DoubleQuote(19), new AttributeValue(20, "utf-8"), new DoubleQuote(22)) },
                new BlockEnd(24));
            TemplateError error = directive.Validate().Single();

            Assert.Contains("Extension", error.Message, StringComparison.OrdinalIgnoreCase);
        }
Пример #5
0
        public static void ValidateReturnsErrorWhenTypeAttributeIsNotSpecified()
        {
            var directive = new ParameterDirective(
                new DirectiveBlockStart(0),
                new DirectiveName(4, "parameter"),
                new[] { new Attribute(new AttributeName(14, "name"), new Equals(18), new DoubleQuote(19), new AttributeValue(20, "p1"), new DoubleQuote(22)) },
                new BlockEnd(24));
            TemplateError error = directive.Validate().Single();

            Assert.Contains("Type", error.Message, StringComparison.OrdinalIgnoreCase);
        }
Пример #6
0
        public static void ValidateReturnsTemplateErrorWhenDirectiveContainsUnrecognizedAttribute()
        {
            var unrecognizedAttribute = new Attribute(new AttributeName(27, "UnrecognizedAttribute"), new Equals(32), new DoubleQuote(33), new AttributeValue(34, "v2"), new DoubleQuote(38));
            var directive             = new TestableDirective(
                new DirectiveBlockStart(10),
                new DirectiveName(14, "template"),
                new[] { unrecognizedAttribute },
                new BlockEnd(23));
            TemplateError error = directive.Validate().Single();

            Assert.Contains(unrecognizedAttribute.Name, error.Message, StringComparison.OrdinalIgnoreCase);
            Assert.Equal(unrecognizedAttribute.Span, error.Span);
            Assert.Equal(unrecognizedAttribute.Position, error.Position);
        }
Пример #7
0
        private static void AssertParseErrors(string input, params TemplateError[] errors)
        {
            TemplateParser parser = CreateParser(input);

            parser.Parse();
            Assert.Equal(errors.Length, parser.Errors.Count);
            for (int i = 0; i < errors.Length; i++)
            {
                TemplateError expected = errors[i];
                TemplateError actual   = parser.Errors[i];
                Assert.Equal(expected.Message, actual.Message);
                Assert.Equal(expected.Span, actual.Span);
                Assert.Equal(expected.Position, actual.Position);
            }
        }
Пример #8
0
        public static void ValidateReturnsTemplateErrorWhenAttributeValueDoesNotMatchKnownValues()
        {
            AttributeValue value;
            var            directive = new DirectiveWithKnownAttributeValues(
                new DirectiveBlockStart(0),
                new DirectiveName(4, "directive"),
                new[] { new Attribute(new AttributeName(13, "attributeWithKnownValues"), new Equals(37), new DoubleQuote(38), value = new AttributeValue(39, "wrong"), new DoubleQuote(44)) },
                new BlockEnd(46));
            TemplateError error = directive.Validate().Single();

            Assert.Contains("attributeWithKnownValues", error.Message, StringComparison.OrdinalIgnoreCase);
            Assert.Contains("wrong", error.Message, StringComparison.OrdinalIgnoreCase);
            Assert.Equal(value.Span, error.Span);
            Assert.Equal(value.Position, error.Position);
        }
Пример #9
0
        public static void SpanReturnsValueSpecifiedInConstructor()
        {
            var target = new TemplateError(string.Empty, new Span(4, 2), default(Position));

            Assert.Equal(new Span(4, 2), target.Span);
        }
Пример #10
0
        public static void MessageReturnsValueSpecifiedInConstructor()
        {
            var target = new TemplateError("42", default(Span), default(Position));

            Assert.Equal("42", target.Message);
        }
Пример #11
0
 public static void SpanReturnsValueSpecifiedInConstructor()
 {
     var target = new TemplateError(string.Empty, new Span(4, 2), default(Position));
     Assert.Equal(new Span(4, 2), target.Span);
 }
Пример #12
0
 public static void MessageReturnsValueSpecifiedInConstructor()
 {
     var target = new TemplateError("42", default(Span), default(Position));
     Assert.Equal("42", target.Message);
 }