diff --git a/src/Fable.Transforms/Global/Compiler.fs b/src/Fable.Transforms/Global/Compiler.fs index 14acff1a3..0a9fe9119 100644 --- a/src/Fable.Transforms/Global/Compiler.fs +++ b/src/Fable.Transforms/Global/Compiler.fs @@ -99,7 +99,7 @@ type InlineExprLazy(f: Compiler -> InlineExpr) = [] module CompilerExt = - let private expectedVersionMatchesActual (expected: string) (actual: string) = + let expectedVersionMatchesActual (expected: string) (actual: string) = try let r = System.Text.RegularExpressions.Regex(@"^(\d+)\.(\d+)(?:\.(\d+))?") @@ -116,10 +116,10 @@ module CompilerExt = let actualMajor, actualMinor, actualPatch = parse actual let expectedMajor, expectedMinor, expectedPatch = parse expected - // Fail also if actual major is bigger than expected major version - actualMajor = expectedMajor - && (actualMinor > expectedMinor - || (actualMinor = expectedMinor && actualPatch >= expectedPatch)) + actualMajor > expectedMajor + || (actualMajor = expectedMajor + && (actualMinor > expectedMinor + || (actualMinor = expectedMinor && actualPatch >= expectedPatch))) with _ -> false diff --git a/tests/Integration/Compiler/CompilerHelpersTests.fs b/tests/Integration/Compiler/CompilerHelpersTests.fs new file mode 100644 index 000000000..5b4bd5dfa --- /dev/null +++ b/tests/Integration/Compiler/CompilerHelpersTests.fs @@ -0,0 +1,24 @@ +module Fable.Tests.Compiler.CompilerHelpers + +open Fable.Core +open Util.Testing +open Fable.Tests.Compiler.Util +open Fable.Tests.Compiler.Util.Compiler + +let tests = + testList "Compiler Helpers" [ + testCase "expectedVersionMatchesActual works for same major version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "5.0.0" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "5.0.0" "5.0.1" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "5.1.0" "5.1.0" |> equal true + + testCase "expectedVersionMatchesActual works if actual version is higher than expected version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.0.1" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.1.0" |> equal true + + testCase "expectedVersionMatchesActual reject if actual version is lower than expected version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "3.0.0" |> equal false + Fable.CompilerExt.expectedVersionMatchesActual "4.0.1" "3.0.0" |> equal false + Fable.CompilerExt.expectedVersionMatchesActual "4.1.0" "3.0.0" |> equal false + ] diff --git a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj index 096a4285c..573d04010 100644 --- a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj +++ b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj @@ -22,6 +22,7 @@ + - \ No newline at end of file + diff --git a/tests/Integration/Compiler/Main.fs b/tests/Integration/Compiler/Main.fs index 4011447b3..fbed235b9 100644 --- a/tests/Integration/Compiler/Main.fs +++ b/tests/Integration/Compiler/Main.fs @@ -7,6 +7,7 @@ let allTests = [ CompilerMessages.tests AnonRecordInInterface.tests + CompilerHelpers.tests ] diff --git a/tests/Integration/Integration/CompilationTests.fs b/tests/Integration/Integration/CompilationTests.fs index 7591eb56d..4e967edfc 100644 --- a/tests/Integration/Integration/CompilationTests.fs +++ b/tests/Integration/Integration/CompilationTests.fs @@ -25,7 +25,7 @@ let tests = Expect.equal exitCode 0 "Expected exit code to be 0" let normalize content = - Regex.Replace(content, @"(/fable-library-js)[.0-9]+", "$1") + Regex.Replace(content, @"(/fable-library-js)[^/]+", "$1") |> _.ReplaceLineEndings() |> _.Trim()