Lolly 1.4.27
Loading...
Searching...
No Matches
Functions
analyze_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "analyze.hpp"
Include dependency graph for analyze_test.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("is_alpha")
 
 TEST_CASE ("is_digit")
 
 TEST_CASE ("is_space")
 
 TEST_CASE ("is_binary_digit")
 
 TEST_CASE ("is_alphanum")
 
 TEST_CASE ("test locase all")
 
 TEST_CASE ("test upcase all")
 
 TEST_CASE ("test string minus")
 
 TEST_CASE ("test string union")
 
 TEST_CASE ("remove_prefix")
 
 TEST_CASE ("remove_suffix")
 
 TEST_CASE ("test_raw_quote")
 
 TEST_CASE ("test_raw_unquote")
 
 TEST_CASE ("test_unescape_guile")
 
 TEST_CASE ("test_starts")
 
 TEST_CASE ("test_ends")
 
 TEST_CASE ("test_read_word")
 
 TEST_CASE ("contains/occurs")
 
 TEST_CASE ("replace")
 
 TEST_CASE ("tokenize")
 
 TEST_CASE ("recompose")
 

Function Documentation

◆ TEST_CASE() [1/21]

TEST_CASE ( "is_alpha" )

Definition at line 4 of file analyze_test.cpp.

4 {
5 for (unsigned char c= 0; c < 255; c++) {
6 if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
7 CHECK (is_alpha (c));
8 }
9 else {
10 CHECK (!is_alpha (c));
11 }
12 }
13}
bool is_alpha(string s)
Checks if a string contains only alphabetic characters.
Definition analyze.cpp:46
The list class represents a linked list.
Definition list.hpp:48

◆ TEST_CASE() [2/21]

TEST_CASE ( "is_digit" )

Definition at line 15 of file analyze_test.cpp.

15 {
16 for (unsigned char c= 0; c < 255; c++) {
17 if (c >= 48 && c <= 57) {
18 CHECK (is_digit (c));
19 }
20 else {
21 CHECK (!is_digit (c));
22 }
23 }
24}
bool is_digit(char c)
Definition analyze.hpp:37

◆ TEST_CASE() [3/21]

TEST_CASE ( "is_space" )

Definition at line 26 of file analyze_test.cpp.

26 {
27 for (unsigned char c= 0; c < 255; c++) {
28 if ((c == 9) || (c == 10) || (c == 13) || (c == 32)) {
29 CHECK (is_space (c));
30 }
31 else {
32 CHECK (!is_space (c));
33 }
34 }
35}
bool is_space(char c)
Definition analyze.hpp:63

◆ TEST_CASE() [4/21]

TEST_CASE ( "is_binary_digit" )

Definition at line 37 of file analyze_test.cpp.

37 {
38 for (unsigned char c= 0; c < 255; c++) {
39 if ((c == '0') || (c == '1')) {
41 }
42 else {
44 }
45 }
46}
bool is_binary_digit(char c)
Definition analyze.hpp:41

◆ TEST_CASE() [5/21]

TEST_CASE ( "is_alphanum" )

Definition at line 57 of file analyze_test.cpp.

57 {
58 CHECK (is_alphanum ("s3"));
59 CHECK (is_alphanum ("ipv6"));
60 CHECK (is_alphanum ("abc"));
61 CHECK (is_alphanum ("123"));
62 CHECK (!is_alphanum (""));
63 CHECK (!is_alphanum ("!"));
64}
bool is_alphanum(string s)
Definition analyze.cpp:55

◆ TEST_CASE() [6/21]

TEST_CASE ( "test locase all" )

Definition at line 66 of file analyze_test.cpp.

66 {
67 CHECK_EQ (locase_all (string ("true")) == string ("true"), true);
68 CHECK_EQ (locase_all (string ("TRue")) == string ("true"), true);
69 CHECK_EQ (locase_all (string ("TRUE")) == string ("true"), true);
70 CHECK_EQ (locase_all (string ("123TRUE")) == string ("123true"), true);
71}
string locase_all(string s)
Converts all uppercase characters in a string to lowercase.
Definition analyze.cpp:137

