Browse Source

Added some unit tests

tags/v0.2.1
Cédric Belin 1 week ago
parent
commit
7fe7ab28db
9 changed files with 74 additions and 1 deletions
  1. +8
    -0
      share/test.hxml
  2. +15
    -0
      test/TestAll.hx
  3. +27
    -0
      test/gitea/DateToolsTest.hx
  4. +2
    -0
      test_eval.hxml
  5. +5
    -0
      test_js.hxml
  6. +3
    -0
      test_neko.hxml
  7. +5
    -0
      test_php.hxml
  8. +1
    -1
      tool/lint.ps1
  9. +8
    -0
      tool/test.ps1

+ 8
- 0
share/test.hxml View File

@@ -0,0 +1,8 @@
--class-path src
--class-path test
--define coverage-lcov-reporter=var/lcov.info
--library datetime:3.1.4
--library instrument:1.1.0
--library utest:1.13.1
--macro instrument.Instrumentation.coverage(['gitea'], ['src'])
--main TestAll

+ 15
- 0
test/TestAll.hx View File

@@ -0,0 +1,15 @@
import instrument.coverage.Coverage;
import gitea.*;
import utest.UTest;

/** Runs the test suite. **/
class TestAll {

/** The test cases. **/
static final tests = [
new DateToolsTest()
];

/** Application entry point. **/
static function main() UTest.run(tests, Coverage.endCoverage);
}

+ 27
- 0
test/gitea/DateToolsTest.hx View File

@@ -0,0 +1,27 @@
package gitea;

import utest.Assert;
import utest.Test;

/** Tests the features of the `DateTools` class. **/
class DateToolsTest extends Test {

/** Tests the `parseIsoString()` method. **/
function testParseIsoString() {
// It should return `null` for an invalid date string.
Assert.isNull(DateTools.parseIsoString("foo"));
Assert.isNull(DateTools.parseIsoString("2000-13-48T00:00:00Z"));
Assert.isNull(DateTools.parseIsoString("2000-01-01T29:73:82Z"));

// It should return a `Date` instance for a valid date string.
var timestamp = 946684800 * 1000.0;
Assert.equals(timestamp, DateTools.parseIsoString("2000-01-01T00:00:00.000Z").getTime());
Assert.equals(timestamp, DateTools.parseIsoString("1999-12-31T22:00:00.000-02:00").getTime());
Assert.equals(timestamp, DateTools.parseIsoString("2000-01-01T03:00:00.000+03:00").getTime());

timestamp = 1596285000 * 1000.0;
Assert.equals(timestamp, DateTools.parseIsoString("2020-08-01T12:30:00Z").getTime());
Assert.equals(timestamp, DateTools.parseIsoString("2020-08-01T07:30:00-05:00").getTime());
Assert.equals(timestamp, DateTools.parseIsoString("2020-08-01T16:30:00+04:00").getTime());
}
}

+ 2
- 0
test_eval.hxml View File

@@ -0,0 +1,2 @@
--interp
share/test.hxml

+ 5
- 0
test_js.hxml View File

@@ -0,0 +1,5 @@
--define js-es=6
--js var/tests.js
--library hxnodejs:12.1.0
share/test.hxml
--cmd node var/tests.js

+ 3
- 0
test_neko.hxml View File

@@ -0,0 +1,3 @@
--neko var/tests.n
share/test.hxml
--cmd neko var/tests.n

+ 5
- 0
test_php.hxml View File

@@ -0,0 +1,5 @@
--define php-lib=php
--define real-position
--php lib
share/test.hxml
--cmd php lib/index.php

+ 1
- 1
tool/lint.ps1 View File

@@ -1,4 +1,4 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
haxelib run checkstyle --config etc/checkstyle.json --source src
haxelib run checkstyle --config etc/checkstyle.json --source src --source test

+ 8
- 0
tool/test.ps1 View File

@@ -0,0 +1,8 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

foreach ($item in "eval", "js", "neko", "php") {
Write-Host "> Testing '$item' target..."
haxe "test_$item.hxml"
}

Loading…
Cancel
Save