diff --git a/src/Fable.Transforms/Global/Prelude.fs b/src/Fable.Transforms/Global/Prelude.fs index 55f20e0145..e0ce8d4097 100644 --- a/src/Fable.Transforms/Global/Prelude.fs +++ b/src/Fable.Transforms/Global/Prelude.fs @@ -12,7 +12,7 @@ module Extensions = module Dictionary = open System.Collections.Generic - let tryFind key (dic: #IDictionary<'Key, 'Value>) = + let tryFind key (dic: IDictionary<'Key, 'Value>) = match dic.TryGetValue(key) with | true, v -> Some v | false, _ -> None @@ -20,7 +20,7 @@ module Dictionary = module ReadOnlyDictionary = open System.Collections.Generic - let tryFind key (dic: #IReadOnlyDictionary<'Key, 'Value>) = + let tryFind key (dic: IReadOnlyDictionary<'Key, 'Value>) = match dic.TryGetValue(key) with | true, v -> Some v | false, _ -> None diff --git a/src/Fable.Transforms/Rust/AST/Tests/Program.fs b/src/Fable.Transforms/Rust/AST/Tests/Program.fs index 86102ef700..4e6f7620a3 100644 --- a/src/Fable.Transforms/Rust/AST/Tests/Program.fs +++ b/src/Fable.Transforms/Rust/AST/Tests/Program.fs @@ -1,6 +1,4 @@ module Program [] -let main _args = - Tests.run () - 0 +let main _args = 0 diff --git a/src/Fable.Transforms/Rust/AST/Tests/Rust.AST.Tests.fsproj b/src/Fable.Transforms/Rust/AST/Tests/Rust.AST.Tests.fsproj index c0f7148913..0dca7f57bd 100644 --- a/src/Fable.Transforms/Rust/AST/Tests/Rust.AST.Tests.fsproj +++ b/src/Fable.Transforms/Rust/AST/Tests/Rust.AST.Tests.fsproj @@ -1,6 +1,7 @@ + Exe net10.0 Major false @@ -21,10 +22,12 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/src/Fable.Transforms/Rust/AST/Tests/Tests.fs b/src/Fable.Transforms/Rust/AST/Tests/Tests.fs index 077aaaf775..d80fc81537 100644 --- a/src/Fable.Transforms/Rust/AST/Tests/Tests.fs +++ b/src/Fable.Transforms/Rust/AST/Tests/Tests.fs @@ -1,7 +1,6 @@ module Tests -// open System -open Microsoft.VisualStudio.TestTools.UnitTesting +open Xunit open Fable.Transforms.Rust.AST.Adapters open Fable.Transforms.Rust.AST.Spans @@ -13,6 +12,8 @@ open type Macros [] module Helpers = + let inline assert_eq<'T> (actual: 'T, expected: 'T) : unit = Assert.Equal(expected, actual) + let fun_to_string (decl: FnDecl, header: FnHeader, name: Ident, generics: Generics) : string = State .new_() @@ -26,66 +27,57 @@ module Helpers = let variant_to_string (var: Variant) : string = State.new_().to_string (fun (s) -> s.print_variant (var)) -[] -type TestClass() = - - [] - member _.test_fun_to_string() = - let abba_ident = Ident.from_str ("abba") - - let decl: FnDecl = - { - inputs = Vec() - output = FnRetTy.Default(DUMMY_SP) - } - - let generics = Generics.default_ () - - assert_eq (fun_to_string (decl, FnHeader.default_ (), abba_ident, generics), "fn abba()") - - [] - member _.test_variant_to_string() = - let ident = Ident.from_str ("principal_skinner") - - let var_: Variant = - { - ident = ident - vis = - { - span = DUMMY_SP - kind = VisibilityKind.Inherited - tokens = None - } - attrs = Vec() - id = DUMMY_NODE_ID - data = VariantData.Unit(DUMMY_NODE_ID) - disr_expr = None - span = DUMMY_SP - is_placeholder = false - } - - let varstr = variant_to_string (var_) - assert_eq (varstr, "principal_skinner") - - [] - member _.test_crate_to_string() = - let sm: SourceMap = SourceMap() - let krate: Crate = Sample.AST.testCrate - let filename: FileName = "filename.rs" - let input: string = "" - let ann: PpAnn = NoAnn() :> PpAnn - let is_expanded: bool = false - let edition: Edition = Edition.Edition2021 - - let actual = print_crate (sm, krate, filename, input, ann, is_expanded, edition) - - let expected = - "pub fn main() { let a = vec![1, 2, 3, 4, 5]; println!(\"{:?}\", a); }\n" - - assert_eq (actual, expected) - -let run () = - let tests = TestClass() - tests.test_fun_to_string () - tests.test_variant_to_string () - tests.test_crate_to_string () +[] +let test_fun_to_string () = + let abba_ident = Ident.from_str ("abba") + + let decl: FnDecl = + { + inputs = Vec() + output = FnRetTy.Default(DUMMY_SP) + } + + let generics = Generics.default_ () + + assert_eq (fun_to_string (decl, FnHeader.default_ (), abba_ident, generics), "fn abba()") + +[] +let test_variant_to_string () = + let ident = Ident.from_str ("principal_skinner") + + let var_: Variant = + { + ident = ident + vis = + { + span = DUMMY_SP + kind = VisibilityKind.Inherited + tokens = None + } + attrs = Vec() + id = DUMMY_NODE_ID + data = VariantData.Unit(DUMMY_NODE_ID) + disr_expr = None + span = DUMMY_SP + is_placeholder = false + } + + let varstr = variant_to_string (var_) + assert_eq (varstr, "principal_skinner") + +[] +let test_crate_to_string () = + let sm: SourceMap = SourceMap() + let krate: Crate = Sample.AST.testCrate + let filename: FileName = "filename.rs" + let input: string = "" + let ann: PpAnn = NoAnn() :> PpAnn + let is_expanded: bool = false + let edition: Edition = Edition.Edition2021 + + let actual = print_crate (sm, krate, filename, input, ann, is_expanded, edition) + + let expected = + "pub fn main() { let a = vec![1, 2, 3, 4, 5,]; println!(\"{:?}\", a,); }\n" + + assert_eq (actual, expected) diff --git a/src/fable-standalone/src/Fable.Standalone.fsproj b/src/fable-standalone/src/Fable.Standalone.fsproj index 51485cc029..9886e08a8a 100644 --- a/src/fable-standalone/src/Fable.Standalone.fsproj +++ b/src/fable-standalone/src/Fable.Standalone.fsproj @@ -18,7 +18,6 @@ - @@ -31,42 +30,51 @@ + - - + + + + + - + - + + + + + + + - diff --git a/tests/Beam/Fable.Tests.Beam.fsproj b/tests/Beam/Fable.Tests.Beam.fsproj index 23977e7e34..ca2e9c732d 100644 --- a/tests/Beam/Fable.Tests.Beam.fsproj +++ b/tests/Beam/Fable.Tests.Beam.fsproj @@ -9,7 +9,7 @@ Fable.Tests - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Php/Fable.Tests.Php.fsproj b/tests/Php/Fable.Tests.Php.fsproj index cf4454a014..509b2813e4 100644 --- a/tests/Php/Fable.Tests.Php.fsproj +++ b/tests/Php/Fable.Tests.Php.fsproj @@ -1,5 +1,6 @@ + Exe net10.0 Major false @@ -7,7 +8,7 @@ preview - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Php/TestString.fs b/tests/Php/TestString.fs index 7c51597b4a..25ad578c90 100644 --- a/tests/Php/TestString.fs +++ b/tests/Php/TestString.fs @@ -2,6 +2,7 @@ module Fable.Tests.String open System open Util.Testing +open System.Globalization let containsInOrder (substrings: string list) (str: string) = let mutable lastIndex = -1 diff --git a/tests/Php/Util.fs b/tests/Php/Util.fs index 896a365908..5990668105 100644 --- a/tests/Php/Util.fs +++ b/tests/Php/Util.fs @@ -30,3 +30,11 @@ module Testing = | 0 -> 0. | 1 -> Seq.head zs | _ -> (Seq.head zs) + sumFirstSeq (Seq.skip 1 zs) (n-1) + + let throwsAnyError f = + try + f() |> ignore + false + with e -> + true + |> equal true