Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
PIRATE-47 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanarkel committed Sep 2, 2023
1 parent bc07c36 commit 72ee98f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Pirate.Lexer.F.Test/Pirate.Lexer.F.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="TokenTest.fs" />
<Compile Include="TokenRepositoryTest.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expecto" Version="9.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Pirate.Lexer.F\Pirate.Lexer.F.fsproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions Pirate.Lexer.F.Test/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tests

open System
open Xunit

[<Fact>]
let ``My test`` () =
Assert.True(true)
31 changes: 31 additions & 0 deletions Pirate.Lexer.F.Test/TokenRepositoryTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Pirate.Lexer.F.Test.TokenRepositoryTest

open Xunit
open Pirate.Lexer.F
open Pirate.Lexer.F.Tokens.Enums

[<Fact>]
let ShouldMakeNumber () =
let tokenRepository = new TokenRepository(new KeyWordService())
let text = "123"
let position = 0

let result = tokenRepository.MakeNumber(text, position)

Assert.Equal(3, result.Position)
Assert.Equal(VALUE, result.Token.TokenGroup);
Assert.Equal(INT, result.Token.TokenType);
Assert.Equal(123, result.Token.Value |> unbox<int>)

[<Fact>]
let ShouldMakeFloat () =
let tokenRepository = new TokenRepository(new KeyWordService())
let text = "123.456"
let position = 0

let result = tokenRepository.MakeNumber(text, position)

Assert.Equal(7, result.Position)
Assert.Equal(VALUE, result.Token.TokenGroup)
Assert.Equal(FLOAT, result.Token.TokenType)
Assert.Equal(123.456, result.Token.Value |> unbox<float>)
15 changes: 15 additions & 0 deletions Pirate.Lexer.F.Test/TokenTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Pirate.Lexer.F.Test.TokenTest

open Xunit
open Pirate.Lexer.F.Tokens
open Pirate.Lexer.F.Tokens.Enums

[<Fact>]
let ShouldMatchToken () =
Token(VALUE, INT, 123).Matches(TokenType.INT, 123) |> Assert.True

[<Fact>]
let ShouldNotMatchToken () =
Token(VALUE, INT, 123).Matches(TokenType.INT, 456) |> Assert.False


0 comments on commit 72ee98f

Please sign in to comment.