Skip to content

Commit 7ae3b11

Browse files
committed
Test: add some tests for Naggum.Assembler.
1 parent b09355d commit 7ae3b11

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Naggum.Test/AssemblerTests.fs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Naggum.Test.AssemblerTest
2+
3+
open System
4+
open System.IO
5+
open System.Text
6+
7+
open Xunit
8+
9+
open Naggum.Assembler
10+
open Naggum.Assembler.Representation
11+
12+
let prepare (source : string) =
13+
use stream = new MemoryStream(Encoding.UTF8.GetBytes source)
14+
Assembler.prepare "file.ngi" stream
15+
16+
[<Fact>]
17+
let ``Empty assembly should be processed`` () =
18+
let source = "(.assembly Empty)"
19+
let result = { Name = "Empty"; Units = List.empty }
20+
Assert.Equal ([result], prepare source)
21+
22+
[<Fact>]
23+
let ``Hello world assembly should be processed`` () =
24+
let source = "(.assembly Hello
25+
(.method Main () (.entrypoint)
26+
(ldstr \"Hello, world!\")
27+
(call `void System.Console::WriteLine(string)`)
28+
(ret)))
29+
"
30+
let result =
31+
{ Name = "Empty"
32+
Units = [Method { Metadata = Set.singleton EntryPoint
33+
Visibility = Public
34+
Name = "Main"
35+
ReturnType = typeof<Void>
36+
Body = [ Ldstr "Hello, world!"
37+
Call (typeof<Console>.GetMethod("WriteLine", [| typeof<String> |]))
38+
Ret ] } ] }
39+
Assert.Equal ([result], prepare source)

Naggum.Test/Naggum.Test.fsproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@
4848
</Choose>
4949
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
5050
<ItemGroup>
51-
<Compile Include="CompilerTest.fs" />
52-
<Content Include="packages.config" />
5351
<Content Include="Naggum.Test.dll.config">
5452
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5553
</Content>
54+
<Content Include="packages.config" />
55+
<Compile Include="AssemblerTests.fs" />
56+
<Compile Include="CompilerTest.fs" />
5657
</ItemGroup>
5758
<ItemGroup>
5859
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -80,6 +81,11 @@
8081
</Reference>
8182
</ItemGroup>
8283
<ItemGroup>
84+
<ProjectReference Include="..\Naggum.Assembler\Naggum.Assembler.fsproj">
85+
<Name>Naggum.Assembler</Name>
86+
<Project>{40b84f1e-1823-4255-80d4-1297613025c1}</Project>
87+
<Private>True</Private>
88+
</ProjectReference>
8389
<ProjectReference Include="..\Naggum.Compiler\Naggum.Compiler.fsproj">
8490
<Name>Naggum.Compiler</Name>
8591
<Project>{a4269c5e-e4ac-44bf-a06e-1b45248910ad}</Project>

0 commit comments

Comments
 (0)