@@ -590,7 +590,7 @@ public static int Main()
590590 }
591591}
592592" ;
593- CreateCompilationWithMscorlib45 ( test ) . VerifyDiagnostics (
593+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
594594 // (2,1): error CS1671: A namespace declaration cannot have modifiers or attributes
595595 Diagnostic ( ErrorCode . ERR_BadModifiersOnNamespace , "public" ) . WithLocation ( 2 , 1 ) ) ;
596596 }
@@ -626,15 +626,13 @@ namespace N { }
626626 Diagnostic ( ErrorCode . ERR_BadModifiersOnNamespace , "[System.Obsolete]" ) . WithLocation ( 1 , 1 ) ) ;
627627 }
628628
629- private static readonly CSharpParseOptions s_previewOptions = CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . Preview ) ;
630-
631629 [ Fact ]
632630 public void NamespaceWithSemicolon1 ( )
633631 {
634632 var test =
635633@"namespace A;" ;
636634
637- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics ( ) ;
635+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics ( ) ;
638636 }
639637
640638 [ Fact ]
@@ -643,7 +641,7 @@ public void NamespaceWithSemicolon3()
643641 var test =
644642@"namespace A.B;" ;
645643
646- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics ( ) ;
644+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics ( ) ;
647645 }
648646
649647 [ Fact ]
@@ -653,7 +651,7 @@ public void MultipleSingleLineNamespaces()
653651@"namespace A;
654652namespace B;" ;
655653
656- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
654+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
657655 // (2,11): error CS8907: Source file can only contain one single-line namespace declaration.
658656 // namespace B;
659657 Diagnostic ( ErrorCode . ERR_MultipleSingleLineNamespace , "B" ) . WithLocation ( 2 , 11 ) ) ;
@@ -668,7 +666,7 @@ public void SingleLineNamespaceNestedInNormalNamespace()
668666 namespace B;
669667}" ;
670668
671- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
669+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
672670 // (3,15): error CS8908: Source file can not contain both single-line and normal namespace declarations.
673671 // namespace B;
674672 Diagnostic ( ErrorCode . ERR_SingleLineAndNormalNamespace , "B" ) . WithLocation ( 3 , 15 ) ) ;
@@ -683,7 +681,7 @@ namespace B
683681{
684682}" ;
685683
686- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
684+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
687685 // (2,11): error CS8908: Source file can only contain single-line and normal namespace declarations.
688686 // namespace B
689687 Diagnostic ( ErrorCode . ERR_SingleLineAndNormalNamespace , "B" ) . WithLocation ( 2 , 11 ) ) ;
@@ -698,7 +696,7 @@ public void NormalAndSingleLineNamespace2()
698696}
699697namespace B;" ;
700698
701- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
699+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
702700 // (4,11): error CS8909: Single-line namespace must precede all other members in a file.
703701 // namespace B;
704702 Diagnostic ( ErrorCode . ERR_SingleLineNamespaceNotBeforeAllMembers , "B" ) . WithLocation ( 4 , 11 ) ) ;
@@ -711,7 +709,7 @@ public void NamespaceWithPrecedingUsing()
711709@"using System;
712710namespace A;" ;
713711
714- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
712+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
715713 // (1,1): hidden CS8019: Unnecessary using directive.
716714 // using System;
717715 Diagnostic ( ErrorCode . HDN_UnusedUsingDirective , "using System;" ) . WithLocation ( 1 , 1 ) ) ;
@@ -724,7 +722,7 @@ public void NamespaceWithFollowingUsing()
724722@"namespace X;
725723using System;" ;
726724
727- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
725+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
728726 // (2,1): hidden CS8019: Unnecessary using directive.
729727 // using System;
730728 Diagnostic ( ErrorCode . HDN_UnusedUsingDirective , "using System;" ) . WithLocation ( 2 , 1 ) ) ;
@@ -737,7 +735,7 @@ public void NamespaceWithPrecedingType()
737735@"class X { }
738736namespace System;" ;
739737
740- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
738+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
741739 // (2,11): error CS8909: Single-line namespace must precede all other members in a file.
742740 // namespace System;
743741 Diagnostic ( ErrorCode . ERR_SingleLineNamespaceNotBeforeAllMembers , "System" ) . WithLocation ( 2 , 11 ) ) ;
@@ -750,7 +748,7 @@ public void NamespaceWithFollowingType()
750748@"namespace System;
751749class X { }" ;
752750
753- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics ( ) ;
751+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics ( ) ;
754752 }
755753
756754 [ Fact ]
@@ -761,7 +759,7 @@ public void SingleLineNamespaceWithPrecedingStatement()
761759System.Console.WriteLine();
762760namespace B;" ;
763761
764- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
762+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
765763 // (3,11): error CS8914: Single-line namespace must precede all other members in a file.
766764 // namespace B;
767765 Diagnostic ( ErrorCode . ERR_SingleLineNamespaceNotBeforeAllMembers , "B" ) . WithLocation ( 3 , 11 ) ) ;
@@ -775,7 +773,7 @@ public void SingleLineNamespaceWithFollowingStatement()
775773namespace B;
776774System.Console.WriteLine();" ;
777775
778- CreateCompilationWithMscorlib45 ( test , parseOptions : s_previewOptions ) . VerifyDiagnostics (
776+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
779777 // (3,16): error CS0116: A namespace cannot directly contain members such as fields or methods
780778 // System.Console.WriteLine();
781779 Diagnostic ( ErrorCode . ERR_NamespaceUnexpected , "WriteLine" ) . WithLocation ( 3 , 16 ) ,
@@ -786,5 +784,51 @@ namespace B;
786784 // System.Console.WriteLine();
787785 Diagnostic ( ErrorCode . ERR_EOFExpected , ";" ) . WithLocation ( 3 , 27 ) ) ;
788786 }
787+
788+ [ Fact ]
789+ public void SingleLineNamespaceUsingsBeforeAndAfter ( )
790+ {
791+ var source1 = @"
792+ namespace A
793+ {
794+ class C1 { }
795+ }
796+
797+ namespace B
798+ {
799+ class C2 { }
800+ }
801+ " ;
802+ var source2 = @"
803+ using A;
804+ namespace X;
805+ using B;
806+
807+ class C
808+ {
809+ void M()
810+ {
811+ new C1();
812+ new C2();
813+ }
814+ }
815+ " ;
816+
817+ CreateCompilationWithMscorlib45 ( new [ ] { source1 , source2 } , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics ( ) ;
818+ }
819+
820+ [ Fact ]
821+ public void SingleLineNamespaceFollowedByVariable ( )
822+ {
823+ var test = @"
824+ namespace B;
825+ int x; // 1
826+ " ;
827+
828+ CreateCompilationWithMscorlib45 ( test , parseOptions : TestOptions . RegularWithFileScopedNamespaces ) . VerifyDiagnostics (
829+ // (3,5): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
830+ // int x; // 1
831+ Diagnostic ( ErrorCode . ERR_NamespaceUnexpected , "x" ) . WithLocation ( 3 , 5 ) ) ;
832+ }
789833 }
790834}
0 commit comments