Skip to content

Commit

Permalink
Small refactoring...
Browse files Browse the repository at this point in the history
Implemented SemVer::Equals(semVer)
Implemented SemVer::IsGreaterThan(semVer)
Implemented SemVer::IsGreaterThanOrEquals(semVer)
  • Loading branch information
SlavaRa committed Oct 4, 2016
1 parent 21bb147 commit 7c68005
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 19 deletions.
2 changes: 1 addition & 1 deletion External/Plugins/HaXeContext/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci,
HaxeComplete GetHaxeComplete(ScintillaControl sci, ASExpr expression, bool autoHide, HaxeCompilerService compilerService)
{
var sdkVersion = GetCurrentSDKVersion();
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.CompletionServer && new SemVer("3.2.1").IsOlderThan(sdkVersion))
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.CompletionServer && sdkVersion.IsGreaterThanOrEquals(new SemVer("3.3.0")))
return new HaxeComplete330(sci, expression, autoHide, completionModeHandler, compilerService, sdkVersion);
return new HaxeComplete(sci, expression, autoHide, completionModeHandler, compilerService, sdkVersion);
}
Expand Down
15 changes: 14 additions & 1 deletion FlashDevelop.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlashDevelop", "FlashDevelop\FlashDevelop.csproj", "{EFD07485-9A64-4EEC-94E7-ACBD4DA5CA93}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -83,6 +83,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASCompletion.Tests", "Tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeRefactor.Tests", "Tests\External\Plugins\CodeRefactor.Tests\CodeRefactor.Tests.csproj", "{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginCore.Tests", "Tests\PluginCore\PluginCore.Tests\PluginCore.Tests.csproj", "{F44D3125-12E8-4143-B250-84C5D89D253C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -493,6 +495,17 @@ Global
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|Any CPU.Build.0 = Release|Any CPU
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.ActiveCfg = Release|x86
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.Build.0 = Release|x86
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|x86.ActiveCfg = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|x86.Build.0 = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|Any CPU.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|x86.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|x86.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|Any CPU.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|Any CPU.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|x86.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 24 additions & 15 deletions PluginCore/PluginCore/Utilities/SemVer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ public SemVer(string version)
{
// ignore the pre-release denotation if present
int hyphenIndex = version.IndexOf('-');
if (hyphenIndex >= 0)
version = version.Substring(0, hyphenIndex);
if (hyphenIndex >= 0) version = version.Substring(0, hyphenIndex);

string[] numbers = version.Split('.');

if (numbers.Length >= 1)
int.TryParse(numbers[0], out Major);
if (numbers.Length >= 2)
int.TryParse(numbers[1], out Minor);
if (numbers.Length >= 3)
int.TryParse(numbers[2], out Patch);
if (numbers.Length >= 1) int.TryParse(numbers[0], out Major);
if (numbers.Length >= 2) int.TryParse(numbers[1], out Minor);
if (numbers.Length >= 3) int.TryParse(numbers[2], out Patch);
}

public override string ToString()
Expand All @@ -39,13 +35,26 @@ public override string ToString()

public bool IsOlderThan(SemVer semVer)
{
if (semVer.Major > Major)
return true;
if (semVer.Major == Major && semVer.Minor > Minor)
return true;
if (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch > Patch)
return true;
return false;
return (semVer.Major > Major)
|| (semVer.Major == Major && semVer.Minor > Minor)
|| (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch > Patch);
}

public bool Equals(SemVer semVer)
{
return semVer.Major == Major && semVer.Minor == Minor && semVer.Patch == Patch;
}

public bool IsGreaterThan(SemVer semVer)
{
return (semVer.Major < Major)
|| (semVer.Major == Major && semVer.Minor < Minor)
|| (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch < Patch);
}

public bool IsGreaterThanOrEquals(SemVer semVer)
{
return Equals(semVer) || IsGreaterThan(semVer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CodeRefactor.Tests")]
[assembly: AssemblyDescription("DistroConfig.DISTRIBUTION_COMPANY")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("DistroConfig.DISTRIBUTION_COMPANY")]
[assembly: AssemblyProduct("CodeRefactor.Tests")]
[assembly: AssemblyCopyright("DistroConfig.DISTRIBUTION_COPYRIGHT")]
[assembly: AssemblyTrademark("")]
Expand Down
70 changes: 70 additions & 0 deletions Tests/PluginCore/PluginCore.Tests/PluginCore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F44D3125-12E8-4143-B250-84C5D89D253C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PluginCore</RootNamespace>
<AssemblyName>PluginCore.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\Bin\Debug\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="PluginCore\Utilities\SemVerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<DependentUpon>Settings.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\PluginCore\PluginCore.csproj">
<Project>{61885F70-B4DC-4B44-852D-5D6D03F2A734}</Project>
<Name>PluginCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NUnit.Framework;
using PluginCore.Utilities;

namespace PluginCore.PluginCore.Utilities
{
[TestFixture]
class SemVerTests
{
[Test]
public void IsOlderThan()
{
var ver = new SemVer("3.2.1");
Assert.IsTrue(ver.IsOlderThan(new SemVer("3.3.0")));
Assert.IsFalse(ver.IsOlderThan(new SemVer("3.0.0")));
}

[Test]
public void Equals()
{
var ver = new SemVer("3.3.0");
Assert.IsTrue(ver.Equals(new SemVer("3.3.0")));
Assert.IsFalse(ver.Equals(new SemVer("3.2.1")));
}

[Test]
public void IsGreaterThan()
{
var ver = new SemVer("3.3.0");
Assert.IsTrue(ver.IsGreaterThan(new SemVer("3.2.1")));
Assert.IsFalse(ver.IsGreaterThan(new SemVer("3.3.0")));
}

[Test]
public void IsGreaterThanOrEquals()
{
var ver = new SemVer("3.3.0");
Assert.IsTrue(ver.IsGreaterThanOrEquals(new SemVer("3.2.1")));
Assert.IsTrue(ver.IsGreaterThanOrEquals(new SemVer("3.3.0")));
Assert.IsFalse(ver.IsGreaterThanOrEquals(new SemVer("3.4.0")));
}
}
}
36 changes: 36 additions & 0 deletions Tests/PluginCore/PluginCore.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PluginCore.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("DistroConfig.DISTRIBUTION_COMPANY")]
[assembly: AssemblyProduct("PluginCore.Tests")]
[assembly: AssemblyCopyright("DistroConfig.DISTRIBUTION_COPYRIGHT")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f44d3125-12e8-4143-b250-84c5d89d253c")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
26 changes: 26 additions & 0 deletions Tests/PluginCore/PluginCore.Tests/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>

0 comments on commit 7c68005

Please sign in to comment.