Browse Source

Prevent null stream (#20)

* Prevent null stream

SyntaxNodes file references VB.NET.xshd while the file name was VBNET.xshd
pull/21/head
Jay Asbury 6 years ago
committed by Igor Velikorossov
parent
commit
68dcb93b32
  1. 6
      ICSharpCode.TextEditor.Sample/ICSharpCode.TextEditor.Sample.csproj
  2. 3
      ICSharpCode.TextEditor.Sample/app.config
  3. 0
      Project/Resources/VB.NET.xshd
  4. 29
      Test/HighlightingManagerTests.cs
  5. 11
      Test/ICSharpCode.TextEditor.Tests.csproj
  6. 1
      Test/packages.config

6
ICSharpCode.TextEditor.Sample/ICSharpCode.TextEditor.Sample.csproj

@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>ICSharpCode.TextEditor.Sample</RootNamespace>
<AssemblyName>ICSharpCode.TextEditor.Sample</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<RuntimeIdentifier>win</RuntimeIdentifier>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -57,5 +58,8 @@
<Name>ICSharpCode.TextEditor</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

3
ICSharpCode.TextEditor.Sample/app.config

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

0
Project/Resources/VBNET.xshd → Project/Resources/VB.NET.xshd

29
Test/HighlightingManagerTests.cs

@ -1,5 +1,8 @@
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
namespace ICSharpCode.TextEditor.Tests
{
@ -23,5 +26,29 @@ namespace ICSharpCode.TextEditor.Tests
IHighlightingStrategy highlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile("test.unkown");
Assert.AreEqual("Default", highlightingStrategy.Name);
}
[Test]
public void ResourceStreamNamesMatchSyntaxNodes()
{
Assembly assembly = typeof(ICSharpCode.TextEditor.Document.ResourceSyntaxModeProvider).Assembly;
var resources = assembly.GetManifestResourceNames();
var syntaxNodesResource = resources.First(r => r.Contains("SyntaxModes"));
var xmlModes = XElement.Load(assembly.GetManifestResourceStream(syntaxNodesResource)).Elements("Mode");
var resourcesToCheck = resources.Where(r => r.EndsWith("xshd"));
var matched = from xml in xmlModes
join res in resourcesToCheck on xml.Attribute("file").Value equals
res.Replace("ICSharpCode.TextEditor.Resources.", "")
select new { ResourceName = res, XMLModeFile = xml.Attribute("file").Value };
var missingInXML = resourcesToCheck.Except(matched.Select(m => m.ResourceName));
var missingInResources = from nd in xmlModes
where !matched.Select(m => m.XMLModeFile).Contains(nd.Attribute("file").Value)
select nd.Attribute("file").Value;
Assert.That(!missingInXML.Any(), "The SyntaxNodes.xml file is out of sync with the actual resources. Check the following resource names that don't exist in xml file. {0}", string.Join(",", missingInXML));
Assert.That(!missingInResources.Any(), "The SyntaxNodes.xml file is out of sync with the actual resources. Check the following resource names that don't exist in embedded resources. {0}", string.Join(",", missingInResources));
}
}
}
}

11
Test/ICSharpCode.TextEditor.Tests.csproj

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -21,18 +21,21 @@
<Optimize>False</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<RuntimeIdentifier>win</RuntimeIdentifier>
<OldToolsVersion>2.0</OldToolsVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DefineConstants>DEBUG</DefineConstants>
<OutputPath>bin\UnitTests\</OutputPath>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
@ -52,6 +55,8 @@
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.1\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

1
Test/packages.config

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.1" targetFramework="net20" />
</packages>
Loading…
Cancel
Save