public static void TestEmptyDictionaryReturnNoNamingStylePreferencesObjectReturnsFalse()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var result = editorConfigStorageLocation.TryGetOption(StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary), typeof(NamingStylePreferences), out _);

            Assert.False(result, "Expected TryParseReadonlyDictionary to return 'false' for empty dictionary");
        }
        public static void TestObjectTypeThrowsInvalidOperationException()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();

            Assert.Throws <InvalidOperationException>(() =>
            {
                editorConfigStorageLocation.TryGetOption(StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary), typeof(object), out var @object);
            });
        }
Example #3
0
        public void TestParseEditorConfigEndOfLine(string configurationString, string newLine)
        {
            var storageLocation = FormattingOptions.NewLine.StorageLocations
                                  .OfType <EditorConfigStorageLocation <string> >()
                                  .Single();
            var allRawConventions = StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary.Add(storageLocation.KeyName, configurationString));

            Assert.True(storageLocation.TryGetOption(allRawConventions, typeof(string), out var parsedNewLine));
            Assert.Equal(newLine, (string?)parsedNewLine);
        }
Example #4
0
        public void TestParseEditorConfigAccessibilityModifiers(string args, int value, ReportDiagnostic severity)
        {
            var storageLocation = CodeStyleOptions2.RequireAccessibilityModifiers.StorageLocations
                                  .OfType <EditorConfigStorageLocation <CodeStyleOption2 <AccessibilityModifiersRequired> > >()
                                  .Single();
            var allRawConventions = StructuredAnalyzerConfigOptions.Create(DictionaryAnalyzerConfigOptions.EmptyDictionary.Add(storageLocation.KeyName, args));

            Assert.True(storageLocation.TryGetOption(allRawConventions, typeof(CodeStyleOption2 <AccessibilityModifiersRequired>), out var parsedCodeStyleOption));
            var codeStyleOption = (CodeStyleOption2 <AccessibilityModifiersRequired>)parsedCodeStyleOption !;

            Assert.Equal((AccessibilityModifiersRequired)value, codeStyleOption.Value);
            Assert.Equal(severity, codeStyleOption.Notification.Severity);
        }
        public static void TestNonEmptyDictionaryReturnsTrue()
        {
            var editorConfigStorageLocation = new NamingStylePreferenceEditorConfigStorageLocation();
            var options = StructuredAnalyzerConfigOptions.Create(new Dictionary <string, string>()
            {
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity"]       = "error",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols"]        = "method_and_property_symbols",
                ["dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style"]          = "pascal_case_style",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_kinds"]           = "method,property",
                ["dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities"] = "*",
                ["dotnet_naming_style.pascal_case_style.capitalization"] = "pascal_case"
            }.ToImmutableDictionary(AnalyzerConfigOptions.KeyComparer));

            var result = editorConfigStorageLocation.TryGetOption(options, typeof(NamingStylePreferences), out var value);

            Assert.True(result, "Expected non-empty dictionary to return true");
            var namingStylePreferences = Assert.IsAssignableFrom <NamingStylePreferences>(value);

            Assert.Equal(ReportDiagnostic.Error, namingStylePreferences.Rules.NamingRules[0].EnforcementLevel);
        }
 public AnalyzerConfigData(AnalyzerConfigOptionsResult result)
 {
     ConfigOptions   = StructuredAnalyzerConfigOptions.Create(result.AnalyzerOptions);
     AnalyzerOptions = result.AnalyzerOptions;
     TreeOptions     = result.TreeOptions;
 }