File: VBSpecialKeywordsTest.cs

package info (click to toggle)
mono 5.18.0.240%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,253,216 kB
  • sloc: cs: 10,925,936; xml: 2,804,987; ansic: 643,970; cpp: 120,384; perl: 59,272; asm: 21,383; sh: 20,162; makefile: 18,157; python: 4,715; pascal: 924; sql: 859; sed: 16; php: 1
file content (171 lines) | stat: -rw-r--r-- 6,831 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Resources;
using System.Web.Razor.Test.Framework;
using Xunit;

namespace System.Web.Razor.Test.Parser.VB
{
    public class VBSpecialKeywordsTest : VBHtmlCodeParserTestBase
    {
        [Fact]
        public void ParseInheritsStatementMarksInheritsSpanAsCanGrowIfMissingTrailingSpace()
        {
            ParseBlockTest("inherits",
                new DirectiveBlock(
                    Factory.MetaCode("inherits")),
                new RazorError(
                    RazorResources.ParseError_InheritsKeyword_Must_Be_Followed_By_TypeName,
                    8, 0, 8));
        }

        [Fact]
        public void InheritsBlockAcceptsMultipleGenericArguments()
        {
            ParseBlockTest("inherits Foo.Bar(Of Biz(Of Qux), String, Integer).Baz",
                new DirectiveBlock(
                    Factory.MetaCode("inherits ").Accepts(AcceptedCharacters.None),
                    Factory.Code("Foo.Bar(Of Biz(Of Qux), String, Integer).Baz")
                           .AsBaseType("Foo.Bar(Of Biz(Of Qux), String, Integer).Baz")));
        }

        [Fact]
        public void InheritsDirectiveSupportsVSTemplateTokens()
        {
            ParseBlockTest("@Inherits $rootnamespace$.MyBase",
                new DirectiveBlock(
                    Factory.CodeTransition(),
                    Factory.MetaCode("Inherits ")
                           .Accepts(AcceptedCharacters.None),
                    Factory.Code("$rootnamespace$.MyBase")
                           .AsBaseType("$rootnamespace$.MyBase")));
        }

        [Fact]
        public void InheritsBlockOutputsErrorIfInheritsNotFollowedByTypeButAcceptsEntireLineAsCode()
        {
            ParseBlockTest(@"inherits                
foo",
                new DirectiveBlock(
                    Factory.MetaCode("inherits                ").Accepts(AcceptedCharacters.None),
                    Factory.Code("\r\n").AsBaseType(String.Empty)),
                new RazorError(
                    RazorResources.ParseError_InheritsKeyword_Must_Be_Followed_By_TypeName,
                    8, 0, 8));
        }

        [Fact]
        public void ParseBlockShouldSupportNamespaceImports()
        {
            ParseBlockTest("Imports Foo.Bar.Baz.Biz.Boz",
                new DirectiveBlock(
                    Factory.MetaCode("Imports Foo.Bar.Baz.Biz.Boz")
                           .With(new AddImportCodeGenerator(
                               ns: " Foo.Bar.Baz.Biz.Boz",
                               namespaceKeywordLength: SyntaxConstants.VB.ImportsKeywordLength))));
        }

        [Fact]
        public void ParseBlockShowsErrorIfNamespaceNotOnSameLineAsImportsKeyword()
        {
            ParseBlockTest(@"Imports
Foo",
                new DirectiveBlock(
                    Factory.MetaCode("Imports\r\n")
                           .With(new AddImportCodeGenerator(
                               ns: "\r\n",
                               namespaceKeywordLength: SyntaxConstants.VB.ImportsKeywordLength))),
                new RazorError(
                    RazorResources.ParseError_NamespaceOrTypeAliasExpected,
                    7, 0, 7));
        }

        [Fact]
        public void ParseBlockShowsErrorIfTypeBeingAliasedNotOnSameLineAsImportsKeyword()
        {
            ParseBlockTest(@"Imports Foo =
System.Bar",
                new DirectiveBlock(
                    Factory.MetaCode("Imports Foo =\r\n")
                           .With(new AddImportCodeGenerator(
                               ns: " Foo =\r\n",
                               namespaceKeywordLength: SyntaxConstants.VB.ImportsKeywordLength))));
        }

        [Fact]
        public void ParseBlockShouldSupportTypeAliases()
        {
            ParseBlockTest("Imports Foo = Bar.Baz.Biz.Boz",
                new DirectiveBlock(
                    Factory.MetaCode("Imports Foo = Bar.Baz.Biz.Boz")
                           .With(new AddImportCodeGenerator(
                               ns: " Foo = Bar.Baz.Biz.Boz",
                               namespaceKeywordLength: SyntaxConstants.VB.ImportsKeywordLength))));
        }

        [Fact]
        public void ParseBlockThrowsErrorIfOptionIsNotFollowedByStrictOrExplicit()
        {
            ParseBlockTest("Option FizzBuzz On",
                new DirectiveBlock(
                    Factory.MetaCode("Option FizzBuzz On")
                           .With(new SetVBOptionCodeGenerator(optionName: null, value: true))),
                new RazorError(
                    String.Format(RazorResources.ParseError_UnknownOption, "FizzBuzz"),
                    7, 0, 7));
        }

        [Fact]
        public void ParseBlockThrowsErrorIfOptionStrictIsNotFollowedByOnOrOff()
        {
            ParseBlockTest("Option Strict Yes",
                new DirectiveBlock(
                    Factory.MetaCode("Option Strict Yes")
                           .With(SetVBOptionCodeGenerator.Strict(true))),
                new RazorError(
                    String.Format(
                        RazorResources.ParseError_InvalidOptionValue,
                        "Strict", "Yes"),
                    14, 0, 14));
        }

        [Fact]
        public void ParseBlockReadsToAfterOnKeywordIfOptionStrictBlock()
        {
            ParseBlockTest("Option Strict On Foo Bar Baz",
                new DirectiveBlock(
                    Factory.MetaCode("Option Strict On")
                           .With(SetVBOptionCodeGenerator.Strict(true))));
        }

        [Fact]
        public void ParseBlockReadsToAfterOffKeywordIfOptionStrictBlock()
        {
            ParseBlockTest("Option Strict Off Foo Bar Baz",
                new DirectiveBlock(
                    Factory.MetaCode("Option Strict Off")
                           .With(SetVBOptionCodeGenerator.Strict(false))));
        }

        [Fact]
        public void ParseBlockReadsToAfterOnKeywordIfOptionExplicitBlock()
        {
            ParseBlockTest("Option Explicit On Foo Bar Baz",
                new DirectiveBlock(
                    Factory.MetaCode("Option Explicit On")
                           .With(SetVBOptionCodeGenerator.Explicit(true))));
        }

        [Fact]
        public void ParseBlockReadsToAfterOffKeywordIfOptionExplicitBlock()
        {
            ParseBlockTest("Option Explicit Off Foo Bar Baz",
                new DirectiveBlock(
                    Factory.MetaCode("Option Explicit Off")
                           .With(SetVBOptionCodeGenerator.Explicit(false))));
        }
    }
}