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

Commit

Permalink
Here be tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 committed Nov 8, 2023
1 parent 35e460c commit ed5a926
Show file tree
Hide file tree
Showing 11 changed files with 729 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ env:
DOTNET_VERSION: '7.0.203'

jobs:
build-and-test:
vuild:

name: build-and-test-${{matrix.os}}
name: build-${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -29,11 +29,8 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install dependencies
- name: Install Dependencies
run: dotnet restore

- name: Build
run: dotnet build

- name: Test
run: dotnet test
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit Tests

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
paths:
- '**.cs'
- '**.csproj'

env:
DOTNET_VERSION: '7.0.203'

jobs:
test:

name: test-${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]

steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install Dependencies
run: dotnet restore

- name: Run Tests
run: dotnet test
18 changes: 18 additions & 0 deletions Moth.Unit/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ public void String()
Assert.AreEqual(expectedGlobal, module.FirstGlobal.ToString());
Assert.AreEqual(expectedMain, module.GetNamedFunction("main").ToString());
}

[TestMethod]
public void ScientificNotation()
{
var expected = "define i32 @main() {" +
"\nentry:" +
"\n %pow = call float @llvm.powi.f32.i32(float 1.000000e+01, i32 5)" +
"\n %0 = fptosi float %pow to i32" +
"\n %1 = mul i32 2, %0" +
"\n %val = alloca i32, align 4" +
"\n store i32 %1, ptr %val, align 4" +
"\n ret i32 0" +
"\n}" +
"\n";
var code = Utils.BasicWrap("local val ?= 2e+5; return 0;");
var module = Utils.FullCompile(code);
Assert.AreEqual(expected, module.GetNamedFunction("main").ToString());
}
}
9 changes: 9 additions & 0 deletions Moth.Unit/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
[TestClass]
public class Definitions
{
[TestMethod]
public void Class()
{
var expected = "%Thing = type { i32, i1, float }";
var code = Utils.PrependNamespace("public class Thing { public int #i32; public bool #bool; private float #f32; }");
var module = Utils.FullCompile(code);
Assert.AreEqual(expected, module.GetTypeByName("Thing").ToString());
}

[TestMethod]
public void ObjectAccess()
{
Expand Down
15 changes: 15 additions & 0 deletions Moth.Unit/Intrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@ public void SizeOf()
var module = Utils.FullCompile(code);
Assert.AreEqual(expected, module.GetNamedFunction("main").ToString());
}

[TestMethod]
public void AlignOf()
{
var expected = "define i32 @main() {" +
"\nentry:" +
"\n %val = alloca i64, align 8" +
"\n store i64 ptrtoint (ptr getelementptr ({ i1, i32 }, ptr null, i64 0, i32 1) to i64), ptr %val, align 4" +
"\n ret i32 0" +
"\n}" +
"\n";
var code = Utils.BasicWrap("local val ?= #i32.alignof(); return 0;");
var module = Utils.FullCompile(code);
Assert.AreEqual(expected, module.GetNamedFunction("main").ToString());
}
}
Loading

0 comments on commit ed5a926

Please sign in to comment.