◆ TEST_CASE() [7/21]

TEST_CASE ( "test upcase all" )

Definition at line 73 of file analyze_test.cpp.

73 {
74 CHECK_EQ (upcase_all (string ("true")) == string ("TRUE"), true);
75 CHECK_EQ (upcase_all (string ("TRue")) == string ("TRUE"), true);
76 CHECK_EQ (upcase_all (string ("TRUE")) == string ("TRUE"), true);
77 CHECK_EQ (upcase_all (string ("123true")) == string ("123TRUE"), true);
78}
string upcase_all(string s)
Converts all lowercase characters in a string to uppercase.
Definition analyze.cpp:127

◆ TEST_CASE() [8/21]

TEST_CASE ( "test string minus" )

Definition at line 80 of file analyze_test.cpp.

80 {
81 CHECK_EQ (string_minus ("Hello World", "eo") == string ("Hll Wrld"), true);
82 CHECK_EQ (string_minus ("", "abc") == string (""), true);
83 CHECK_EQ (string_minus ("abc", "") == string ("abc"), true);
84}
string string_minus(string s1, string s2)
Remove characters from one string that are in another string.
Definition analyze.cpp:156

◆ TEST_CASE() [9/21]

TEST_CASE ( "test string union" )

Definition at line 86 of file analyze_test.cpp.

86 {
87 CHECK_EQ (string_union ("abc", "") == string ("abc"), true);
88 CHECK_EQ (string_union ("", "abc") == string ("abc"), true);
89 CHECK_EQ (string_union ("Hello World", "eo") == string ("Hll Wrldeo"), true);
90}
string string_union(string s1, string s2)
Union of two strings.
Definition analyze.cpp:151

◆ TEST_CASE() [10/21]

TEST_CASE ( "remove_prefix" )

Definition at line 92 of file analyze_test.cpp.

92 {
93 string_eq (remove_prefix ("abc", "a"), "bc");
94 string_eq (remove_prefix ("abc", ""), "abc");
95 string_eq (remove_prefix ("", ""), "");
96 string_eq (remove_prefix ("abc", ""), "abc");
97 string_eq (remove_prefix ("a1a", "a"), "1a");
98}
string remove_prefix(string s, string prefix)
Remove the prefix from s if matches.
Definition analyze.cpp:168
void string_eq(string left, string right)

◆ TEST_CASE() [11/21]

TEST_CASE ( "remove_suffix" )

Definition at line 100 of file analyze_test.cpp.

100 {
101 string_eq (remove_suffix ("abc", "c"), "ab");
102 string_eq (remove_suffix ("abc", ""), "abc");
103 string_eq (remove_suffix ("", ""), "");
104 string_eq (remove_suffix ("abc", ""), "abc");
105 string_eq (remove_suffix ("a1a", "a"), "a1");
106}
string remove_suffix(string s, string suffix)
Remove the suffix from s if matches.
Definition analyze.cpp:175

◆ TEST_CASE() [12/21]

TEST_CASE ( "test_raw_quote" )

Definition at line 108 of file analyze_test.cpp.

108 {
109 CHECK_EQ (raw_quote ("a") == "\"a\"", true);
110 CHECK_EQ (raw_quote ("") == "\"\"", true);
111}
string raw_quote(string s)
Add quotes around a string to indicate it's a string, not a symbol.
Definition analyze.cpp:420

◆ TEST_CASE() [13/21]

TEST_CASE ( "test_raw_unquote" )

Definition at line 113 of file analyze_test.cpp.

113 {
114 CHECK_EQ (raw_unquote ("\"a\"") == "a", true);
115 CHECK_EQ (raw_unquote ("\"a") == "\"a", true);
116 CHECK_EQ (raw_unquote ("a\"") == "a\"", true);
117 CHECK_EQ (raw_unquote ("") == "", true);
118 CHECK_EQ (raw_unquote ("a") == "a", true);
119}
string raw_unquote(string s)
Remove quotes from a string label.
Definition analyze.cpp:426

