-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ZenVoich/expect
Expect
- Loading branch information
Showing
27 changed files
with
960 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: mops test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: install moc | ||
run: npx mocv use latest | ||
|
||
- name: install mops | ||
run: npm i ic-mops -g | ||
|
||
- name: install mops packages | ||
run: mops install | ||
|
||
- name: run tests | ||
run: mops test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import Debug "mo:base/Debug"; | ||
import {expect = _expect; fail = _fail} "./expect"; | ||
|
||
module { | ||
public func test(name: Text, fn: () -> async ()): async () { | ||
public func test(name : Text, fn : () -> async ()) : async () { | ||
Debug.print("mops:1:start " # name); | ||
await fn(); | ||
Debug.print("mops:1:end " # name); | ||
}; | ||
|
||
public func suite(name: Text, fn: () -> async ()): async () { | ||
public func suite(name : Text, fn : () -> async ()) : async () { | ||
await test(name, fn); | ||
}; | ||
|
||
public func skip(name: Text, fn: () -> async ()): async () { | ||
public func skip(name : Text, fn : () -> async ()) : async () { | ||
Debug.print("mops:1:skip " # name); | ||
}; | ||
|
||
public let expect = _expect; | ||
public let fail = _fail; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Array "mo:base/Array"; | ||
import Option "mo:base/Option"; | ||
import Debug "mo:base/Debug"; | ||
import {fail} "./utils"; | ||
|
||
module { | ||
public class ExpectArray<T>(arr : [T], itemToText : (T) -> Text, itemEqual : (T, T) -> Bool) { | ||
func _arrayToText(arr : [T], limit : Nat) : Text { | ||
var text = "["; | ||
label l do { | ||
for (i in arr.keys()) { | ||
text #= itemToText(arr[i]); | ||
|
||
if (i + 1 < arr.size()) { | ||
if (text.size() > limit) { | ||
text #= "..."; | ||
break l; | ||
}; | ||
text #= ", "; | ||
}; | ||
}; | ||
text #= "]"; | ||
}; | ||
return text; | ||
}; | ||
|
||
public func equal(other : [T]) { | ||
if (not Array.equal<T>(arr, other, itemEqual)) { | ||
fail(_arrayToText(arr, 100), "", _arrayToText(other, 100)); | ||
}; | ||
}; | ||
|
||
public func notEqual(other : [T]) { | ||
if (Array.equal<T>(arr, other, itemEqual)) { | ||
fail(_arrayToText(arr, 100), "", _arrayToText(other, 100)); | ||
}; | ||
}; | ||
|
||
public func contains(a : T) { | ||
let has = Array.find<T>(arr, func b = itemEqual(a, b)); | ||
if (Option.isNull(has)) { | ||
fail(_arrayToText(arr, 100), "to contain element", itemToText(a)); | ||
}; | ||
}; | ||
|
||
public func notContains(a : T) { | ||
let has = Array.find<T>(arr, func b = itemEqual(a, b)); | ||
if (Option.isSome(has)) { | ||
fail(_arrayToText(arr, 100), "to not contain element", itemToText(a)); | ||
}; | ||
}; | ||
|
||
public func size(n : Nat) { | ||
if (arr.size() != n) { | ||
fail( | ||
"array size " # debug_show(arr.size()) # " - " # _arrayToText(arr, 50), | ||
"array size", | ||
debug_show(n) | ||
); | ||
}; | ||
}; | ||
}; | ||
}; |
Oops, something went wrong.