Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Global/Prelude.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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

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
Expand Down
4 changes: 1 addition & 3 deletions src/Fable.Transforms/Rust/AST/Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module Program

[<EntryPoint>]
let main _args =
Tests.run ()
0
let main _args = 0
11 changes: 7 additions & 4 deletions src/Fable.Transforms/Rust/AST/Tests/Rust.AST.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RollForward>Major</RollForward>
<IsPackable>false</IsPackable>
Expand All @@ -21,10 +22,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.1.0" />
<PackageReference Include="coverlet.collector" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageReference Include="XUnit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
122 changes: 57 additions & 65 deletions src/Fable.Transforms/Rust/AST/Tests/Tests.fs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +12,8 @@ open type Macros
[<AutoOpen>]
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_()
Expand All @@ -26,66 +27,57 @@ module Helpers =
let variant_to_string (var: Variant) : string =
State.new_().to_string (fun (s) -> s.print_variant (var))

[<TestClass>]
type TestClass() =

[<TestMethod>]
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()")

[<TestMethod>]
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")

[<TestMethod>]
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 ()
[<Fact>]
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()")

[<Fact>]
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")

[<Fact>]
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)
20 changes: 14 additions & 6 deletions src/fable-standalone/src/Fable.Standalone.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<Compile Include="../../Fable.AST/Plugins.fs" />

<!-- Fable.Transforms -->
<Compile Include="../../Fable.Transforms/Babel/Babel.fs" />
<Compile Include="../../Fable.Transforms/Global/Fable.Core.fs" />
<Compile Include="../../Fable.Transforms/Global/Metadata.fs" />
<Compile Include="../../Fable.Transforms/Global/Prelude.fs" />
Expand All @@ -31,42 +30,51 @@
<Compile Include="../../Fable.Transforms/FSharp2Fable.Util.fs" />
<Compile Include="../../Fable.Transforms/ReplacementsInject.fs" />
<Compile Include="../../Fable.Transforms/Replacements.Util.fs" />
<Compile Include="../../Fable.Transforms/Printer.fs" />
<Compile Include="../../Fable.Transforms/Python/Replacements.fs" />
<Compile Include="../../Fable.Transforms/Rust/Replacements.fs" />
<Compile Include="../../Fable.Transforms/Dart/Replacements.fs" />
<Compile Include="../../Fable.Transforms/Beam/Prelude.fs" />
<Compile Include="../../Fable.Transforms/Beam/Beam.AST.fs" />
<Compile Include="../../Fable.Transforms/Beam/Replacements.fs" />
<Compile Include="../../Fable.Transforms/Replacements.fs" />
<Compile Include="../../Fable.Transforms/Replacements.Api.fs" />
<Compile Include="../../Fable.Transforms/QuotationEmitter.fs" />
<Compile Include="../../Fable.Transforms/FSharp2Fable.fsi" />
<Compile Include="../../Fable.Transforms/FSharp2Fable.fs" />
<Compile Include="../../Fable.Transforms/FableTransforms.fsi" />
<Compile Include="../../Fable.Transforms/FableTransforms.fs" />
<Compile Include="../../Fable.Transforms/State.fs" />

<Compile Include="../../Fable.Transforms/Babel/Babel.fs" />
<Compile Include="../../Fable.Transforms/Babel/Fable2Babel.fs" />
<Compile Include="../../Fable.Transforms/Printer.fs" />
<Compile Include="../../Fable.Transforms/Babel/BabelPrinter.fs" />

<Compile Include="../../Fable.Transforms/Python/Python.AST.fs" />
<Compile Include="../../Fable.Transforms/Python/PythonPrinter.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Types.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Util.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Annotation.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Bases.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Reflection.fs" />
<Compile Include="../../Fable.Transforms/Python/Fable2Python.Transforms.fs" />
<Compile Include="../../Fable.Transforms/Python/PythonPrinter.fs" />
<Compile Include="../../Fable.Transforms/Python/PythonCompiler.fs" />

<Compile Include="../../Fable.Transforms/Php/Php.fs" />
<Compile Include="../../Fable.Transforms/Php/Fable2Php.fs" />
<Compile Include="../../Fable.Transforms/Php/PhpPrinter.fs" />

<Compile Include="../../Fable.Transforms/Dart/Dart.fs" />
<Compile Include="../../Fable.Transforms/Dart/Fable2Dart.fs" />
<Compile Include="../../Fable.Transforms/Dart/DartPrinter.fs" />

<Compile Include="../../Fable.Transforms/Rust/RustPrinter.fs" />
<Compile Include="../../Fable.Transforms/Rust/Fable2Rust.fs" />

<Compile Include="../../Fable.Transforms/Beam/Prelude.fs" />
<Compile Include="../../Fable.Transforms/Beam/Beam.AST.fs" />
<Compile Include="../../Fable.Transforms/Beam/Fable2Beam.Util.fs" />
<Compile Include="../../Fable.Transforms/Beam/Fable2Beam.Reflection.fs" />
<Compile Include="../../Fable.Transforms/Beam/Fable2Beam.fs" />
<Compile Include="../../Fable.Transforms/Beam/ErlangPrinter.fs" />
<Compile Include="../../Fable.Transforms/State.fs" />

<!-- Fable.Standalone -->
<Compile Include="Interfaces.fs"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/Beam/Fable.Tests.Beam.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<RootNamespace>Fable.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageReference Include="XUnit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
3 changes: 2 additions & 1 deletion tests/Php/Fable.Tests.Php.fsproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RollForward>Major</RollForward>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageReference Include="XUnit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
1 change: 1 addition & 0 deletions tests/Php/TestString.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/Php/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading