Skip to content

Commit fe9d777

Browse files
Merge pull request #8 from eiriktsarpalis/add-tests
Add test project and sln
2 parents eda0b72 + fe1e48d commit fe9d777

5 files changed

Lines changed: 133 additions & 0 deletions

File tree

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SOURCE_DIRECTORY := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
2+
3+
Configuration ?= Release
4+
Output ?= "$(SOURCE_DIRECTORY)/artifacts"
5+
.DEFAULT_GOAL := test
6+
7+
all: clean build test pack
8+
9+
clean:
10+
dotnet clean && rm -rf $(Output)
11+
12+
build:
13+
dotnet build -c $(Configuration)
14+
15+
test: build
16+
dotnet test --no-build -c $(Configuration)
17+
18+
pack: build
19+
dotnet pack --no-build -c $(Configuration) -o $(Output)

UnitsOfMeasure.Extra.sln

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnitsOfMeasure.Extra", "src\UnitsOfMeasure.Extra.fsproj", "{194B07ED-714F-48CD-A1E3-E09862D58F60}"
7+
EndProject
8+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnitsOfMeasure.Extra.Tests", "tests\UnitsOfMeasure.Extra.Tests.fsproj", "{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
15+
Release|Any CPU = Release|Any CPU
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|x64.ActiveCfg = Debug|Any CPU
26+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|x64.Build.0 = Debug|Any CPU
27+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|x86.ActiveCfg = Debug|Any CPU
28+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Debug|x86.Build.0 = Debug|Any CPU
29+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|x64.ActiveCfg = Release|Any CPU
32+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|x64.Build.0 = Release|Any CPU
33+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|x86.ActiveCfg = Release|Any CPU
34+
{194B07ED-714F-48CD-A1E3-E09862D58F60}.Release|x86.Build.0 = Release|Any CPU
35+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|x64.ActiveCfg = Debug|Any CPU
38+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|x64.Build.0 = Debug|Any CPU
39+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|x86.ActiveCfg = Debug|Any CPU
40+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Debug|x86.Build.0 = Debug|Any CPU
41+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|x64.ActiveCfg = Release|Any CPU
44+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|x64.Build.0 = Release|Any CPU
45+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|x86.ActiveCfg = Release|Any CPU
46+
{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}.Release|x86.Build.0 = Release|Any CPU
47+
EndGlobalSection
48+
EndGlobal

src/UnitsOfMeasure.Extra.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
3+
34
<PropertyGroup>
45
<Version>1.0.0</Version>
56
<PackageVersion>1.0.0-beta-005</PackageVersion>
67
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
78
<GenerateDocumentationFile>true</GenerateDocumentationFile>
89
</PropertyGroup>
10+
911
<ItemGroup>
1012
<Compile Include="UnitsOfMeasure.Extra.fs" />
1113
</ItemGroup>
14+
1215
<ItemGroup>
1316
<Content Include="*.fsproj; *.fs" PackagePath="fable\" />
1417
</ItemGroup>
18+
1519
<ItemGroup>
1620
<PackageReference Update="FSharp.Core" Version="4.1.17" />
1721
</ItemGroup>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="UnitsOfMeasure.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="../src/UnitsOfMeasure.Extra.fsproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="xunit" Version="2.4.0" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
19+
<PackageReference Include="Microsoft.Net.Test.SDK" Version="15.9.0" />
20+
</ItemGroup>
21+
22+
</Project>

tests/UnitsOfMeasure.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module UnitsOfMeasure.Extra.Tests
2+
3+
open System
4+
open Xunit
5+
open UnitsOfMeasure.Extra
6+
7+
[<Measure>] type skuId
8+
[<Measure>] type km
9+
[<Measure>] type foo
10+
11+
type Record =
12+
{
13+
skuId : string<skuId>
14+
foo : string<foo>
15+
distance : int<km>
16+
}
17+
18+
// Tests intentionally without assertions
19+
20+
[<Fact>]
21+
let ``Simple unit of measure conversions``() =
22+
let x = Guid.NewGuid() |> UoM.tag<skuId>
23+
let y = (UoM.untag x).ToString("N") |> UoM.tag<skuId>
24+
let z = UoM.tag<km> 42
25+
let w = sprintf "%O %s %d" (UoM.untag x) (UoM.untag y) z
26+
()
27+
28+
[<Fact>]
29+
let ``Simple unit of measure conversions with cast operator``() =
30+
let x : Guid<skuId> = % Guid.NewGuid()
31+
let y : string<skuId> = % (%x).ToString()
32+
let z : int<km> = % 42
33+
let w : string<foo> = % sprintf "%O %s %d" %x %y %z
34+
()
35+
36+
[<Fact>]
37+
let ``Record with units of measure``() =
38+
let record = { skuId = % "skuId" ; foo = % "foo" ; distance = % 42 }
39+
let x = sprintf "%s %s %d" %record.skuId %record.foo %record.distance
40+
()

0 commit comments

Comments
 (0)