◆ TEST_CASE() [14/21]

TEST_CASE ( "test_unescape_guile" )

Definition at line 121 of file analyze_test.cpp.

121 {
122 CHECK_EQ (unescape_guile ("\\\\") == "\\\\\\\\", true);
123}
string unescape_guile(string s)
Unescape a Guile-syntax string.
Definition analyze.cpp:515

◆ TEST_CASE() [15/21]

TEST_CASE ( "test_starts" )

Definition at line 125 of file analyze_test.cpp.

125 {
126 CHECK (starts ("abc_def", "abc"));
127 CHECK (!starts ("abc_def", "def"));
128 CHECK (starts ("abc", ""));
129 CHECK (starts ("", ""));
130}
bool starts(string s, const char *what)
Definition analyze.cpp:566

◆ TEST_CASE() [16/21]

TEST_CASE ( "test_ends" )

Definition at line 132 of file analyze_test.cpp.

132 {
133 CHECK (ends ("abc_def", "def"));
134 CHECK (ends ("abc_def", ""));
135 CHECK (!ends ("abc_def", "de"));
136}
bool ends(string s, const char *what)
Definition analyze.cpp:576

◆ TEST_CASE() [17/21]

TEST_CASE ( "test_read_word" )

Definition at line 138 of file analyze_test.cpp.

138 {
139 string word;
140 int i= 0;
141 CHECK (read_word ("hello123", i, word));
142 CHECK_EQ (word == "hello", true);
143 CHECK_EQ (i, 5);
144
145 i = 0;
146 word= "";
147 CHECK (!read_word ("123", i, word));
148 CHECK (is_empty (word));
149 CHECK_EQ (i, 0);
150}
bool read_word(string s, int &i, string &result)
Definition analyze.cpp:681
bool is_empty(string s)
Definition string.cpp:354

◆ TEST_CASE() [18/21]

TEST_CASE ( "contains/occurs" )

Definition at line 152 of file analyze_test.cpp.

152 {
153 CHECK (contains ("abc", "a"));
154 CHECK (contains ("abc", "ab"));
155 CHECK (contains ("abc", "bc"));
156 CHECK (!contains ("abc", "B"));
157 CHECK (contains ("", ""));
158 CHECK (contains ("abc", ""));
159 CHECK (!contains ("abc", " "));
160 CHECK (contains ("hello world", " "));
161}
bool contains(T a, array< T > b)
Check if an array contains a specified element.

◆ TEST_CASE() [19/21]

TEST_CASE ( "replace" )

Definition at line 163 of file analyze_test.cpp.

163 {
164 CHECK_EQ (replace ("a-b", "-", "_") == "a_b", true);
165 CHECK_EQ (replace ("a-b-c", "-", "_") == "a_b_c", true);
166}
string replace(string s, string what, string by)
Definition analyze.cpp:899

◆ TEST_CASE() [20/21]

TEST_CASE ( "tokenize" )

Definition at line 168 of file analyze_test.cpp.

168 {
169 CHECK_EQ (tokenize ("hello world", " "), array<string> ("hello", "world"));
170 CHECK_EQ (tokenize ("zotero://select/library/items/2AIFJFS7", "://"),
171 array<string> ("zotero", "select/library/items/2AIFJFS7"));
172}
array< string > tokenize(string s, string sep)
Definition analyze.cpp:948

◆ TEST_CASE() [21/21]

TEST_CASE ( "recompose" )

Definition at line 174 of file analyze_test.cpp.

174 {
175 string_eq (recompose (array<string> ("hello", "world"), " "), "hello world");
176 string_eq (
177 recompose (array<string> ("zotero", "select/library/items/2AIFJFS7"),
178 "://"),
179 "zotero://select/library/items/2AIFJFS7");
180}
string recompose(array< string > a, string sep)
Definition analyze.cpp:963