Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertType method to UnitTest #520

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/docs/standard-lib/unittest.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ This helper method ensures that the value passed in is equal to nil.

This helper method ensures that the value passed in is not equal to nil.

### assertType(value, value)

This helper method checks the type of the first value is equal to the type as a string.

```cs
this.assertType("Dictu", "string");
this.assertType(10, "number");
```

### assertTruthy(value)

This helper method ensures that the value passed in would evaluate to true.
Expand Down
7 changes: 6 additions & 1 deletion src/optionals/unittest/unittest-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
" }\n" \
"\n" \
" assertNotEquals(value, expected) {\n" \
" this.printResult(value == expected, 'Failure: {} is equal to {}.'.format(value, expected));\n" \
" this.printResult(value != expected, 'Failure: {} is equal to {}.'.format(value, expected));\n" \
" }\n" \
"\n" \
" assertNil(value) {\n" \
Expand All @@ -113,6 +113,11 @@
" this.printResult(value != nil, 'Failure: Should not be nil.');\n" \
" }\n" \
"\n" \
" assertType(value, expected) {\n" \
" const valType = type(value);\n" \
" this.printResult(valType == expected, 'Failure: {}({}) is not of type {}.'.format(value, valType, expected));\n" \
" }\n" \
"\n" \
" assertTruthy(value) {\n" \
" this.printResult(value, 'Failure: {} is not Truthy.'.format(value));\n" \
" }\n" \
Expand Down
7 changes: 6 additions & 1 deletion src/optionals/unittest/unittest.du
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class UnitTest {
}

assertNotEquals(value, expected) {
this.printResult(value == expected, 'Failure: {} is equal to {}.'.format(value, expected));
this.printResult(value != expected, 'Failure: {} is equal to {}.'.format(value, expected));
}

assertNil(value) {
Expand All @@ -113,6 +113,11 @@ abstract class UnitTest {
this.printResult(value != nil, 'Failure: Should not be nil.');
}

assertType(value, expected) {
const valType = type(value);
this.printResult(valType == expected, 'Failure: {}({}) is not of type {}.'.format(value, valType, expected));
}

assertTruthy(value) {
this.printResult(value, 'Failure: {} is not Truthy.'.format(value));
}
Expand Down