-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #16 from adrianocastro189/release/version-0.0.8-alpha
Release - 0.0.8-alpha
- Loading branch information
Showing
22 changed files
with
575 additions
and
123 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
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,28 @@ | ||
# Bool | ||
|
||
The **Bool** support methods are focused on working and validating bool | ||
values. | ||
|
||
Each helper method is well documented in the support source code and won't | ||
be duplicated here. Please, refer to the `./src/Support/Bool.lua` for better | ||
reference. | ||
|
||
## Methods | ||
|
||
* `Bool:isTrue()` - Determines whether a value represents true or not. | ||
|
||
:::note Note about the absence of isFalse() | ||
|
||
Developers may notice this class has no `isFalse()` method. | ||
|
||
In terms of determining if a value is true, there's a limited | ||
range of values that can be considered true. On the other hand, | ||
anything else **shouldn't be considered false.** Consumers of this | ||
class can use `isTrue()` to determine if a value represents a true | ||
value, but using a `isFalse()` method would be a bit inconsistent. | ||
That said, instead of having a `isFalse()` method, consumers can | ||
use the `not` operator to determine if a value is false, which | ||
makes the code more readable, like: if this value is not true, | ||
then do something. | ||
|
||
::: |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Test Classes | ||
|
||
Test classes in the Stormwind Library are organized in a way that makes it | ||
easy to run all tests at once although split into multiple files for each | ||
class in the src directory. | ||
|
||
The `./tests/unit.lua` file is the entry point for running all tests and it | ||
also defines a base test class that sets up the library before each test. | ||
Setting up the library before each test ensures that the library is in a | ||
clean state before each test is run, so mocking the library on tests won't | ||
affect the results of other tests. | ||
|
||
## Writing a test class | ||
|
||
In order to write a test class, it's highly recommended to follow a couple | ||
of standards to keep the tests organized, easy to read, and easy to | ||
maintain. | ||
|
||
As an example, consider the support classes in the library as they are good | ||
representatives of how a test class should be written. | ||
|
||
1. Start by creating a directory following the same structure as the src | ||
directory, but inside tests | ||
1. Create a test file for each class in the src directory | ||
1. Define the test class starting with the **Test** prefix followed by the | ||
name of the class being tested; this is important for the test runner to | ||
identify the test class, otherwise it will be skipped | ||
1. Define a method for each test case starting with the **test** prefix | ||
1. Update the `./tests/unit.lua` file to include the test file, preferably | ||
in alphabetical order | ||
|
||
## Getting the library instance in a test case | ||
|
||
A library instance is available in each test case through the global | ||
variable `__` and it's ready to be used without any further setup. However, | ||
if a test case requires a different setup, it's possible to instantiate a | ||
new library instance in the test case by doing this: | ||
|
||
```lua | ||
local __ = StormwindLibrary.new({ | ||
name = 'TestSuite' | ||
}) | ||
``` | ||
|
||
In the example above, `StormwindLibrary` is an alias for the library version | ||
being tested, so when new versions are released, it's only necessary to | ||
update the alias in the `./tests/unit.lua` file. | ||
|
||
## Mocking library properties and methods | ||
|
||
The library is set up before each test in the base test class, so mocking | ||
properties and methods of the library can be done in each test case without | ||
affecting other tests. | ||
|
||
To mock a property or method of the library, simply assign a new value to | ||
the property or method in the test case. For example, to mock the `name` | ||
property of the library, you can do the following: | ||
|
||
```lua | ||
__.name = 'MockedName' | ||
``` | ||
|
||
To mock a method of the library, you can assign a new function to the | ||
method in the test case. | ||
|
||
There's no need to revert the mocked properties and methods back to their | ||
original values after the test case is run, unless the test method is | ||
expected to be called multiple times in the same test class and with | ||
different mocks. |
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,39 @@ | ||
--[[ | ||
The Bool support class contains helper functions to manipulate boolean | ||
values. | ||
]] | ||
local Bool = {} | ||
Bool.__index = Bool | ||
Bool.__ = self | ||
|
||
--[[ | ||
Determines whether a value represents true or not. | ||
This method checks if a value is in a range of possible values that | ||
represent a true value. | ||
@NOTE: Developers may notice this class has no isFalse() method. | ||
In terms of determining if a value is true, there's a limited | ||
range of values that can be considered true. On the other hand, | ||
anything else shouldn't be considered false. Consumers of this | ||
class can use isTrue() to determine if a value represents a true | ||
value, but using a isFalse() method would be a bit inconsistent. | ||
That said, instead of having a isFalse() method, consumers can | ||
use the not operator to determine if a value is false, which | ||
makes the code more readable, like: if this value is not true, | ||
then do something. | ||
@tparam mixed value | ||
@treturn bool | ||
]] | ||
function Bool:isTrue(value) | ||
local inArray, index = self.__.arr:inArray({1, "1", "true", true, "yes"}, value) | ||
|
||
-- it returns just the first inArray result, as the second value is the index | ||
-- which makes no sense in this context | ||
return inArray | ||
end | ||
-- end of Bool | ||
|
||
self.bool = Bool |
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
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
Oops, something went wrong.