mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-17 03:50:04 +02:00
tests: Adding doctest framework.
This commit is contained in:
parent
35c2c2fe79
commit
dbbdc896e1
6 changed files with 7125 additions and 53 deletions
|
|
@ -1,11 +1,12 @@
|
|||
#include <libeosio/base58.hpp>
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <doctest.h>
|
||||
|
||||
typedef std::pair<std::string, size_t> testpair_t;
|
||||
typedef std::array<testpair_t, 6> tests;
|
||||
|
||||
int test_string() {
|
||||
TEST_CASE("base58::is_base58 [string]") {
|
||||
tests input = {
|
||||
// Empty string is a valid base58 string.
|
||||
testpair_t("", std::string::npos),
|
||||
|
|
@ -30,48 +31,22 @@ int test_string() {
|
|||
|
||||
size_t ret = libeosio::is_base58(it->first);
|
||||
|
||||
if ( ret != it->second ) {
|
||||
std::cout << ret << " is not equalt to " << it->second << std::endl;
|
||||
return 1;
|
||||
}
|
||||
CHECK(ret == it->second);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_char() {
|
||||
|
||||
TEST_CASE("base58::is_base58 [char]") {
|
||||
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
std::string invalid_alphabet = "0OIl";
|
||||
|
||||
for(int i = 0; i < valid_alphabet.length(); i++) {
|
||||
char ch = valid_alphabet[i];
|
||||
|
||||
if ( libeosio::is_base58(ch) == false ) {
|
||||
std::cout << ch << " should be a valid base58 character " << std::endl;
|
||||
return 1;
|
||||
}
|
||||
CHECK(libeosio::is_base58(ch) == true);
|
||||
}
|
||||
|
||||
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
||||
char ch = invalid_alphabet[i];
|
||||
|
||||
if ( libeosio::is_base58(ch) ) {
|
||||
std::cout << ch << " should be a invalid base58 character " << std::endl;
|
||||
return 1;
|
||||
}
|
||||
CHECK(libeosio::is_base58(ch) == false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
if (test_string() != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (test_char() != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue