jeger/source/main.cpp

197 lines
6.0 KiB
C++
Raw Normal View History

2023-09-02 11:39:52 -04:00
#include <stdio.h>
2023-09-07 15:51:42 -04:00
#include <string.h>
2023-09-08 10:35:16 -04:00
#include <stdlib.h>
2023-09-09 08:37:54 -04:00
#include "test.hpp"
2023-09-02 11:39:52 -04:00
2023-09-08 10:35:16 -04:00
signed main() {
2023-09-23 10:52:45 -04:00
TEST( R"del(abc)del", "abc", true);
TEST(R"del(efg1)del", "efg1", true);
2023-09-08 10:35:16 -04:00
TEST( R"del(nig)del", "ger", false);
2023-09-23 10:52:45 -04:00
TEST( R"del(ss)del", "sss", true);
2023-09-08 10:35:16 -04:00
TEST( R"del(sss)del", "ss", false);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del(ab+c)del", "abc", true);
TEST(R"del(ef+g1)del", "effffg1", true);
2023-09-08 10:35:16 -04:00
TEST(R"del(efg1+)del", "efg", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(efg1+)del", "efg1", true);
TEST(R"del(efg1+)del", "efg11", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del(a+a)del", "aaa", true);
TEST( R"del(a+a)del", "aa", true);
2023-09-08 10:35:16 -04:00
TEST( R"del(a+a)del", "a", false);
2023-09-23 10:52:45 -04:00
TEST( R"del(a+a)del", "aaa", true);
2023-09-08 10:35:16 -04:00
TEST(R"del(a+\+)del", "aaa", false);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-08 10:35:16 -04:00
TEST( R"del(ab*c)del", "abc", true);
TEST(R"del(ef*g1)del", "effffg1", true);
TEST(R"del(efg1*)del", "efg", true);
TEST(R"del(efg1*)del", "efg1", true);
TEST(R"del(efg1*)del", "efg11", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del(ne.)del", "net", true);
2023-09-08 10:35:16 -04:00
TEST( R"del(ne.)del", "ne", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(ne.+)del", "neoo", true);
TEST(R"del(ne.*)del", "neoo", true);
TEST(R"del(ne.*)del", "ne", true);
2023-09-07 15:18:47 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del(ne.o)del", "neto", true);
TEST(R"del(ne.+o)del", "nettto", true);
2023-09-08 10:35:16 -04:00
TEST(R"del(ne.+o)del", "neo", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(ne.+o)del", "neoo", true);
TEST(R"del(ne.*o)del", "neo", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST(R"del(ne.)del", "ne\t", true);
2023-09-08 10:35:16 -04:00
TEST(R"del(ne\t)del", "ne", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(ne\t)del", "ne\t", true);
2023-09-08 10:35:16 -04:00
TEST(R"del(ne\t)del", "net", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(ne)del", "ne\t", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-08 10:35:16 -04:00
TEST(R"del(\sa)del", " a", true);
TEST(R"del(\sa)del", " a ", true);
TEST(R"del(\wi)del", "hi", true);
TEST(R"del(\w+)del", "asd", true);
TEST(R"del(\w*)del", "", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del([A-Za-z]+)del", "HelloWorld", true);
TEST(R"del([A-Za-z]+g)del", "HelloWorldg", true);
2023-09-08 10:35:16 -04:00
TEST(R"del([A-Za-z]+g)del", "g", false);
2023-09-23 10:52:45 -04:00
TEST(R"del([A-Za-z]*g)del", "g", true);
2023-09-08 10:35:16 -04:00
TEST(R"del([A-Za-z]+1)del", "1", false);
2023-09-07 15:18:47 -04:00
puts("");
2023-09-08 10:35:16 -04:00
TEST( R"del([^0-9])del", "0", false);
TEST( R"del([^A-Za-z])del", "HelloWorld", false);
2023-09-23 10:52:45 -04:00
TEST(R"del([^A-Za-z]+g)del", "313g", true);
TEST( R"del([^0-9])del", "HelloWorld", true);
TEST( R"del([^a])del", "ba", true);
2023-09-02 11:39:52 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST( R"del(^\^)del", "^^", true);
2023-09-08 10:35:16 -04:00
TEST( R"del(^\^)del", " ^", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(^ \^)del", " ^", true);
TEST( R"del(^a*)del", "asd", true);
TEST( R"del(^)del", "", true);
2023-09-02 11:39:52 -04:00
2023-09-08 10:35:16 -04:00
puts("");
2023-09-02 11:39:52 -04:00
2023-09-23 10:52:45 -04:00
TEST( R"del(\<test)del", "test", true);
TEST( R"del(test\>)del", "test", true);
2023-09-22 14:36:33 -04:00
TEST( R"del(\<test)del", "ttest", false);
2023-09-08 10:35:16 -04:00
TEST( R"del(test\>)del", "testa", false);
2023-09-23 10:52:45 -04:00
TEST(R"del(\<test\>)del", "test", true);
2023-09-02 11:39:52 -04:00
2023-09-21 02:38:32 -04:00
puts("");
2023-09-26 10:03:59 -04:00
TEST( R"del(\<test)del", " test ", true);
TEST( R"del(test\>)del", " test ", true);
TEST( R"del(\<test)del", " ttest ", false);
TEST( R"del(test\>)del", "testa ", false);
TEST(R"del(\<test\>)del", " test ", true);
puts("");
2023-09-22 14:36:33 -04:00
TEST( R"del(\<int\>)del", "printf", false);
TEST(R"del(.\<print\>.)del", " print ", true);
TEST(R"del(.\<print\>.)del", "fprint", false);
TEST(R"del(.\<print\>.)del", "printf", false);
TEST(R"del(.\<print\>.)del", "fprintf", false);
2023-09-21 02:38:32 -04:00
2023-09-23 06:41:15 -04:00
puts("");
TEST(R"del(\<while\>)del", "while", true);
TEST(R"del(\<while\>)del", " while ", true);
TEST(R"del(\<while\>)del", "9while ", true);
TEST(R"del(\<while\>)del", "for while {", true);
TEST(R"del(\<while\>)del", "for while{", true);
2023-09-25 09:48:12 -04:00
puts("");
2023-09-25 15:51:40 -04:00
TEST(R"del(/\*[\d\D]*\*/)del", "908", false);
TEST(R"del(/\*[\d\D]*\*/)del", "/*908*/", true);
TEST(R"del(/\*[\d\D]*\*/)del", "/*asd*/", true);
TEST(R"del(/\*[\d\D]*\*/)del", "/* asd */", true);
TEST(R"del(/\*[\d\D]*\*/)del", "/* as* */", true);
2023-09-25 09:48:12 -04:00
2023-09-09 08:37:54 -04:00
if (test_counter == passed_tests) {
2023-09-02 11:39:52 -04:00
fputs("\033[32m", stdout);
2023-09-09 08:37:54 -04:00
} else {
fputs("\033[31m", stdout);
2023-09-02 11:39:52 -04:00
}
printf("\nPassed %d out of %d tests.\033[0m\n", passed_tests, test_counter);
printf("\tPositives: %d/%d\n", positive_successes, positives);
printf("\tNegatives: %d/%d\n", negative_successes, negatives);
2023-09-08 10:35:16 -04:00
puts("");
2023-09-09 08:37:54 -04:00
puts("");
2023-09-08 10:35:16 -04:00
2023-09-23 10:52:45 -04:00
TEST2( R"del(abc)del", "abc", match_t{ 0, strlen("abc")});
2023-09-09 08:37:54 -04:00
TEST2(R"del(efg1)del", "efg1", match_t{ 0, strlen("efg1")});
2023-09-23 10:52:45 -04:00
TEST2( R"del(nig)del", "ger", match_t{-1, -1});
TEST2( R"del(ss)del", "sss", match_t{ 0, 2});
TEST2( R"del(sss)del", "ss", match_t{-1, -1});
2023-09-09 08:37:54 -04:00
puts("");
2023-09-08 10:35:16 -04:00
puts("");
2023-09-23 10:52:45 -04:00
TEST2( R"del(ab+c)del", "abc", match_t{ 0, strlen("abc")});
2023-09-09 08:37:54 -04:00
TEST2(R"del(ef+g1)del", "effffg1", match_t{ 0, strlen("effffg1")});
2023-09-23 10:52:45 -04:00
TEST2(R"del(efg1+)del", "efg", match_t{-1, -1});
TEST2(R"del(efg1+)del", "efg1", match_t{ 0, strlen("efg1")});
TEST2(R"del(efg1+)del", "efg11", match_t{ 0, strlen("efg11")});
2023-09-09 08:37:54 -04:00
puts("");
puts("");
2023-09-23 10:52:45 -04:00
TEST2( R"del(a+a)del", " aaa", match_t{ 1, strlen("aaa")});
TEST2( R"del(a+a)del", " aa", match_t{ 1, strlen("aa")});
TEST2( R"del(a+a)del", " a", match_t{-1, -1});
TEST2( R"del(a+a)del", " aaa", match_t{ 3, strlen("aaa")});
2023-09-09 08:37:54 -04:00
TEST2(R"del(a+\+)del", "aaa+", match_t{ 0, strlen("aaa+")});
2023-09-23 08:52:40 -04:00
puts("");
puts("");
TEST2(R"del(\<while\>)del", "while", match_t{0, strlen("while")});
TEST2(R"del(\<while\>)del", " while", match_t{1, strlen("while")});
TEST2(R"del(\<while\>)del", "for while", match_t{4, strlen("while")});
TEST2(R"del(\<while\>)del", "for9while", match_t{4, strlen("while")});
TEST2(R"del(\<while\>)del", "for9while ", match_t{4, strlen("while")});
2023-09-23 10:48:03 -04:00
puts("");
puts("");
TEST2(R"del(\+)del", "akjh ab+ snabd", match_t{ strlen("akjh ab+")-1, 1});
TEST2(R"del(\*)del", "a*jh abn snabd", match_t{ strlen("a*")-1, 1});
TEST2(R"del(\=)del", "ak=h abn snabd", match_t{ strlen("ak=")-1, 1});
TEST2(R"del(\?)del", "akjh abn s?abd", match_t{ strlen("akjh abn s?")-1, 1});
TEST2(R"del(\+)del", "akjh abn snab+", match_t{strlen("akjh abn snab+")-1, 1});
2023-09-09 08:37:54 -04:00
if(test_counter2 == passed_tests2) {
fputs("\033[32m", stdout);
} else {
fputs("\033[31m", stdout);
}
printf("\nPassed %d out of %d tests.\033[0m\n", passed_tests2, test_counter2);
return 0;
2023-09-02 11:39:52 -04:00
}