示例#1
0
        public static void GetAttributeNameReturnsValueOfAttributeWithGivenName()
        {
            var directive = new TestableDirective(
                new DirectiveBlockStart(0),
                new DirectiveName(4, "template"),
                new[] { new Attribute(new AttributeName(13, "hostspecific"), new Equals(26), new DoubleQuote(27), new AttributeValue(28, "true"), new DoubleQuote(32)) },
                new BlockEnd(23));

            Assert.Equal("true", directive.GetAttributeValue("hostspecific"));
        }
示例#2
0
 public static void AttributesReturnsCaseInsensitiveDictionaryOfAttributesByName()
 {
     var a1 = new Attribute(new AttributeName(13, "language"), new Equals(21), new DoubleQuote(22), new AttributeValue(23, "C#"), new DoubleQuote(25));
     var a2 = new Attribute(new AttributeName(27, "debug"), new Equals(32), new DoubleQuote(33), new AttributeValue(34, "True"), new DoubleQuote(38));
     var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new[] { a1, a2 }, new BlockEnd(27));            
     IReadOnlyDictionary<string, Attribute> dictionary = directive.Attributes;
     Assert.NotNull(dictionary);
     Assert.Same(a1, dictionary["Language"]);
     Assert.Same(a2, dictionary["Debug"]);
 }
示例#3
0
 public static void ChildNodesReturnsNodesSpecifiedInConstructor()
 {
     var start = new DirectiveBlockStart(0);
     var name = new DirectiveName(4, "template");
     var a1 = new Attribute(new AttributeName(13, "language"), new Equals(21), new DoubleQuote(22), new AttributeValue(23, "C#"), new DoubleQuote(25));
     var a2 = new Attribute(new AttributeName(27, "debug"), new Equals(32), new DoubleQuote(33), new AttributeValue(34, "True"), new DoubleQuote(38));
     var end = new BlockEnd(27);
     var directive = new TestableDirective(start, name, new[] { a1, a2 }, end);
     Assert.True(directive.ChildNodes().SequenceEqual(new SyntaxNode[] { start, name, a1, a2, end }));
 }
示例#4
0
        public static void ChildNodesReturnsNodesSpecifiedInConstructor()
        {
            var start     = new DirectiveBlockStart(0);
            var name      = new DirectiveName(4, "template");
            var a1        = new Attribute(new AttributeName(13, "language"), new Equals(21), new DoubleQuote(22), new AttributeValue(23, "C#"), new DoubleQuote(25));
            var a2        = new Attribute(new AttributeName(27, "debug"), new Equals(32), new DoubleQuote(33), new AttributeValue(34, "True"), new DoubleQuote(38));
            var end       = new BlockEnd(27);
            var directive = new TestableDirective(start, name, new[] { a1, a2 }, end);

            Assert.True(directive.ChildNodes().SequenceEqual(new SyntaxNode[] { start, name, a1, a2, end }));
        }
示例#5
0
        public static void AttributesReturnsCaseInsensitiveDictionaryOfAttributesByName()
        {
            var a1        = new Attribute(new AttributeName(13, "language"), new Equals(21), new DoubleQuote(22), new AttributeValue(23, "C#"), new DoubleQuote(25));
            var a2        = new Attribute(new AttributeName(27, "debug"), new Equals(32), new DoubleQuote(33), new AttributeValue(34, "True"), new DoubleQuote(38));
            var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new[] { a1, a2 }, new BlockEnd(27));
            IReadOnlyDictionary <string, Attribute> dictionary = directive.Attributes;

            Assert.NotNull(dictionary);
            Assert.Same(a1, dictionary["Language"]);
            Assert.Same(a2, dictionary["Debug"]);
        }
示例#6
0
        public static void SpanEndsAtBlockEnd()
        {
            BlockEnd end;
            var      directive = new TestableDirective(
                new DirectiveBlockStart(10),
                new DirectiveName(14, "template"),
                new Attribute[0],
                end = new BlockEnd(23));

            Assert.Equal(end.Span.End, directive.Span.End);
        }
示例#7
0
        public static void SpanStartsAtBlockStart()
        {
            DirectiveBlockStart start;
            var directive = new TestableDirective(
                start = new DirectiveBlockStart(10),
                new DirectiveName(14, "template"),
                new Attribute[0],
                new BlockEnd(23));

            Assert.Equal(start.Span.Start, directive.Span.Start);
        }
示例#8
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);
        }
示例#9
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);
 }
示例#10
0
 public static void SpanEndsAtBlockEnd()
 {
     BlockEnd end;
     var directive = new TestableDirective(
         new DirectiveBlockStart(10),
         new DirectiveName(14, "template"),
         new Attribute[0],
         end = new BlockEnd(23));
     Assert.Equal(end.Span.End, directive.Span.End);
 }
示例#11
0
 public static void SpanStartsAtBlockStart()
 {
     DirectiveBlockStart start;
     var directive = new TestableDirective(
         start = new DirectiveBlockStart(10), 
         new DirectiveName(14, "template"), 
         new Attribute[0], 
         new BlockEnd(23));
     Assert.Equal(start.Span.Start, directive.Span.Start);
 }
示例#12
0
 public static void PositionReturnsPositionOfBlockStart()
 {
     var target = new TestableDirective(new DirectiveBlockStart(0, new Position(4, 2)), new DirectiveName(0, string.Empty), Enumerable.Empty<Attribute>(), new BlockEnd(0));
     Assert.Equal(new Position(4, 2), target.Position);
 }
示例#13
0
 public static void GetAttributeNameReturnsValueOfAttributeWithGivenName()
 {
     var directive = new TestableDirective(
         new DirectiveBlockStart(0),
         new DirectiveName(4, "template"),
         new[] { new Attribute(new AttributeName(13, "hostspecific"), new Equals(26), new DoubleQuote(27), new AttributeValue(28, "true"), new DoubleQuote(32)) },
         new BlockEnd(23));
     Assert.Equal("true", directive.GetAttributeValue("hostspecific"));
 }
示例#14
0
 public static void KindReturnsDirectiveSyntaxKind()
 {
     var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new Attribute[0], new BlockEnd(13));
     Assert.Equal(SyntaxKind.Directive, directive.Kind);
 }
示例#15
0
        public static void KindReturnsDirectiveSyntaxKind()
        {
            var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new Attribute[0], new BlockEnd(13));

            Assert.Equal(SyntaxKind.Directive, directive.Kind);
        }
示例#16
0
        public static void PositionReturnsPositionOfBlockStart()
        {
            var target = new TestableDirective(new DirectiveBlockStart(0, new Position(4, 2)), new DirectiveName(0, string.Empty), Enumerable.Empty <Attribute>(), new BlockEnd(0));

            Assert.Equal(new Position(4, 2), target.Position);
        }
示例#17
0
 public static void DirectiveNameReturnsTextOfDirectiveNameNode()
 {
     var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new Attribute[0], new BlockEnd(13));
     Assert.Equal("template", directive.DirectiveName);
 }
示例#18
0
        public static void DirectiveNameReturnsTextOfDirectiveNameNode()
        {
            var directive = new TestableDirective(new DirectiveBlockStart(0), new DirectiveName(4, "template"), new Attribute[0], new BlockEnd(13));

            Assert.Equal("template", directive.DirectiveName);
        }